// ==UserScript== // @name B站直播通知助手 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.1 // @description 每小时检测一次,检测到主播开启直播后桌面通知,支持添加多个主播UID,用逗号分隔(半角逗号)! // @author 张仨 // @crontab * once * * * // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_openInTab // @grant GM_getValue // @connect api.iyk0.com // ==/UserScript== /* ==UserConfig== 配置: UID: title: 输入主播UID,多个可用逗号分隔(半角逗号)! description: 地区信息 default: 1037793830,17047572, ==/UserConfig== */ return new Promise((resolve, reject) => { function Ajax(uid) { GM_xmlhttpRequest({ method: "GET", responseType: "json", url: "https://api.iyk0.com/bilibili/user/?mid=" + uid, onload: function (xhr) { if (xhr.response.code === 200) { if (xhr.response.live_bf === "直播中") { let imageUrl = xhr.response.face let name = xhr.response.name let live_url = xhr.response.live_url let live_title = xhr.response.live_title let live_online = xhr.response.live_online GM_notification({ title: `${name} 正在直播中...`, text: `标题:${live_title} \n人气:${live_online} \n点击进入直播间`, image: imageUrl, 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]) } });