Greasy Fork

Greasy Fork is available in English.

双倍快乐

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name 双倍快乐
// @author xcl & Zilewang7(啥也没做)
// @description 双倍文字,双倍快乐; 单行变双行,原文档一行,翻译一行
// @version 0.0.3
// @match *://*/*
// @namespace http://greasyfork.icu/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";
    };
})();