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.

La data de 25-06-2025. Vezi ultima versiune.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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";
  };
})();