Greasy Fork

Greasy Fork is available in English.

双倍快乐

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

当前为 2021-08-12 提交的版本,查看 最新版本

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

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

  "use strict";
  const duplicateBtn = document.createElement("div");
  duplicateBtn.style.backgroundColor = "skyblue";
  duplicateBtn.style.zIndex = 10000;
  duplicateBtn.style.width = '88px';
  duplicateBtn.style.height = '30px';
  duplicateBtn.style.position = "fixed";
  duplicateBtn.style.top = "50px";
  duplicateBtn.style.left = "-78px";
  duplicateBtn.style.transition = 'all 0.3s';
  duplicateBtn.style.border = '1px solid transparent';
  duplicateBtn.style.outline = 'none';
  duplicateBtn.style.borderRadius = '10px';
  duplicateBtn.onmouseover = () => {
    duplicateBtn.style.left = "-12px";
  };
  duplicateBtn.onmouseleave = () => {
    duplicateBtn.style.left = "-78px";
  };
  document.body.appendChild(duplicateBtn);
  duplicateBtn.onclick = () => {
      document.querySelectorAll("p").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");
    });

    for (let i = 1; i <= 6; i++) {
      let h = "h" + i;
      document.querySelectorAll(h).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");
      });
    }

    document.querySelectorAll("a").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";
  };
})();