zuquanzhi / Auto Refresh HITWH

// ==UserScript==
// @name         Auto Refresh HITWH
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Keep refreshing the HITWH page until it loads correctly
// @author       zuquanzhi
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const refreshInterval = 2000; //刷新间隔设置为2s

    function shouldRun() {
        return window.location.href.includes('hitwh.edu.cn');
    }

    //检查特定元素,可以根据网页特征进行修改
    //eg:检查head栏有没有加载出“哈尔滨工业大学(威海)”字样
    function isPageLoaded() {
        const metaTag = document.querySelector('meta[name="keywords"]');
        if (metaTag && metaTag.content === "哈尔滨工业大学(威海)") {
            return true;
        }
        return false;
    }

    function checkPageAndRefresh() {
        if (shouldRun() && !isPageLoaded()) {
            setTimeout(() => location.reload(), refreshInterval);
        }
    }

    window.addEventListener('load', checkPageAndRefresh);
})();