Google Docs Viewer to Editable Mode (Improved)

Make Google Docs view-only mode editable

目前為 2025-02-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();

})();