COC2 翻译分段修复

修复 Google 翻译导致段落合并的问题

目前为 2024-10-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         COC2 翻译分段修复
// @namespace    http://tampermonkey.net/
// @version      2024-10-29
// @description  修复 Google 翻译导致段落合并的问题
// @author       LinHQ
// @match        *://*/*
// @grant        none
// @run-at       context-menu
// @license      AGPLv3
// ==/UserScript==

(function () {
  'use strict';
  new MutationObserver((li, ob) => {
    try {
      li.forEach((mu) => {
        if (mu.type !== 'childList') return
        const nodes = mu.addedNodes
        nodes.forEach(node => {
          let t
          if (node.nodeType === 3) {
            t = node.parentNode
          } else if (node?.querySelector('.mainText')) {
            t = [...node?.querySelectorAll('.mainText')].pop()
          }

          if (!t?.matches('.mainText')) return

          requestAnimationFrame(() => {
              ob.disconnect()
              t.innerHTML = t.innerHTML?.replaceAll('\n', '<br>') ?? t.innerHTML
              ob.observe(document, {
                  subtree: true,
                  childList: true
              })
          })
        })
      })
    } catch (e) {
      console.warn('Script Error!', e)
    }
  }).observe(document, {
    subtree: true,
    childList: true
  })
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址