Google Docs Viewer to Editable Mode (Improved)

Make Google Docs view-only mode editable

当前为 2025-02-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Google Docs Viewer to Editable Mode (Improved)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Make Google Docs view-only mode editable
// @author       You
// @match        https://docs.google.com/document/d/*/view*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to wait until the document editor is loaded
    function waitForDocument() {
        const viewerOverlay = document.querySelector('.kix-viewer-overlay');
        if (viewerOverlay) {
            removeViewerOverlay(viewerOverlay);
        }

        const editableDiv = document.querySelector('.kix-appview-editor');
        if (editableDiv) {
            enableEditing(editableDiv);
        } else {
            setTimeout(waitForDocument, 1000);
        }
    }

    // Remove the viewer overlay that blocks editing
    function removeViewerOverlay(viewerOverlay) {
        viewerOverlay.style.display = 'none';
        viewerOverlay.remove();
    }

    // Enable editing mode on the document
    function enableEditing(editableDiv) {
        editableDiv.contentEditable = true;  // Enable content editing
        editableDiv.style.pointerEvents = 'auto';  // Make the content interactable

        // Force certain behaviors to remove "view-only" restrictions
        const viewerContent = editableDiv.querySelector('.kix-document');
        if (viewerContent) {
            viewerContent.setAttribute('contenteditable', 'true');
        }

        // Optionally, remove any additional overlays or protections
        const disallowedMessage = document.querySelector('.docs-viewer-disallowed-message');
        if (disallowedMessage) {
            disallowedMessage.style.display = 'none';
        }

        console.log('Google Docs is now in editable mode.');
    }

    // Start the process once the page is ready
    waitForDocument();

})();