Moodle AutoLeave

Закрывает конфу в мудле как только в чате появится текст "до свидания"

安裝腳本?
作者推薦腳本

您可能也會喜歡 Moodle AutoPilot

安裝腳本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Moodle AutoLeave
// @namespace    https://t.me/johannmosin
// @version      0.4.0
// @description  Закрывает конфу в мудле как только в чате появится текст "до свидания"
// @author       Johann Mosin
// @license      MIT
// @match        https://*.edu.vsu.ru/html5client/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to disable beforeunload popups
    function disablePopups() {
        // Remove onbeforeunload from all elements
        var all = document.getElementsByTagName("*");
        for (var i = 0, max = all.length; i < max; i++) {
            if (all[i].getAttribute("onbeforeunload")) {
                all[i].setAttribute("onbeforeunload", null);
            }
        }
        // Clear window-level beforeunload
        window.onbeforeunload = null;

        // Override addEventListener to prevent new beforeunload listeners
        if (!window._originalAddEventListener) {
            window._originalAddEventListener = window.addEventListener;
        }
        window.addEventListener = function(type, listener, useCapture) {
            if (type !== "beforeunload") {
                window._originalAddEventListener(type, listener, useCapture);
            }
        };
    }

    // Original checkText function with preserved functionality
    function checkText() {
        var text = document.body.innerText.toLowerCase();
        if (text.includes('до свидания') || text.includes('досвидания')) {
            // Ensure popups are disabled before redirect
            disablePopups();
            window.close();
        }
    }

    // Initial popup disable
    disablePopups();

    // Run popup disable periodically
    setInterval(disablePopups, 500);

    // Original interval check for text
    setInterval(checkText, 10000);
})();