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.

Устаревшая версия за 25.06.2025. Перейдите к последней версии.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или 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";
  };
})();