// ==UserScript== // @name Microsoft Bing Rewards每日任务脚本 // @version V3.2.1 // @description 原作者【怀沙2049】自动完成微软Rewards每日搜索任务:60%概率使用诗词(hitokoto),30%概率使用热门词,10%使用默认词,避免重复搜索被封号。 // @note 更新于 2025年5月5日:1) 新增Hitokoto诗词接口 https://v1.hitokoto.cn/;2) 按概率选择关键词;3) 补充中文注释。 // @author Soul233 // @match https://*.bing.com/* // @exclude https://rewards.bing.com/* // @license GNU GPLv3 // @icon https://www.bing.com/favicon.ico // @connect gumengya.com // @connect v1.hitokoto.cn // @run-at document-end // @grant GM_registerMenuCommand // @grant GM_addStyle // @grant GM_openInTab // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @namespace https://scriptcat.org/zh-CN/script-show-page/3356 // ==/UserScript== /* --------------------------- 全局变量配置 --------------------------- */ var max_rewards = 40; // 每日总搜索次数 var pause_time = 9; // 每执行4次搜索后暂停的毫秒数(旧逻辑保留),可按需修改 * 60000 以使用分钟 var search_words = []; // 存放将要执行搜索的关键词 /* -------- 热门词接口配置(保持旧逻辑不变) -------- */ var appkey = ""; // 从 https://www.gmya.net/api 申请 var HOT_WORDS_APIS = "https://api.gmya.net/Api/"; // 故梦热门词 API var KEYWORDS_SOURCE = ['BaiduHot', 'TouTiaoHot', 'DouYinHot', 'WeiBoHot']; // 轮询顺序 var current_source_index = 0; // 用于轮询来源 /* -------- 默认搜索词(当 API 全部失效时兜底使用) -------- */ var DEFAULT_SEARCH_WORDS = [ "盛年不重来,一日难再晨", "千里之行,始于足下", "少年易学老难成,一寸光阴不可轻", "敏而好学,不耻下问", "海内存知已,天涯若比邻", "三人行,必有我师焉", "莫愁前路无知已,天下谁人不识君", "人生贵相知,何用金与钱", "天生我材必有用", "海纳百川有容乃大;壁立千仞无欲则刚", "穷则独善其身,达则兼济天下", "读书破万卷,下笔如有神", "学而不思则罔,思而不学则殆", "一年之计在于春,一日之计在于晨", "莫等闲,白了少年头,空悲切", "少壮不努力,老大徒伤悲", "一寸光阴一寸金,寸金难买寸光阴", "近朱者赤,近墨者黑", "吾生也有涯,而知也无涯", "纸上得来终觉浅,绝知此事要躬行", "学无止境", "己所不欲,勿施于人", "天将降大任于斯人也", "鞠躬尽瘁,死而后已", "书到用时方恨少", "天下兴亡,匹夫有责", "人无远虑,必有近忧", "为中华之崛起而读书", "一日无书,百事荒废", "岂能尽如人意,但求无愧我心", "人生自古谁无死,留取丹心照汗青", "吾生也有涯,而知也无涯", "生于忧患,死于安乐", "言必信,行必果", "读书破万卷,下笔如有神", "夫君子之行,静以修身,俭以养德", "老骥伏枥,志在千里", "一日不读书,胸臆无佳想", "王侯将相宁有种乎", "淡泊以明志。宁静而致远,", "卧龙跃马终黄土" ]; /* -------- 新增:Hitokoto 诗词接口 -------- */ var HITOKOTO_API = "https://v1.hitokoto.cn/?c=i&encode=text"; /* ======================= 工具函数 ======================= */ /** * 从 Hitokoto 获取一条诗词。 * @returns {Promise} 诗词内容 */ async function getHitokotoWord() { const resp = await fetch(HITOKOTO_API); if (!resp.ok) throw new Error("Hitokoto API 请求失败:" + resp.status); return await resp.text(); } /** * 轮询多个热门词源直至成功。 * @returns {Promise} 热门搜索词数组 */ async function getHotWords() { while (current_source_index < KEYWORDS_SOURCE.length) { const source = KEYWORDS_SOURCE[current_source_index]; const url = appkey ? `${HOT_WORDS_APIS}${source}?format=json&appkey=${appkey}` : `${HOT_WORDS_APIS}${source}`; try { const res = await fetch(url); if (!res.ok) throw new Error(`HTTP error ${res.status}`); const data = await res.json(); if (data.data && data.data.length) { return data.data.map(item => item.title); } } catch (e) { console.error(`热门词来源 ${source} 请求失败:`, e); } current_source_index++; } // 全部失败则返回默认词 return DEFAULT_SEARCH_WORDS; } /** * 根据概率返回搜索词:60% Hitokoto / 30% 热门词 / 10% 默认词。 * @returns {Promise} */ async function chooseSearchWords() { const p = Math.random(); try { if (p < 0.6) { // 60% 概率 return [await getHitokotoWord()]; } else if (p < 0.9) { // 30% 概率 return await getHotWords(); } else { // 10% 概率 return DEFAULT_SEARCH_WORDS; } } catch (e) { console.error("获取搜索词出错,使用默认词:", e); return DEFAULT_SEARCH_WORDS; } } /** * 在字符串中插入混淆字符,降低被检测概率。 * @param {string} st 原字符串 * @returns {string} 混淆后的字符串 */ function AutoStrTrans(st) { const yStr = st; const rStr = ""; // 可自定义混淆字符 let zStr = ""; let prePo = 0; for (let i = 0; i < yStr.length;) { let step = Math.floor(Math.random() * 5) + 1; // 随机步长 1~5 if (i > 0) { zStr += yStr.substr(prePo, i - prePo) + rStr; prePo = i; } i += step; } if (prePo < yStr.length) { zStr += yStr.substr(prePo); } return zStr; } /** * 生成指定长度仅包含大写字母和数字的随机字符串。 * @param {number} length 长度 * @returns {string} */ function generateRandomString(length) { const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; let res = ""; for (let i = 0; i < length; i++) res += chars.charAt(Math.floor(Math.random() * chars.length)); return res; } /* ======================= 主流程 ======================= */ /** * 执行搜索:根据次数决定 PC/移动端,插入随机延迟与暂停。 */ function exec() { const randomDelay = Math.floor(Math.random() * 20000) + 10000; // 随机延迟 10~30 秒 const randomString = generateRandomString(4); const randomCvid = generateRandomString(32); if (GM_getValue('Cnt') == null) GM_setValue('Cnt', max_rewards + 10); const cnt = GM_getValue('Cnt'); if (cnt >= max_rewards) return; // 完成任务 document.title = `[${cnt} / ${max_rewards}] ` + document.title; // 显示进度 smoothScrollToBottom(); GM_setValue('Cnt', cnt + 1); setTimeout(() => { let nowtxt = search_words[cnt] || DEFAULT_SEARCH_WORDS[cnt % DEFAULT_SEARCH_WORDS.length]; nowtxt = AutoStrTrans(nowtxt); const baseUrl = cnt <= max_rewards / 2 ? "https://www.bing.com/search?q=" : "https://cn.bing.com/search?q="; const finalUrl = `${baseUrl}${encodeURI(nowtxt)}&form=${randomString}&cvid=${randomCvid}`; if ((cnt + 1) % 5 === 0) { setTimeout(() => { location.href = finalUrl; }, pause_time); // 暂停后继续 } else { location.href = finalUrl; } }, randomDelay); } /** * 平滑滚动到页面底部,模拟用户行为。 */ function smoothScrollToBottom() { document.documentElement.scrollIntoView({ behavior: 'smooth', block: 'end' }); } /* ======================= 菜单注册 ======================= */ GM_registerMenuCommand('开始', () => { GM_setValue('Cnt', 0); location.href = "https://www.bing.com/?br_msg=Please-Wait"; }, 'o'); GM_registerMenuCommand('停止', () => { GM_setValue('Cnt', max_rewards + 10); }, 'o'); /* ======================= 启动脚本 ======================= */ chooseSearchWords() .then(words => { search_words = words; exec(); }) .catch(err => { console.error(err); search_words = DEFAULT_SEARCH_WORDS; exec(); }); /* ======================= END ======================= */