Make Google Docs view-only mode editable
当前为
// ==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();
})();