Google Docs: Bypass Copy Disabled (UI Dropdown)

Adds a drop-up menu to extract restricted Google Docs text. Options include copy, output to console, paste, and download as .txt. Plain text only, no images/styles.

当前为 2025-06-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Google Docs: Bypass Copy Disabled (UI Dropdown)
// @namespace    Violentmonkey Scripts
// @version      2.0
// @description  Adds a drop-up menu to extract restricted Google Docs text. Options include copy, output to console, paste, and download as .txt. Plain text only, no images/styles.
// @author       Kankoo
// @match        https://docs.google.com/document/d/*
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  function extractText() {
    const chunks = [...document.querySelectorAll("script")]
      .filter(el => el.innerHTML.includes("DOCS_modelChunk = "))
      .map(el => el.innerHTML);

    let textChunks = "";

    for (const chunk of chunks) {
      const matches = chunk.match(/"s":"(.*?)"/g);
      if (matches) {
        for (const match of matches) {
          const extracted = match
            .replace(/^"s":"|"$|\\n/g, '')
            .replace(/\\"/g, '"')
            .replace(/\\\\/g, '\\')
            .replace(/\\u000b/g, '\n\n');
          textChunks += extracted + '\n\n';
        }
      }
    }

    return textChunks;
  }

  function downloadTxt(text) {
    const blob = new Blob([text], { type: 'text/plain' });
    const a = document.createElement('a');
    a.href = URL.createObjectURL(blob);
    a.download = 'extracted_doc.txt';
    a.click();
  }

  function pasteToBody(text) {
    const p = document.createElement('pre');
    p.textContent = text;
    p.style.whiteSpace = 'pre-wrap';
    p.style.padding = '20px';
    p.style.border = '1px solid #ccc';
    p.style.backgroundColor = '#f9f9f9';
    p.style.zIndex = 99999;
    p.style.position = 'fixed';
    p.style.top = '10px';
    p.style.left = '10px';
    p.style.maxHeight = '90vh';
    p.style.overflowY = 'auto';
    p.style.fontFamily = 'monospace';
    document.body.appendChild(p);
  }

  // Toggle & Menu UI
  const container = document.createElement("div");
  container.style.position = "fixed";
  container.style.bottom = "20px";
  container.style.right = "20px";
  container.style.zIndex = 99999;
  container.style.fontFamily = "Arial, sans-serif";

  const toggleBtn = document.createElement("button");
  toggleBtn.textContent = "^";
  Object.assign(toggleBtn.style, {
    backgroundColor: "#4285F4",
    color: "white",
    border: "none",
    padding: "6px 10px",
    borderRadius: "6px",
    fontSize: "16px",
    cursor: "pointer",
    width: "40px"
  });

  const menu = document.createElement("div");
  menu.style.display = "none";
  menu.style.flexDirection = "column";
  menu.style.marginBottom = "8px";
  menu.style.background = "white";
  menu.style.border = "1px solid #ccc";
  menu.style.borderRadius = "6px";
  menu.style.boxShadow = "0 4px 8px rgba(0,0,0,0.2)";
  menu.style.overflow = "hidden";

  const makeMenuItem = (label, action) => {
    const item = document.createElement("button");
    item.textContent = label;
    Object.assign(item.style, {
      padding: "8px 12px",
      background: "white",
      border: "none",
      borderBottom: "1px solid #eee",
      textAlign: "left",
      cursor: "pointer",
      fontSize: "14px"
    });
    item.onmouseover = () => item.style.background = "#f0f0f0";
    item.onmouseout = () => item.style.background = "white";
    item.onclick = () => {
      menu.style.display = "none";
      toggleBtn.textContent = "^";
      action();
    };
    return item;
  };

  const actions = [
    makeMenuItem("📋 Copy document TXT", () => {
      const text = extractText();
      navigator.clipboard.writeText(text).then(() => {
        console.log("✅ Copied to clipboard");
      });
    }),
    makeMenuItem("💻 Output to console", () => {
      console.log("✅ Extracted text:\n\n" + extractText());
    }),
    makeMenuItem("📄 Output and Paste", () => {
      pasteToBody(extractText());
    }),
    makeMenuItem("💾 Download as TXT", () => {
      downloadTxt(extractText());
    })
  ];

  actions.forEach(btn => menu.appendChild(btn));
  container.appendChild(menu);
  container.appendChild(toggleBtn);
  document.body.appendChild(container);

  toggleBtn.onclick = () => {
    const isOpen = menu.style.display === "flex";
    menu.style.display = isOpen ? "none" : "flex";
    toggleBtn.textContent = isOpen ? "^" : "v";
  };
})();