// ==UserScript== // @name 必应积分商城每日签到 // @namespace wyz // @description 每日自动完成任务获取必应积分奖励,可兑换实物 // @version 1.0.4 // @author wyz // @crontab * 10-23 once * * // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_getValue // @grant GM_setValue // @connect rewards.bing.com // @connect cn.bing.com // @require https://scriptcat.org/lib/946/%5E1.0.1/PushCat.js // ==/UserScript== /* ==UserConfig== PushCat: AccessKey: title: 消息推送key # 配置的标题 description: 消息推送key https://sct.icodef.com/ type: text # 选项类型,如果不填写会根据数据自动识别 ==/UserConfig== */ let accessKey = GM_getValue("PushCat.AccessKey"); if (accessKey == "") { // 由于脚本猫v0.13的UserConfig有bug,如果你需要消息推送服务的话,请在此手动设置 GM_setValue("PushCat.AccessKey", ""); accessKey = GM_getValue("PushCat.AccessKey"); } // 消息推送: https://sct.icodef.com/ const push = new PushCat({ accessKey, }); function pushSend(title, content) { return new Promise(resolve => { if (accessKey) { push.send(title, content); } GM_notification({ title: title, text: content, timeout: 3000, }); resolve(); }) } function getSubstring(inputStr, startStr, endStr) { const startIndex = inputStr.indexOf(startStr); if (startIndex == -1) { return null; } const endIndex = inputStr.indexOf(endStr, startIndex + startStr.length); if (endIndex == -1) { return null; } return inputStr.substring(startIndex + startStr.length, endIndex); } function getRewardsInfo() { return new Promise((resolve, reject) => { // 获取今日签到信息 GM_xmlhttpRequest({ url: "https://rewards.bing.com", onload(resp) { console.log(resp); if (resp.status == 200) { resolve(resp); } else { pushSend("必应每日签到失败", "请求返回错误: " + resp.status).then(() => reject()); } }, onerror(e) { pushSend("必应每日签到失败", e || "未知错误").then(() => reject()); } }); }) } function extractKeywords(inputStr) { const regex = /"indexUrl":"","query":"(.*?)"/g; const matches = [...inputStr.matchAll(regex)]; return matches.map(match => match[1]); } let keywordList = []; let keywordIndex = 0; // 获取搜索关键字 function searchKeyword() { return new Promise((resolve, reject) => { if (keywordList.length == 0) { GM_xmlhttpRequest({ url: "https://top.baidu.com/board?platform=pc&sa=pcindex_entry", onload(resp) { if (resp.status == 200) { keywordList = extractKeywords(resp.responseText); resolve(keywordList[keywordIndex]); } else { pushSend('关键字获取失败', '热门词获取失败'); reject(new Error('关键字获取失败,' + resp.status)); } } }); } else { keywordIndex++; if (keywordIndex > keywordList.length) { keywordIndex = 0; } resolve(keywordList[keywordIndex]); } }); } let handlerNum = 0; function handler() { return getRewardsInfo().then(async resp => { handlerNum++ if (handlerNum > 30) { return true; } // 获取今日已获取积分 const data = resp.responseText const pointProgress = getSubstring(data, '"pointProgressMax":30,"pointProgress":', ',"'); if (pointProgress >= 30) { const availablePoints = getSubstring(data, '"availablePoints":', ',"'); const activeLevelName = getSubstring(data, '"activeLevelName":"', '","'); const progress = getSubstring(data, '"progress":', ',"'); const progressMax = getSubstring(data, '"progressMax":', ',"'); pushSend("必应每日签到完成", "当前等级: " + activeLevelName + "(" + progress + "/" + progressMax + ")" + "\n可用积分: " + availablePoints + " 搜索积分: " + pointProgress); return true; } else { // 进行一次搜索 GM_xmlhttpRequest({ url: "https://www.bing.com/search?q=" + await searchKeyword(), }); return false; } }); } return new Promise((resolve, reject) => { const h = async () => { try { const result = await handler(); if (result) { resolve(); } else { setTimeout(() => { h(); }, 1000); } } catch (e) { reject(); } } h(); });