Google Forms Auto-Close Simplified

Закрывает вкладку через 3 сек после отправки Google Forms (formResponse).

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Google Forms Auto-Close Simplified
// @namespace    https://t.me/zycck
// @version      1.6
// @description  Закрывает вкладку через 3 сек после отправки Google Forms (formResponse).
// @match        https://docs.google.com/forms/u/0/d/e/*/formResponse*
// @grant        window.close
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Регулярка для проверки URL
    const pattern = /^https:\/\/docs\.google\.com\/forms\/u\/0\/d\/e\/.+\/formResponse.*$/;

    // Время в миллисекундах, соответствующее 5000 секундам
    const timeoutMs = 3000;

    // Запомним изначальный URL и время
    let lastUrl = location.href;
    let lastChangeTime = Date.now();

    // Функция, закрывающая вкладку (с обходом для браузеров, не давших разрешения)
    function closeTab() {
        // Попытка стандартного close()
        window.close();
        // Если не сработало (Chrome), пробуем хак:
        window.open('', '_self');
        window.close();
    }

    setInterval(() => {

        const currentUrl = location.href;
        console.log(pattern.test(currentUrl),(Date.now() - lastChangeTime) > timeoutMs)
        if (currentUrl !== lastUrl) {
            lastUrl = currentUrl;
            lastChangeTime = Date.now();
        }
        if (pattern.test(currentUrl) && (Date.now() - lastChangeTime) > timeoutMs) {
            closeTab();
        }
    }, 1000);

})();