B站直播通知助手
// ==UserScript==
// @name B站直播通知助手
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.2.0
// @description 每半小时检测一次,检测到主播开启直播后桌面通知,添加多个主播UID,用逗号分隔(半角逗号),建议添加不超过4个或以上!
// @author 张仨
// @crontab */30 * * * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_openInTab
// @grant GM_getValue
// @connect api.iyk0.com
// @require https://cdn.jsdelivr.net/npm/scriptcat-lib@1.1.3/dist/gm.js
// ==/UserScript==
/* ==UserConfig==
配置:
UID:
title: 输入主播UID,多个可用逗号分隔(半角逗号)!
description: 主播UID
default: 1037793830,17047572,
==/UserConfig== */
return new Promise((resolve, reject) => {
async function Ajax(uid) {
let xhr = await gm.ajax("https://api.iyk0.com/bilibili/user/?mid=" + uid);
if (xhr.data.code === 200) {
if (xhr.data.live_bf === "直播中") {
let imageUrl = xhr.data.face
let name = xhr.data.name
let live_url = xhr.data.live_url
let live_title = xhr.data.live_title
let live_online = xhr.data.live_online
GM_notification({
title: `${name} 正在直播中...`,
text: `标题:${live_title} \n人气:${live_online} \n点击进入直播间`,
image: imageUrl,
timeout: 8000,
onclick: function () {
GM_openInTab(live_url)
},
ondone() {
resolve();
}
})
} else { resolve(); }
} else {
GM_notification("数据获取失败,请稍后重试或检查uid是否正确")
resolve();
}
}
let UID = GM_getValue("配置.UID") || "1037793830,17047572"
let arr = UID.split(",")
for (let i = 0; i < arr.length; i++) {
Ajax(arr[i])
}
});