Google Forms Auto-Close Simplified

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

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

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.

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

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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

})();