Google Docs User Account Redirect

Redirect Google Docs to correct user Account

2025-08-26 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Google Docs User Account Redirect
// @description  Redirect Google Docs to correct user Account
// @version      0.1
// @author       Torkelicous
// @icon         https://ssl.gstatic.com/docs/documents/images/kix-favicon7.ico
// @include      https://docs.google.com/*
// @run-at       document-start
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// @namespace https://greasyfork.org/users/1403155
// ==/UserScript==

(function() {

    let wantedAccount = GM_getValue('wantedAccount', 1)
    let isUIVisible = GM_getValue('isUIVisible', true);
    let guiContainer;
    let toggleButton;

    // Create toggle
    function createToggleButton() {
        toggleButton = document.createElement('button');
        toggleButton.textContent = isUIVisible ? '➖' : '➕';
        toggleButton.style.position = 'fixed';
        toggleButton.style.bottom = '10px';
        toggleButton.style.right = '70px';
        toggleButton.style.zIndex = '1000';
        toggleButton.style.padding = '5px';
        toggleButton.style.cursor = 'pointer';
        toggleButton.style.backgroundColor = 'black';
        toggleButton.style.border = '1px solid grey';
        toggleButton.style.borderRadius = '3px';
        toggleButton.style.fontSize = '16px';

        toggleButton.onclick = function() {
            if (isUIVisible) {
                guiContainer.style.display = 'none';
                toggleButton.textContent = '➕';
            } else {
                guiContainer.style.display = 'block';
                toggleButton.textContent = '➖';
            }
            isUIVisible = !isUIVisible;
            GM_setValue('isUIVisible', isUIVisible);
        };

        document.body.appendChild(toggleButton);
    }

    // GUI for wantedAccount
    function createGUI() {
        guiContainer = document.createElement('div');
        guiContainer.style.position = 'fixed';
        guiContainer.style.bottom = '10px';
        guiContainer.style.right = '110px';
        guiContainer.style.padding = '10px';
        guiContainer.style.backgroundColor = 'DarkGrey';
        guiContainer.style.border = '1px solid grey';
        guiContainer.style.zIndex = '1000';
        guiContainer.style.display = isUIVisible ? 'block' : 'none'; // Set initial display based on saved state

        const label = document.createElement('label');
        label.textContent = 'Account: ';
        guiContainer.appendChild(label);

        const input = document.createElement('input');
        input.type = 'number';
        input.min = '0';
        input.max = '9';
        input.style.width = '30px';
        input.value = wantedAccount;
        guiContainer.appendChild(input);

        const button = document.createElement('button');
        button.textContent = 'Save';
        button.style.marginLeft = '5px';
        button.onclick = function() {
            GM_setValue('wantedAccount', input.value);
            location.reload();
        };
        guiContainer.appendChild(button);
        document.body.appendChild(guiContainer);
        createToggleButton();
    }
    window.addEventListener('load', createGUI);

    // Redirect logic for Docs
    var currentUrl = window.location.href;
    var urlPattern = /^https:\/\/docs\.google\.com\/document\/u\/(\d+)\//;
    var match = currentUrl.match(urlPattern);

    if (match) {
        var currentAccount = match[1];
        if (currentAccount != wantedAccount) {
            var newUrl = currentUrl.replace(/\/u\/\d+\//, `/u/${wantedAccount}/`);
            window.location.replace(newUrl);
        }
    } else {
        if (currentUrl.includes('docs.google.com/document/') && !currentUrl.includes('/u/')) {
            var newUrl = currentUrl.replace('docs.google.com/document/', `docs.google.com/document/u/${wantedAccount}/`);
            window.location.replace(newUrl);
        }
    }

})();