微步下班倒计时

如名称

目前為 2023-08-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         微步下班倒计时
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  如名称
// @author       ws
// @match        https://x.threatbook.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=threatbook.com
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    ///html/body/div[1]/div[1]/div[1]/div[2]/div[6]/div[2]/div[2]
    // Your code here...

    window.onload = setTimeout(click_item, 500);
    function click_item() {
        var xpath = '//*[@id="app"]/div[1]/div[1]/div[2]/div[6]/div[2]';
        var element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
        var newData = document.createElement('div');
        // 给这个div添加css
        newData.style.color = "red";
        newData.style.fontSize = "20px";
        newData.style.fontWeight = "bold";

        if (element) {
            // 执行上面的代码
            var endTime = new Date();
            endTime.setHours(22, 0, 0, 0);
            setInterval(function() {
                let now = new Date();
                let timeLeft = endTime - now;
                var msg = "";
                if (timeLeft < 0) {
                    msg = "警告:工作时间已经结束!"
                    clearInterval(intervalId); // 停止倒计时
                } else {
                    let days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
                    let hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                    let minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
                    let seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
                    msg = "🕙距离下班:" + hours + "小时 " + minutes + "分钟 " + seconds + "秒"
                }
                newData.textContent = msg;
                element.appendChild(newData);
            },1000);
        } else {
            setTimeout(click_item, 300) //300 毫秒
        }
    }
})();