[冬奥版]奥运奖牌提醒小助手
// ==UserScript==
// @name [冬奥版]奥运奖牌提醒小助手
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.4
// @description 每半小时提醒一次奖牌数量,可以自己修改定时时间
// @author Wyz
// @crontab 0/30 * * * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// ==/UserScript==
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: "https://tiyu.baidu.com/beijing2022/home/tab/%E5%A5%96%E7%89%8C%E6%A6%9C/from/pc",
onload(resp) {
console.log(resp.responseText);
const regex = /<div class="national-box" data-a-0dd384e7><img src="(.*?)" class="img[\s\S]*?" data-a-0dd384e7><\/div> <div class="national-name m-c-line-clamp1" data-a-0dd384e7>(.*?)<\/div><\/div> <div class="right-box" data-a-0dd384e7><div class="num" data-a-0dd384e7>(\d+)<\/div> <div class="num" data-a-0dd384e7>(\d+)<\/div> <div class="num" data-a-0dd384e7>(\d+)<\/div> <div class="num" data-a-0dd384e7>(\d+)<\/div><\/div><\/div>/gm;
let list = [];
const str = resp.responseText;
let m;
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
list.push(m);
}
let t1 = parseInt(list[0][3]) + parseInt(list[0][4]) + parseInt(list[0][5]);
let t2 = parseInt(list[1][3]) + parseInt(list[1][4]) + parseInt(list[1][5]);
let t3 = parseInt(list[2][3]) + parseInt(list[2][4]) + parseInt(list[2][5]);
GM_notification({
title: "奥运奖牌提醒小助手",
image: list[0][1],
text: `1.${list[0][2]} ${list[0][3]}金 ${list[0][4]}银 ${list[0][5]}铜 总数:${t1}\n2.${list[1][2]} ${list[1][3]}金 ${list[1][4]}银 ${list[1][5]}铜 总数:${t2}\n3.${list[2][2]} ${list[2][3]}金 ${list[2][4]}银 ${list[2][5]}铜 总数:${t3}`
});
resolve();
},
onerror() {
GM_notification("奖牌数据获取失败");
resolve();
}
})
});