Microsoft Bing Rewards每日任務腳本 隨機暫停

自動完成微軟Rewards每日搜尋任務,隨機搜尋次數,隨機暫停時間,每日0點重新計數搜尋次數,避免帳號因重複詞被封,新增浮動搜尋進度顯示。

// ==UserScript==
// @name         Microsoft Bing Rewards每日任务脚本 随机暂停 
// @name:zh-TW   Microsoft Bing Rewards每日任務腳本 隨機暫停 
// @name:en      Microsoft Bing Rewards Daily Task Script
// @version      V7.1.0
// @description  自动完成微软Rewards每日搜索任务,随机搜索次数,随机暂停时间,每日0点重新计数搜索次数,悬浮搜索进度显示。
// @description:zh-TW 自動完成微軟Rewards每日搜尋任務,隨機搜尋次數,隨機暫停時間,每日0點重新計數搜尋次數,避免帳號因重複詞被封,新增浮動搜尋進度顯示。
// @description:en  Automatically completes Microsoft Rewards daily search tasks and prevents account bans from repeated queries. Added floating search progress display (top-right, large font).
// @note         更新于 2025年09月14日
// @author       789cn
// @match        https://*.bing.com/*
// @exclude      https://rewards.bing.com/*
// @license      GNU GPLv3
// @icon         https://www.bing.com/favicon.ico
// @connect      gumengya.com
// @run-at       document-end
// @grant        GM_registerMenuCommand
// @grant        GM_addStyle
// @grant        GM_openInTab
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @namespace    https://greasyfork.org/zh-TW/scripts/496117
// ==/UserScript==

var max_rewards = Math.floor(Math.random() * (33 - 28 + 1)) + 28; // 随机每次搜索总次数
var pause_time = Math.floor(Math.random() * (900000 - 360000 + 1)) + 360000; // 随机暂停时间(6到15分钟)
var search_words = []; // 搜索词
var appkey = ""; // APIKEY
var Hot_words_apis = "https://api.gmya.net/Api/";

var default_search_words = [
    "盛年不重来,一日难再晨", "千里之行,始于足下", "少年易学老难成,一寸光阴不可轻", "敏而好学,不耻下问", "海内存知已,天涯若比邻",
    "三人行,必有我师焉", "莫愁前路无知已,天下谁人不识君", "人生贵相知,何用金与钱", "天生我材必有用", "海纳百川有容乃大;壁立千仞无欲则刚",
    "穷则独善其身,达则兼济天下", "读书破万卷,下笔如有神", "学而不思则罔,思而不学则殆", "一年之计在于春,一日之计在于晨",
    "莫等闲,白了少年头,空悲切", "少壮不努力,老大徒伤悲", "一寸光阴一寸金,寸金难买寸光阴", "近朱者赤,近墨者黑",
    "吾生也有涯,而知也无涯", "纸上得来终觉浅,绝知此事要躬行", "学无止境", "己所不欲,勿施于人", "天将降大任于斯人也",
    "鞠躬尽瘁,死而后已", "书到用时方恨少", "天下兴亡,匹夫有责", "人无远虑,必有近忧", "为中华之崛起而读书", "一日无书,百事荒废",
    "岂能尽如人意,但求无愧我心", "人生自古谁无死,留取丹心照汗青", "生于忧患,死于安乐", "言必信,行必果", "夫君子之行,静以修身,俭以养德",
    "老骥伏枥,志在千里", "一日不读书,胸臆无佳想", "王侯将相宁有种乎", "淡泊以明志。宁静而致远", "卧龙跃马终黄土"
];

var keywords_source = ['BaiduHot', 'TouTiaoHot', 'DouYinHot', 'WeiBoHot'];
var current_source_index = 0;

// ================== 每日重置 ==================
function checkAndResetDaily() {
    const today = new Date().toDateString();
    const lastReset = GM_getValue('lastReset', '');
    if (lastReset !== today) {
        GM_setValue('Cnt', 0);
        GM_setValue('lastReset', today);
        GM_setValue('stopped', false);
        max_rewards = Math.floor(Math.random() * (33 - 28 + 1)) + 28;
        return true;
    }
    return false;
}

// ================== 获取热门搜索词 ==================
async function douyinhot_dic() {
    while (current_source_index < keywords_source.length) {
        const source = keywords_source[current_source_index];
        let url = appkey ? Hot_words_apis + source + "?format=json&appkey=" + appkey : Hot_words_apis + source;
        try {
            const response = await fetch(url);
            if (!response.ok) throw new Error('HTTP error! status: ' + response.status);
            const data = await response.json();
            if (data.data.some(item => item)) return data.data.map(item => item.title);
        } catch (error) {
            console.error('搜索词来源请求失败:', error);
        }
        current_source_index++;
    }
    console.error('所有搜索词来源请求失败');
    return default_search_words;
}

// ================== 菜单 ==================
GM_registerMenuCommand('开始', function () {
    GM_setValue('stopped', false);
    // ✅ 不再强制清零,保持计数器延续
    checkAndResetDaily();
    location.href = "https://www.bing.com/?br_msg=Please-Wait";
}, 'o');

GM_registerMenuCommand('停止', function () {
    GM_setValue('stopped', true);
    console.log("已停止运行");
}, 'o');

// ================== 工具函数 ==================
function AutoStrTrans(st) {
    let yStr = st, rStr = "", zStr = "", prePo = 0;
    for (let i = 0; i < yStr.length;) {
        let step = parseInt(Math.random() * 5) + 1;
        if (i > 0) {
            zStr = zStr + yStr.substr(prePo, i - prePo) + rStr;
            prePo = i;
        }
        i = i + step;
    }
    if (prePo < yStr.length) zStr = zStr + yStr.substr(prePo, yStr.length - prePo);
    return zStr;
}

function generateRandomString(length) {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    let result = '';
    for (let i = 0; i < length; i++) result += characters.charAt(Math.floor(Math.random() * characters.length));
    return result;
}

// ================== 悬浮搜索进度提示 ==================
(function () {
    'use strict';
    const floatDiv = document.createElement('div');
    floatDiv.id = 'bingSearchProgress';
    floatDiv.innerText = '[0 / ' + max_rewards + ']';
    document.body.appendChild(floatDiv);

    GM_addStyle(`
        #bingSearchProgress {
            position: fixed;
            top: 80px;   /* 下移 */
            right: 20px;
            z-index: 9999;
            background: rgba(0,0,0,0.6);
            color: #fff;
            font-size: 18px;
            font-weight: bold;
            padding: 12px 18px;
            border-radius: 10px;
            box-shadow: 0 0 12px rgba(0,0,0,0.5);
            pointer-events: none;
        }
    `);

    function updateProgress() {
        const currentSearchCount = GM_getValue('Cnt', 0);
        floatDiv.innerText = `[${currentSearchCount} / ${max_rewards}]`;
    }

    setInterval(updateProgress, 1000);
    window.updateBingSearchProgress = updateProgress;
})();

// ================== 主执行 ==================
function exec() {
    if (GM_getValue('stopped', false)) {
        console.log("检测到停止标志,脚本终止。");
        return;
    }

    let randomDelay = Math.floor(Math.random() * 20000) + 10000;
    let randomString = generateRandomString(4);
    let randomCvid = generateRandomString(32);

    if (GM_getValue('Cnt') == null) GM_setValue('Cnt', 0);
    let currentSearchCount = GM_getValue('Cnt');

    if (currentSearchCount < max_rewards) {
        // ✅ 修复计数器不同步:先递增
        currentSearchCount++;
        GM_setValue('Cnt', currentSearchCount);

        let tt = document.getElementsByTagName("title")[0];
        tt.innerHTML = "[" + currentSearchCount + " / " + max_rewards + "] " + tt.innerHTML;
        smoothScrollToBottom();

        setTimeout(function () {
            if (GM_getValue('stopped', false)) return;
            let nowtxt = search_words[currentSearchCount - 1];
            nowtxt = AutoStrTrans(nowtxt);
            let searchUrl = currentSearchCount < max_rewards / 2
                ? `https://www.bing.com/search?q=${encodeURI(nowtxt)}&form=${randomString}&cvid=${randomCvid}`
                : `https://cn.bing.com/search?q=${encodeURI(nowtxt)}&form=${randomString}&cvid=${randomCvid}`;
            if (currentSearchCount % 5 === 0) {
                setTimeout(function () { if (!GM_getValue('stopped', false)) location.href = searchUrl; }, pause_time);
            } else {
                location.href = searchUrl;
            }
        }, randomDelay);
    }

    // 次日零点自动重置
    const now = new Date();
    const msUntilMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime() - now.getTime();
    setTimeout(function () {
        if (checkAndResetDaily()) {
            douyinhot_dic().then(names => {
                search_words = names;
                exec();
            }).catch(console.error);
        }
    }, msUntilMidnight);

    function smoothScrollToBottom() {
        document.documentElement.scrollIntoView({ behavior: 'smooth', block: 'end' });
    }
}

// ================== 初始化 ==================
douyinhot_dic().then(names => {
    search_words = names;
    checkAndResetDaily();
    exec();
}).catch(console.error);