Greasy Fork

Greasy Fork is available in English.

双倍快乐

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

当前为 2021-07-27 提交的版本,查看 最新版本

// ==UserScript==
// @name              双倍快乐
// @author            xcl & Zilewang7(啥也没做)
// @description       双倍文字,双倍快乐; 单行变双行,原文档一行,翻译一行
// @version           0.0.1
// @match             *://*/*
// @namespace http://greasyfork.icu/users/513536
// ==/UserScript==
(function () {
  "use strict";
  let isPressed = false;
  const duplicateBtn = document.createElement("button");
  duplicateBtn.style.backgroundColor = "skyblue";
  duplicateBtn.style.zIndex = 10000;
  duplicateBtn.style.opacity = 0.5;
  duplicateBtn.style.width = '88px !important';
  duplicateBtn.style.height = '30px !important';
  duplicateBtn.style.position = "fixed !important";
  duplicateBtn.style.top = "50px !important";
  duplicateBtn.style.left = "-78px !important";
  duplicateBtn.style.transition = 'all 0.3s !important';
  duplicateBtn.onmouseover = () => {
    duplicateBtn.style.opacity = 1;
    duplicateBtn.innerHTML = "双倍文字";
    duplicateBtn.style.left = 0;
  };
  duplicateBtn.onmouseleave = () => {
    duplicateBtn.style.opacity = 0.5;
    duplicateBtn.innerHTML = "";
    duplicateBtn.style.left = "-78px !important";
  };
  document.body.appendChild(duplicateBtn);
  duplicateBtn.onclick = () => {
    if (isPressed) return;
    for (const node of document.querySelectorAll("p")) {
      const copy = document.createElement(node.nodeName);
      copy.textContent = node.textContent;
      node.parentElement.insertBefore(copy, node.nextElementSibling);
      node.setAttribute("translate", "no");
    }

    let Title = "h";
    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;
        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;
      node.parentElement.insertBefore(copy, node.nextElementSibling);
      node.setAttribute("translate", "no");
    });
    isPressed = true;
  };
})();