如名称
当前为
// ==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 毫秒
}
}
})();