// ==UserScript== // @name COC2 翻译分段修复 // @namespace http://tampermonkey.net/ // @version 2024-10-10 // @description 修复 Google 翻译导致段落合并的问题 // @author LinHQ // @match *://*/* // @run-at context-menu // @license AGPL-v3 // @downloadURL none // ==/UserScript== (function () { 'use strict'; new MutationObserver((li, ob) => { try { li.forEach((mu) => { if (mu.type !== 'childList') return const nodes = mu.addedNodes nodes.forEach(node => { // 翻译会为 br 处理换行 let t if (node.nodeType === 3) { t = node.parentNode } else if (node?.querySelector('.mainText')) { t = node?.querySelector('.mainText') } if (!t?.matches('.mainText')) return ob.disconnect() t.innerHTML = t.innerHTML?.replaceAll('\n', '
') ?? t.innerHTML ob.observe(document, { subtree: true, childList: true }) }) }) } catch (e) { console.warn('Script Error!', e) } }).observe(document, { subtree: true, childList: true }) })();