// ==UserScript== // @name Microsoft Bing Rewards每日任务脚本 // @namespace https://greasyfork.org/users/1362311 // @version 4.0.11 // @description 自动完成微软积分每日搜索任务 // @author honguangli // @license MIT // @match https://www.bing.com/* // @match https://cn.bing.com/* // @match https://rewards.bing.com/* // @icon https://www.bing.com/favicon.ico // @run-at document-end // @grant GM_registerMenuCommand // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @connect api.gumengya.com // @downloadURL https://update.greasyfork.icu/scripts/507570/Microsoft%20Bing%20Rewards%E6%AF%8F%E6%97%A5%E4%BB%BB%E5%8A%A1%E8%84%9A%E6%9C%AC.user.js // @updateURL https://update.greasyfork.icu/scripts/507570/Microsoft%20Bing%20Rewards%E6%AF%8F%E6%97%A5%E4%BB%BB%E5%8A%A1%E8%84%9A%E6%9C%AC.meta.js // ==/UserScript== (function() { 'use strict'; // 仅在顶层框架运行 if (window.top !== window.self) { return; } const keywordApi = 'https://api.gumengya.com/Api/'; // 词条接口 const rewardHost = 'https://rewards.bing.com'; // 积分页面 const searchHost = 'https://www.bing.com'; // 搜索页面 const pathnames = ['/', '/search']; // 触发搜索页面 const autoRunSearch = '?runMode=auto&runKey=1362311'; // 自动触发任务参数 const searchTimes = 40; // 自动搜索次数 const searchDelaySecondsMin = 15; // 每次搜索最小延迟时间,单位秒 const searchDelaySecondsMax = 30; // 每次搜索最大延迟时间,单位秒 const searchDelaySecondsFirst = 3; // 首次搜索延迟时间,单位秒,设置为0时立即触发 const closeTaskCardDelaySeconds = 0; // 搜索完成后弹窗自动关闭延迟时间,单位秒,设置为0时需手动关闭 const searchSafeDelayTimes = 4; // 每搜索n次后触发长暂停 const searchSafeDelaySeconds = 0 * 60; // 每次触发长暂停时长,单位秒 const clickDelaySecondsFirst = 3; // 首次搜索延迟时间,单位秒 const startBtn = true; // 是否在搜索框附近插入任务启动按钮 const startBtnText = '获取积分'; // 任务启动按钮文本 const dailyBtn = true; // 是否在搜索框附近插入获取每日活动积分按钮 const dailyBtnText = '获取积分2'; // 获取每日活动积分按钮文本 // 搜索词条库 const searchKeySource = [ { name: '百度', action: 'BaiduHot' }, { name: '抖音', action: 'DouYinHot' }, { name: '搜狗', action: 'SoGouHot' }, { name: '360', action: 'SoHot' }, { name: '微博', action: 'WeiBoHot' }, { name: '知乎', action: 'ZhiHuHot' }, { name: '今日头条', action: 'TouTiaoHot' }, { name: '快手', action: 'KuaiShouHot' } ]; // 默认词条 const defaultKeywords = [ '众芳摇落独暄妍', '占尽风情向小园', '疏影横斜水清浅', '暗香浮动月黄昏', '霜禽欲下先偷眼', '粉蝶如知合断魂', '幸有微吟可相狎', '不须檀板共金樽', '剪绡零碎点酥乾', '向背稀稠画亦难', '日薄从甘春至晚', '霜深应怯夜来寒', '澄鲜只共邻僧惜', '冷落犹嫌俗客看', '忆着江南旧行路', '酒旗斜拂堕吟鞍', '东风夜放花千树', '更吹落', '星如雨', '宝马雕车香满路', '凤箫声动', '玉壶光转', '一夜鱼龙舞', '蛾儿雪柳黄金缕', '笑语盈盈暗香去', '众里寻他千百度', '蓦然回首', '那人却在', '灯火阑珊处', '君不见黄河之水天上来', '奔流到海不复回', '君不见高堂明镜悲白发', '朝如青丝暮成雪', '人生得意须尽欢', '莫使金樽空对月', '天生我材必有用', '千金散尽还复来', '烹羊宰牛且为乐', '会须一饮三百杯', '岑夫子', '丹丘生', '将进酒', '杯莫停', '与君歌一曲', '请君为我倾耳听', '钟鼓馔玉不足贵', '但愿长醉不愿醒', '古来圣贤皆寂寞', '惟有饮者留其名', '陈王昔时宴平乐', '斗酒十千恣欢谑', '主人何为言少钱', '径须沽取对君酌', '五花马', '千金裘', '呼儿将出换美酒', '与尔同销万古愁' ]; const timeKey = 'time'; // 时间戳 const countKey = 'count'; // 计数器 const pointsKey = 'points'; // 当日初始积分 const searchPointsKey = 'searchPoints'; // 当日搜索任务初始积分 const keywordsKey = 'search'; // 搜索词条 const searchParamKey = 'param'; // 搜索参数 // web worker let delayWorker = null; // 搜索任务 let scrollWorker = null; // 模拟浏览 GM_addStyle('#reward-task { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, .2); z-index: 99999; }'); GM_addStyle('#reward-task > .reward-task-content { max-width: 460px; margin: calc(50vh - 32px) auto 0; padding: 20px; background-color: #ffffff; border: 1px solid #e4e7ed; border-radius: 20px; color: #303133; overflow: hidden; transition: 0.3s; box-shadow: 0px 0px 12px rgba(0,0,0,0.12); }'); GM_addStyle('#reward-task > .reward-task-content > div { display: flex; flex-flow: row wrap; align-items: center; column-gap: 12px; }'); GM_addStyle('#reward-task > .reward-task-content > div > .item { width: 160px; padding: 7px 0; }'); GM_addStyle('#reward-task > .reward-task-content > div > .tips { padding: 7px 0; color: #E6A23C; }'); GM_addStyle('#reward-task > .reward-task-content > div > .btn-wrap { flex-grow: 1; text-align: right; }'); GM_addStyle('.reward-task-btn { display: inline-block; line-height: 1; white-space: nowrap; cursor: pointer; background: #fff; border: 1px solid #dcdfe6; -webkit-appearance: none; text-align: center; -webkit-box-sizing: border-box; box-sizing: border-box; outline: 0; margin: 0; -webkit-transition: .1s; transition: .1s; font-weight: 500; padding: 8px 16px; font-size: 14px; border-radius: 4px; color: #606266; background-color: #ffffff; border: 1px solid #dcdfe6; border-color: #dcdfe6; }'); GM_addStyle('.reward-task-btn.warning { color: #fff; background-color: #ebb563; border-color: #ebb563; }'); GM_addStyle('#ScopeRow { margin-top: 48px; }'); // 注册菜单 const registerMenuCommand = () => { // 启动搜索任务 GM_registerMenuCommand('获取积分', () => { start(); }); // 启动搜索任务,含每日活动任务 GM_registerMenuCommand('获取积分2(含每日活动)', () => { navigateToRewardPage(); }); // 停止任务 GM_registerMenuCommand('停止', () => { stop(); removeTaskCard(); }); // 更新词条 GM_registerMenuCommand('更新词条', () => { new Promise((resolve, reject) => { let source = Math.floor(Math.random() * searchKeySource.length); queryKeywordList(source, resolve, reject); }).then( () => { alert('获取词条成功'); }).catch( err => { alert('获取词条失败:' + err.message); }); }); // 生成随机词条 GM_registerMenuCommand('生成随机词条', () => { const keywords = generateKeywordList(100); const today = new Date(); today.setHours(0); today.setMinutes(0); today.setSeconds(0); today.setMilliseconds(0); GM_setValue(keywordsKey, { time: today.getTime(), source: 0, keywords: keywords, }); }); }; // 启动搜索任务 const start = () => { GM_setValue(countKey, 1); GM_setValue(searchPointsKey, -1); search(); }; // 结束搜索任务 const stop = () => { GM_setValue(countKey, 0); GM_setValue(searchPointsKey, -1); if (scrollWorker) { scrollWorker.postMessage({ type: "end" }); } }; // 跳转积分页面并运行每日活动任务 const navigateToRewardPage = () => { location.href = rewardHost + autoRunSearch; }; // 跳转搜索页面并运行搜索任务 const navigateToSearchPage = () => { location.href = searchHost + autoRunSearch; }; // 自动点击完成每日活动积分 const autoClickRewardActivity = () => { insertActivityTaskCard( () => { navigateToSearchPage(); }); }; // 搜索 const search = () => { const count = GM_getValue(countKey); if (!count || count <= 0 || count > searchTimes + 1) { stop(); return; } // 延迟时间 const delay = count === 1 ? searchDelaySecondsFirst : Math.floor(Math.random() * (searchDelaySecondsMax - searchDelaySecondsMin + 1)) + searchDelaySecondsMin + (count % searchSafeDelayTimes !== 1 ? 0 : searchSafeDelaySeconds); // 添加任务进度卡片 insertTaskCard(count - 1, delay, () => { // 获取词条 getSearchInfo().then( keyword => { const queryInput = document.getElementById('sb_form_q'); const param = `?q=${ encodeURIComponent(keyword) }&form=${ Math.random() > 0.4 ? 'QBLH' : 'QBRE' }&sp=-1&lq=0&pq=${ queryInput ? encodeURIComponent(queryInput.value) || '' : '' }&sc=0-0&qs=n&sk=&cvid=${ generateRandomString(32) }&ghsh=0&ghacc=0&ghpl=`; // 更新计数器 GM_setValue(countKey, count+1); // 更新搜索参数 GM_setValue(searchParamKey, param); // 触发搜索 location.href = searchHost + '/search' + param; }).catch( err => { stop(); removeTaskCard(); alert('获取词条失败:' + err.message); }); }); if (count > searchTimes) { return; } // 模拟浏览网页 pretendHuman(); }; // 获取词条 const getSearchInfo = () => { return new Promise((resolve, reject) => { const today = new Date(); today.setHours(0); today.setMinutes(0); today.setSeconds(0); today.setMilliseconds(0); let source = Math.floor(Math.random() * searchKeySource.length); const saveConfig = GM_getValue(keywordsKey); // 当日缓存的搜索词还未用完 if (saveConfig && saveConfig.time === today.getTime()) { if (saveConfig.keywords.length > 0) { const keyword = saveConfig.keywords[0]; saveConfig.keywords.splice(0, 1); GM_setValue(keywordsKey, saveConfig); resolve(keyword); return; } else { source = (saveConfig.source + 1) % searchKeySource.length; } } // 更新词条 queryKeywordList(source, resolve, reject); }); }; // 更新词条 const queryKeywordList = (source, resolve, reject) => { const today = new Date(); today.setHours(0); today.setMinutes(0); today.setSeconds(0); today.setMilliseconds(0); // 获取新词条 const queryKeyword = (config, retry) => { GM_xmlhttpRequest({ method: 'GET', url: keywordApi + searchKeySource[config.source].action, headers: { "Content-Type": "application/json" }, responseType: 'json', onload: response => { if (response.status !== 200 || !response.response) { handleErr(new Error('调用Api失败'), retry, config); return; } if (response.response.code !== 200) { handleErr(new Error(response.response.msg), retry, config); return; } config.keywords = Array.from(new Set(response.response.data.map(item => searchKeySource[config.source].name + ' ' + item.title + ' ' + generateRandomString(3)))); config.keywords.splice(50); const keyword = config.keywords[0]; config.keywords.splice(0, 1); GM_setValue(keywordsKey, config); resolve(keyword); }, onerror: err => { handleErr(err, retry, config); }, }); }; // 失败处理,支持重试 const handleErr = (err, retry, config) => { if (retry <= 0) { console.error(`获取词条[${ searchKeySource[config.source].name }]:失败终止`, err); //reject(err); config.keywords = generateKeywordList(100); const keyword = config.keywords[0]; config.keywords.splice(0, 1); GM_setValue(keywordsKey, config); resolve(keyword); return; } console.warn(`获取词条[${ searchKeySource[config.source].name }]:失败重试[第${ searchKeySource.length - retry }次]`, err); setTimeout(() => { queryKeyword({ time: config.time, source: (config.source + 1) % searchKeySource.length, keywords: [], }, retry-1); }, 500); }; // 获取新词条 queryKeyword({ time: today.getTime(), source: source, keywords: [], }, 0, searchKeySource.length - 1); }; // 生成随机词条 const generateKeywordList = (size) => { if (size <= 0) { return; } const keywords = []; for (let i = 0; i < defaultKeywords.length && keywords.length < size * 1.2; i++) { if (defaultKeywords[i].length < 3) { keywords.push(defaultKeywords[i]); continue; } let j = 0; while (j < defaultKeywords[i].length) { let z = Math.min(defaultKeywords[i].length, Math.floor(Math.random() * 3) + 2 + j); keywords.push(defaultKeywords[i].slice(j, z)); j = z; } if (Math.random() >= 0.5) { keywords.push(generateRandomStringZh(5)); } } return Array.from(new Set(keywords)).slice(0, size); }; // 插入启动按钮 const insertStartBtn = () => { if (document.getElementById('reward-task-start')) { document.getElementById('reward-task-start').remove(); } if (!startBtn) { return; } // 获取搜索表单 const queryForm = document.getElementById('sb_form'); // 添加启动按钮 const btn = document.createElement('button'); btn.appendChild(document.createTextNode(startBtnText)); btn.setAttribute('id', 'reward-task-start'); btn.setAttribute('type', 'button'); btn.classList.add('reward-task-btn'); btn.style.setProperty('margin', '8px'); btn.style.setProperty('padding', '8px 24px'); btn.style.setProperty('border-radius', '24px'); btn.onclick = () => { start(); }; // 首页表单会重置组件内容,需要等待几秒后再插入 setTimeout( () => { queryForm.appendChild(btn); }, location.pathname !== '/' ? 0 : 5000); }; // 插入启动按钮2 const insertDailyBtn = () => { if (document.getElementById('reward-task-daily')) { document.getElementById('reward-task-daily').remove(); } if (!dailyBtn) { return; } // 获取搜索表单 const queryForm = document.getElementById('sb_form'); // 添加启动按钮2 const btn = document.createElement('button'); btn.appendChild(document.createTextNode(dailyBtnText)); btn.setAttribute('id', 'reward-task-daily'); btn.setAttribute('type', 'button'); btn.classList.add('reward-task-btn'); btn.style.setProperty('margin', '8px'); btn.style.setProperty('padding', '8px 24px'); btn.style.setProperty('border-radius', '24px'); btn.onclick = () => { navigateToRewardPage(); }; // 首页表单会重置组件内容,需要等待几秒后再插入 setTimeout( () => { queryForm.appendChild(btn); }, location.pathname !== '/' ? 0 : 5000); }; // 插入搜索任务卡片 const insertTaskCard = (times, delay, finish) => { removeTaskCard(); // 添加搜索任务卡片 const h = `
当前积分:${ getCurrPoints() }
本次获得积分:${ getTaskPoints() }
当日获得积分:${ getTodayPoints() }
进度:${ times } / ${ searchTimes }
${ times >= searchTimes ? `已完成${ closeTaskCardDelaySeconds > 0 ? ',' + closeTaskCardDelaySeconds + '秒后自动关闭' : '' }` : `等待时间:${ delay } 秒 ` }
当前积分:${ getCurrPoints() }
本次获得积分:${ getTaskPoints() }
当日获得积分:${ getTodayPoints() }
每日任务:${ daily.finish } / ${ daily.total }
更多任务:${ more.finish } / ${ more.total }
等待时间:${ delay } 秒
注意:每日任务必须在12:00后执行才能获得积分!