微步下班倒计时

如名称

当前为 2023-08-13 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 毫秒
        }
    }
})();