Google Forms Auto-Close Simplified

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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

})();