双倍快乐

双倍文字,双倍快乐; 单行变双行,原文档一行,翻译一行

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name 双倍快乐
// @author xcl & Zilewang7(啥也没做)
// @description 双倍文字,双倍快乐; 单行变双行,原文档一行,翻译一行
// @version 0.0.3
// @match *://*/*
// @namespace https://greasyfork.org/users/513536
// ==/UserScript==
(function () {

    const textColor = '#239e23'; // 此行为译文颜色,可以自定义;

    "use strict";
    const duplicateBtn = document.createElement("div");
    const styles = {
        backgroundColor: "skyblue",
        zIndex: 10000,
        width: '88px',
        height: '30px',
        position: 'fixed',
        top: '50px',
        left: '-78px',
        transition: 'all 0.3s',
        border: '1px solid transparent',
        outline: 'none',
        borderRadius: '10px'
    };
    Object.entries(styles).forEach(([key, value]) => {
        duplicateBtn.style[key] = value;
    })

    duplicateBtn.onmouseover = () => {
        duplicateBtn.style.left = "-12px";
    };
    duplicateBtn.onmouseleave = () => {
        duplicateBtn.style.left = "-78px";
    };
    document.body.appendChild(duplicateBtn);
    const shouldDuplicateTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'li'];

    duplicateBtn.onclick = () => {
        for (const tag of shouldDuplicateTags) {
            document.querySelectorAll(tag).forEach(node => {
                const copy = document.createElement(node.nodeName);
                copy.textContent = node.textContent;
                copy.style.setProperty('color', textColor, 'important');
                node.parentElement.insertBefore(copy, node.nextElementSibling);
                node.setAttribute("translate", "no");
            })
        }
        duplicateBtn.style.display = "none";
    };
})();