Google Forms Auto-Close Simplified

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);

})();