每日指定时间自动刷新页面

在每天凌晨1点和早上6点自动刷新页面

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         每日指定时间自动刷新页面
// @namespace    http://ptlsp.com/
// @version      0.1
// @description  在每天凌晨1点和早上6点自动刷新页面
// @author       PTLSP
// @match        *://*/*
// @grant        none
// @license      GPL-3.0 License
// ==/UserScript==

(function() {
    'use strict';

    function scheduleRefresh(hours, minutes) {
        const now = new Date();
        let target = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes, 0);
        // 如果当前时间已经过了目标时间,则目标时间设为明天
        if (now > target) {
            target.setDate(target.getDate() + 1);
        }
        const timeout = target.getTime() - now.getTime();
        setTimeout(() => {
            window.location.reload();
        }, timeout);
    }

    // 设置在每天凌晨1点自动刷新页面
    scheduleRefresh(1, 0);
    // 设置在每天早上6点自动刷新页面
    scheduleRefresh(6, 0);
})();