Greasy Fork

Greasy Fork is available in English.

Microsoft Rewards 自动获取搜索积分

自动完成Microsoft Rewards每日搜索任务,显示今日积分获取进度,自动计算搜索次数,积分等级1和等级2均可使用

当前为 2025-12-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Microsoft Rewards 自动获取搜索积分
// @namespace    http://tampermonkey.net/
// @version      1.4.5
// @description  自动完成Microsoft Rewards每日搜索任务,显示今日积分获取进度,自动计算搜索次数,积分等级1和等级2均可使用
// @author       MIANKRAM
// @match        *://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_openInTab
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// @grant        GM_addValueChangeListener
// @grant        GM_xmlhttpRequest
// @run-at       document-end
// @license      MIT
// ==/UserScript==
 
(function () {
    'use strict';
 
    if (window.self !== window.top) return;
 
    const CONFIG = {
        rewardsUrl: "https://rewards.bing.com/redeem/pointsbreakdown",
        searchBaseUrl: "https://www.bing.com/search?q=",
        weiboApi: "https://weibo.com/ajax/side/hotSearch",
        keys: {
            l1: 'rewardsPointsLevel1',
            l2: 'rewardsPointsLevel2',
            status: 'rewardsGlobalStatus',
            trigger: 'rewardsStartSignal',
            total: 'rewardsTotalPoints' 
        },
        selectors: {
            total: "#rh_rwm > div > span.points-container, #fly_id_rwds_b > div > div > div.hb_value_col",
            l1_pc: "#userPointsBreakdown > div > div:nth-child(2) > div > div > div > div.pointsDetail > mee-rewards-user-points-details > div > div > div > div > p.pointsDetail.c-subheading-3.ng-binding",
            l2_pc: "#userPointsBreakdown > div > div:nth-child(2) > div > div:nth-child(1) > div > div.pointsDetail > mee-rewards-user-points-details > div > div > div > div > p.pointsDetail.c-subheading-3.ng-binding",
            l2_mobile: "#userPointsBreakdown > div > div:nth-child(2) > div > div:nth-child(2) > div > div.pointsDetail > mee-rewards-user-points-details > div > div > div > div > p.pointsDetail.c-subheading-3.ng-binding"
        }
    };
 
    const INSTANCE_ID = Math.random().toString(36).substr(2, 9);
 
    let state = {
        isRunning: false,
        isRemoteRunning: false,
        hotWords: [],
        timers: {
            search: null,
            countdown: null,
            slaveCountdown: null,
            sync: null,
            heartbeat: null
        }
    };
 
const FALLBACK_KEYWORDS = [
    "2025科技趋势", "2026科技预测", "Surface Pro 11", "Surface新款", "iPhone 17 Pro", 
    "iPhone 17 Air", "华为Mate 70 Pro", "华为Pura 80", "小米16 Ultra", "三星Galaxy S26", 
    "OPPO Find X8", "vivo X200", "荣耀Magic 7", "一加14", "真我GT7", "红米K80", 
    "魅族22", "鸿蒙HarmonyOS NEXT", "iOS 19新功能", "Android 16特性", "Windows 12下载", 
    "macOS新版本", "Ubuntu 24.04", "Deepin V23", "Arch Linux", "Kali Linux", "CentOS Stream", 
    "Debian教程", "Steam Deck 2", "Switch 2首发", "PS5 Pro评测", "Xbox新主机", 
    "RTX 5090显卡", "RTX 5080参数", "RX 8900 XT", "Intel酷睿Ultra", "AMD锐龙9000", 
    "DDR6内存", "PCIe 6.0硬盘", "Wi-Fi 7路由器", "蓝牙6.0技术", "6G通信标准", 
    "星链Starlink", "固态电池量产", "钠离子电池", "可控核聚变", "量子计算", "脑机接口", 
    "人形机器人", "波士顿动力", "特斯拉Optimus", "SpaceX发射", "SpaceX星舰", 
    "NASA登月计划", "中国空间站", "韦伯望远镜", "引力波探测", "超导材料", "石墨烯应用", 
    "生物3D打印", "基因编辑CRISPR", "Python教程", "Java面试题", "C++标准", "Rust语言入门", 
    "Go语言实战", "JavaScript框架", "TypeScript技巧", "React 19", "Vue 3.5", "Angular新版", 
    "Svelte 5", "Flutter开发", "SwiftUI教程", "Kotlin协程", "Docker容器", "Docker部署", 
    "Kubernetes K8s", "微服务架构", "Serverless计算", "GraphQL接口", "REST API设计", 
    "MySQL优化", "Redis缓存", "MongoDB教程", "PostgreSQL", "Elasticsearch", 
    "Kafka消息队列", "Nginx配置", "Nginx反向代理", "Linux命令大全", "Git常用命令", 
    "Vim快捷键", "VS Code插件", "Cursor编辑器", "IntelliJ IDEA", "PyCharm激活", 
    "GitHub Copilot", "DeepSeek Coder", "GPT-5最新", "Claude 3.5 Sonnet", "Gemini Ultra", 
    "文心一言4.0", "讯飞星火", "通义千问", "Kimi智能助手", "Midjourney V7", 
    "Stable Diffusion XL", "DALL-E 3", "Sora视频生成", "Runway Gen-3", "Pika Labs", 
    "AI绘画提示词", "AI生成PPT", "AI写论文", "AI去水印", "AI修图", "Notion AI", 
    "Notion模板", "Obsidian插件", "Logseq教程", "Excel函数公式", "PPT制作技巧", 
    "Word排版", "XMind思维导图", "Figma教程", "Sketch资源", "Adobe PS 2025", 
    "Premiere剪辑", "DaVinci调色", "Blender建模", "C4D渲染", "Unity开发", 
    "Unreal Engine 5", "Godot引擎", "Raspberry Pi 5", "Arduino开发", "ESP32教程", 
    "STM32单片机", "PCB设计", "KiCad教程", "Altium Designer", "Verilog语法", 
    "FPGA入门", "Matlab仿真", "Latex排版", "Markdown语法", "Regex正则表达式", 
    "JSON格式化", "XML解析", "YAML语法", "HTTP状态码", "TCP/IP协议", "WebSockets", 
    "MQTT协议", "OAuth2.0", "JWT认证", "SSL证书", "DNS解析", "CDN加速", "Apache配置", 
    "Tomcat部署", "Maven构建", "Gradle配置", "Jenkins流水线", "GitLab CI/CD", 
    "Ansible自动化", "Terraform", "Prometheus监控", "Grafana面板", "天气预报", 
    "空气质量", "台风路径", "地震预警", "万年历2026", "农历转换", "法定节假日", 
    "调休安排", "春运抢票", "高铁时刻表", "航班动态", "地铁线路图", "公交实时查询", 
    "网约车优惠", "共享单车", "今日油价", "油价调整", "92号汽油", "95号汽油", 
    "新能源充电桩", "特斯拉超充", "违章查询", "驾照扣分", "车险报价", "二手车估值", 
    "汽车保养", "轮胎更换", "行车记录仪", "ETC办理", "健康食谱", "减肥餐", "低卡零食", 
    "高蛋白食物", "痛风饮食", "糖尿病食谱", "宝宝辅食", "家常菜做法", "空气炸锅食谱", 
    "电饭煲美食", "烘焙教程", "鸡尾酒调法", "咖啡豆推荐", "茶叶分类", "股市行情", 
    "A股大盘", "港股通", "美股纳斯达克", "标普500", "基金净值", "ETF基金", "可转债", 
    "国债逆回购", "银行理财", "大额存单", "存款利率", "LPR房贷利率", "公积金贷款", 
    "社保查询", "医保报销", "养老金计算", "个税计算", "个税计算器", "年终奖扣税", 
    "汇率换算", "美元汇率", "日元汇率", "欧元汇率", "比特币价格", "以太坊走势", 
    "黄金价格", "白银期货", "国际油价", "新能源车", "小米SU7 Max", "比亚迪仰望U8", 
    "蔚来ET9", "小鹏X9", "理想MEGA", "问界M9", "极氪001", "智界S7", "阿维塔12", 
    "特斯拉Model Y", "坦克700", "方程豹豹5", "自动驾驶FSD", "激光雷达", "ChatGPT技巧", 
    "提示词工程", "LLM微调", "RAG检索增强", "LangChain教程", "HuggingFace", 
    "Transformers", "PyTorch教程", "TensorFlow", "Keras入门", "旅游攻略", "特价机票", 
    "酒店预订", "民宿推荐", "迪士尼攻略", "环球影城", "川西自驾", "新疆旅游", 
    "西藏路线", "云南大理", "三亚海景房", "哈尔滨冰雪", "日本自由行", "泰国签证", 
    "新加坡免签", "马尔代夫", "欧洲申根签", "护照办理", "露营装备", "徒步路线", 
    "滑雪场推荐", "潜水考证", "钓鱼技巧", "摄影构图", "电影推荐", "豆瓣高分", 
    "奥斯卡获奖", "春节档电影", "漫威新片", "DC电影", "奈飞热剧", "国产剧排行", 
    "美剧推荐", "韩剧更新", "日剧推荐", "动漫新番", "海贼王最新", "火影忍者", 
    "进击的巨人", "鬼灭之刃", "咒术回战", "间谍过家家", "星链卫星", "火星殖民", 
    "载人航天", "空间站直播", "天文现象", "流星雨时间", "日食月食", "极光预测", 
    "AI发展", "通用人工智能", "图灵测试", "深度学习", "机器学习", "神经网络", 
    "计算机视觉", "NLP自然语言", "知识图谱", "数据挖掘", "亚运会", "奥运会", "世界杯", 
    "欧洲杯", "NBA赛程", "CBA直播", "英超积分榜", "西甲皇马", "欧冠决赛", "F1赛车", 
    "网球大满贯", "斯诺克", "乒乓球WTT", "羽毛球公开赛", "UFC格斗", "马拉松报名", 
    "华为Mate60", "麒麟芯片", "卫星通话", "发改委通知", "公积金提取", "居住证办理", 
    "户口迁移", "身份证补办", "结婚登记", "离婚手续", "出生证明", "专项附加扣除", 
    "考研资料", "考研政治", "考研英语", "考研数学", "专业课真题", "复试技巧", 
    "调剂信息", "公务员考试", "国考报名", "省考时间", "申论范文", "行测题库", "事业单位", 
    "教师资格证", "普通话考试", "四六级查分", "雅思口语", "托福听力", "GRE词汇", 
    "CPA注册会计", "一建二建", "法考主观题", "高考志愿", "双一流大学", "QS排名", 
    "强基计划", "综评招生", "专升本", "成人自考", "简历模板", "面试技巧", "自我介绍", 
    "职场沟通", "远程办公", "副业赚钱", "自媒体运营", "短视频脚本", "直播带货", 
    "跨境电商", "亚马逊运营", "TikTok玩法", "独立站Shopify", "SEO优化", "SEM竞价", 
    "私域流量", "品牌营销", "危机公关", "甲流症状", "支原体肺炎", "新冠变异", "带状疱疹", 
    "九价HPV", "狂犬疫苗", "流感疫苗", "体检报告", "幽门螺旋杆菌", "洗牙团购", 
    "近视手术", "正畸牙套", "失眠治疗", "抑郁症自测", "MBTI测试", "星座运势", 
    "塔罗牌占卜", "周公解梦", "单位换算", "BMI计算器", "房贷计算器", "日期计算器", 
    "进制转换", "二维码生成", "图片压缩", "PDF转Word", "视频格式转换", "在线翻译", 
    "繁简转换", "IP查询", "网速测试", "端口扫描", "Whois查询", "垃圾分类", "邮编查询", 
    "区号查询", "我的世界", "王者荣耀", "和平精英", "原神", "崩坏星穹铁道", "绝区零", 
    "英雄联盟", "云顶之弈", "无畏契约", "穿越火线", "地下城与勇士", "魔兽世界", 
    "炉石传说", "DOTA2", "CS2", "Apex英雄", "永劫无间", "黑神话悟空", "艾尔登法环", 
    "赛博朋克2077", "荒野大镖客2", "博德之门3", "只狼", "塞尔达传说", "宝可梦", 
    "马里奥", "动森", "健身环大冒险", "双11红包", "618满减", "年货节", "百亿补贴", 
    "李佳琦直播", "董宇辉", "罗永浩", "疯狂星期四", "麦当劳优惠", "瑞幸9.9", "库迪咖啡", 
    "喜茶新品", "霸王茶姬", "海底捞暗号", "山姆会员", "Costco必买", "宜家好物", 
    "无印良品", "优衣库折扣", "始祖鸟", "Lululemon", "萨洛蒙", "Hoka跑鞋", "冲锋衣推荐", 
    "羽绒服品牌", "防晒霜测评", "洗面奶推荐", "电动牙刷", "吹风机推荐", "扫地机器人", 
    "洗地机", "投影仪", "智能门锁", "机械键盘轴体", "Cherry MX轴", "凯华BOX轴", 
    "TTC金粉轴", "客制化键盘", "GMK键帽", "热插拔套件", "罗技GPW3", "雷蛇毒蝰V3", 
    "卓威鼠标", "人体工学椅", "赫曼米勒Aeron", "升降桌推荐", "显示器支架", "屏幕挂灯", 
    "桌面搭建", "RGB灯带", "雷电4扩展坞", "NAS群晖", "极空间Z4", "Jellyfin搭建", 
    "Plex媒体库", "家庭影院", "回音壁推荐", "4K投影仪", "极米投影", "当贝投影", 
    "蓝光原盘", "PT下载", "乐高新品", "高达模型", "PG独角兽", "手办预定", "HotToys漫威", 
    "盲盒隐藏款", "泡泡玛特", "Switch卡带", "PS5手柄", "Xbox Elite 3", 
    "Steam Deck OLED", "ROG Ally X", "AYANEO掌机", "怀旧掌机", "街机模拟器", 
    "3D打印机", "拓竹Bambu Lab", "光固化打印", "无人机航拍", "大疆Mini 4 Pro", 
    "Insta360 X4", "GoPro Hero 13", "大疆Action 5", "单反相机", "微单推荐", 
    "索尼A7M5", "佳能EOS R5 II", "尼康Z8", "富士X100VI", "理光GR3x", "镜头推荐", 
    "大光圈定焦", "长焦镜头", "人像摄影", "风光摄影", "街拍技巧", "延时摄影", 
    "Lightroom预设", "Photoshop 2025", "Capture One", "视频剪辑", "Final Cut Pro", 
    "剪映专业版", "OBS直播", "麦克风推荐", "舒尔SM7B", "声卡调试", "监听耳机", 
    "森海塞尔HD600", "HiFi音箱", "真力音箱", "黑胶唱机", "索尼Walkman", "流媒体音乐", 
    "Spotify会员", "Apple Music古典", "Tidal无损", "Qobuz", "网易云黑胶", 
    "B站大会员", "YouTube Premium", "Netflix拼车", "Disney+订阅", "HBO Max", 
    "Kindle Scribe", "微信读书", "得到App", "樊登读书", "豆瓣高分书", "科幻小说", 
    "三体全集", "沙丘原著", "阿西莫夫", "东野圭吾", "村上春树", "余华活着", "金庸全集", 
    "哈利波特", "魔戒", "断舍离", "极简主义", "手账排版", "子弹笔记", "时间管理", 
    "番茄工作法", "GTD工作法", "心流状态", "费曼学习法", "快速阅读", "记忆宫殿", 
    "英语口语", "雅思听力", "多邻国", "背单词App", "Anki卡片", "TED演讲", "Coursera课程", 
    "Udemy教程", "猫粮推荐", "渴望猫粮", "巅峰罐头", "猫砂除臭", "宠物驱虫", 
    "布偶猫", "金渐层", "缅因猫", "柯基", "柴犬", "边牧智商", "宠物医院", "宠物保险", 
    "水族造景", "草缸教程", "热带鱼", "海水缸", "多肉植物", "室内绿植", "龟背竹", 
    "鲜花养护", "阳台种菜", "露营帐篷", "天幕推荐", "户外电源", "卡式炉", "钛杯", 
    "冲锋衣", "硬壳外套", "登山鞋", "巴塔哥尼亚", "北面羽绒服", "迪卡侬", "CrossFit", 
    "普拉提", "尊巴舞", "马拉松配速", "骑行路线", "公路车", "崔克Trek", "闪电Specialized", 
    "捷安特", "美利达", "Brompton小布", "电动滑板车", "平衡车", "装修避坑", "全屋定制", 
    "除甲醛", "智能马桶", "恒温花洒", "汉斯格雅", "杜拉维特", "乳胶床垫", "席梦思", 
    "记忆棉枕", "遮光窗帘", "指纹锁", "可视门铃", "扫拖机器人", "洗碗机", "嵌入式冰箱", 
    "垃圾处理器", "净水器", "RO反渗透", "空气净化器", "加湿器", "除湿机", "戴森吹风机", 
    "徕芬", "咖啡机", "德龙咖啡机", "布雷维尔", "意式浓缩", "手冲咖啡", "V60滤杯", 
    "摩卡壶", "咖啡豆烘焙", "精酿啤酒", "IPA啤酒", "单一麦芽", "威士忌", "红酒品鉴", 
    "鸡尾酒", "普洱茶", "大红袍", "龙井茶", "紫砂壶", "烘焙工具", "厨师机", "烤箱推荐", 
    "低筋面粉", "黄油推荐", "淡奶油", "马卡龙", "戚风蛋糕", "欧包教程"
];
 
    if (location.href.startsWith(CONFIG.rewardsUrl)) {
        const checkExist = setInterval(function () {
            const l1El = document.querySelector(CONFIG.selectors.l1_pc);
            const l2PcEl = document.querySelector(CONFIG.selectors.l2_pc);
            const l2MobEl = document.querySelector(CONFIG.selectors.l2_mobile);
 
            if (l1El || (l2PcEl && l2MobEl)) {
                clearInterval(checkExist);
 
                setTimeout(() => {
                    const finalL1El = document.querySelector(CONFIG.selectors.l1_pc);
                    const finalL2PcEl = document.querySelector(CONFIG.selectors.l2_pc);
                    const finalL2MobEl = document.querySelector(CONFIG.selectors.l2_mobile);
 
                    let dataToSave = {};
                    
                    if (finalL2PcEl && finalL2MobEl) {
                        dataToSave = {
                            level: 2,
                            pc: finalL2PcEl.innerText,
                            mobile: finalL2MobEl.innerText,
                            timestamp: Date.now()
                        };
                        GM_setValue(CONFIG.keys.l2, dataToSave);
                        GM_setValue(CONFIG.keys.l1, null);
                    } else if (finalL1El) {
                        dataToSave = {
                            level: 1,
                            pc: finalL1El.innerText,
                            timestamp: Date.now()
                        };
                        GM_setValue(CONFIG.keys.l1, dataToSave);
                        GM_setValue(CONFIG.keys.l2, null);
                    }
                    window.close();
                }, 5000);
            }
        }, 500);
        setTimeout(() => clearInterval(checkExist), 20000);
        return;
    }
 
    function updateTotalPointsFromBing() {
        if (!location.hostname.includes('bing.com')) return;
        const totalEl = document.querySelector(CONFIG.selectors.total);
        if (totalEl) {
            const pointsText = totalEl.innerText.trim().replace(/,/g, '');
            if (pointsText !== "" && pointsText.match(/^\d+$/)) {
                GM_setValue(CONFIG.keys.total, {
                    points: pointsText,
                    timestamp: Date.now()
                });
                console.log(`[Rewards] 总积分更新: ${pointsText}`);
                updateUI();
            }
        }
    }
 
    function fetchHotSearchKeywords() {
        GM_xmlhttpRequest({
            method: "GET",
            url: CONFIG.weiboApi,
            onload: function (response) {
                try {
                    const json = JSON.parse(response.responseText);
                    if (json?.data?.realtime) {
                        const words = json.data.realtime.map(item => item.word_scheme || item.word);
                        state.hotWords = [...new Set([...words, ...FALLBACK_KEYWORDS])].sort(() => Math.random() - 0.5);
                    } else throw new Error();
                } catch (e) { state.hotWords = [...FALLBACK_KEYWORDS].sort(() => Math.random() - 0.5); }
            },
            onerror: function () { state.hotWords = [...FALLBACK_KEYWORDS].sort(() => Math.random() - 0.5); }
        });
    }
 
    function getNextKeyword() {
        if (!state.hotWords || state.hotWords.length === 0) state.hotWords = [...FALLBACK_KEYWORDS].sort(() => Math.random() - 0.5);
        return state.hotWords.shift();
    }
 
    function parsePoints(str) {
        if (!str) return { current: 0, max: 0, remaining: 0, percent: 0 };
        const parts = str.split('/');
        if (parts.length !== 2) return { current: 0, max: 0, remaining: 0, percent: 0 };
        const current = parseInt(parts[0].replace(/[^0-9]/g, '')) || 0;
        const max = parseInt(parts[1].replace(/[^0-9]/g, '')) || 0;
        return { current, max, remaining: Math.ceil((max - current) / 3), percent: max > 0 ? (current / max) * 100 : 0 };
    }
 
    function getRemainingTasks() {
        const l1 = GM_getValue(CONFIG.keys.l1);
        const l2 = GM_getValue(CONFIG.keys.l2);
 
        const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
 
        if (l2) {
            if (isMobile) {
                return parsePoints(l2.mobile).remaining;
            } else {
                return parsePoints(l2.pc).remaining;
            }
        } else if (l1) {
            return parsePoints(l1.pc).remaining;
        }
        return 0;
    }
 
    function performSearch() {
        if (!location.hostname.includes('bing.com')) return;
 
        updateTotalPointsFromBing();
 
        const keyword = getNextKeyword();
        const sbInput = document.getElementById('sb_form_q');
        const sbForm = document.getElementById('sb_form');
        const sbGo = document.getElementById('sb_form_go') || document.getElementById('search_icon');
 
        if (sbInput) {
            let lastValue = sbInput.value;
            sbInput.value = keyword;
            const tracker = sbInput._valueTracker;
            if (tracker) tracker.setValue(lastValue);
            sbInput.dispatchEvent(new Event('input', { bubbles: true }));
            sbInput.dispatchEvent(new Event('change', { bubbles: true }));
 
            const titleEl = document.querySelector('.neon-title');
            if (titleEl) {
                titleEl.innerText = `搜: ${keyword.substring(0, 6)}...`;
                setTimeout(() => titleEl.innerText = "Microsoft Rewards", 5000);
            }
            setTimeout(() => {
                if (sbGo) sbGo.click();
                else if (sbForm) sbForm.submit();
            }, 300 + Math.random() * 200);
        }
    }
 
    function startLoop() {
        if (state.isRunning || state.isRemoteRunning) return;
 
        if (!location.hostname.includes('bing.com')) {
            console.log("[Rewards] 启动器模式:发送启动信号并打开新标签页...");
            GM_setValue(CONFIG.keys.trigger, Date.now());
            if (state.hotWords.length === 0) fetchHotSearchKeywords();
            const keyword = getNextKeyword();
            const url = CONFIG.searchBaseUrl + encodeURIComponent(keyword);
            GM_openInTab(url, { active: true, insert: true });
            state.isRemoteRunning = true;
            togglePanel(true);
            updateUI();
            return;
        }
 
        console.log("[Rewards] 工作模式:开始执行任务循环");
        state.isRunning = true;
        updateGlobalStatus(true, Date.now() + 60000);
        togglePanel(true);
        updateUI();
        if (state.hotWords.length === 0) fetchHotSearchKeywords();
        performSearch();
 
        updateRemainingDisplay(getRemainingTasks() - 1);
 
        if (state.timers.sync) clearInterval(state.timers.sync);
 
        state.timers.sync = setInterval(() => {
            GM_openInTab(CONFIG.rewardsUrl, { active: false, insert: true });
        }, 30000); 
 
        const schedule = () => {
            if (!state.isRunning) return;
            const remaining = getRemainingTasks();
 
            if (remaining <= 0) { stopLoop(true); return; }
 
            const delay = Math.floor(Math.random() * (120 - 80 + 1)) + 80;
            const targetTime = Date.now() + (delay * 1000);
 
            updateGlobalStatus(true, targetTime);
            if (state.timers.heartbeat) clearInterval(state.timers.heartbeat);
            state.timers.heartbeat = setInterval(() => { updateGlobalStatus(true, targetTime); }, 5000);
 
            if (state.timers.countdown) clearInterval(state.timers.countdown);
            state.timers.countdown = setInterval(() => {
                const left = Math.ceil((targetTime - Date.now()) / 1000);
                updateTimerDisplay(left);
                if (Date.now() >= targetTime) {
                    clearInterval(state.timers.countdown);
                    if (state.isRunning) {
                        performSearch();
                        schedule();
                    }
                }
            }, 1000);
        };
        schedule();
    }
 
    function updateGlobalStatus(isRunning, nextSearchTime = 0) {
        GM_setValue(CONFIG.keys.status, {
            isRunning: isRunning,
            owner: isRunning ? INSTANCE_ID : null,
            timestamp: Date.now(),
            nextSearchTime: nextSearchTime
        });
    }
 
    function stopLoop(completed = false) {
        console.log("[Rewards] 停止任务");
        state.isRunning = false;
 
        const currentStatus = GM_getValue(CONFIG.keys.status);
        if (currentStatus && currentStatus.owner === INSTANCE_ID) {
            updateGlobalStatus(false);
        } else if (!completed) {
            updateGlobalStatus(false);
        }
 
        if (state.timers.countdown) clearInterval(state.timers.countdown);
        if (state.timers.sync) clearInterval(state.timers.sync);
        if (state.timers.heartbeat) clearInterval(state.timers.heartbeat);
 
        updateTimerDisplay(completed ? "完成" : "已停止");
        updateUI(completed);
    }
 
    window.addEventListener('beforeunload', () => { });
 
    GM_addValueChangeListener(CONFIG.keys.status, (name, oldVal, newVal, remote) => {
        if (newVal && newVal.isRunning) {
            if (newVal.owner !== INSTANCE_ID) {
                if (state.isRunning) stopLoop(false);
                if (!state.isRemoteRunning) togglePanel(true);
                state.isRemoteRunning = true;
                if (newVal.nextSearchTime) startSlaveCountdown(newVal.nextSearchTime);
                updateUI();
            }
        } else {
            state.isRemoteRunning = false;
            if (state.isRunning) stopLoop(false);
            stopSlaveCountdown();
            updateUI();
        }
    });
 
    function startSlaveCountdown(targetTime) {
        if (state.timers.slaveCountdown) clearInterval(state.timers.slaveCountdown);
        const updateSlaveTimer = () => {
            const left = Math.ceil((targetTime - Date.now()) / 1000);
            updateTimerDisplay(left > 0 ? left : 0);
        };
        updateSlaveTimer();
        state.timers.slaveCountdown = setInterval(updateSlaveTimer, 1000);
    }
 
    function stopSlaveCountdown() {
        if (state.timers.slaveCountdown) clearInterval(state.timers.slaveCountdown);
        updateTimerDisplay("待机");
    }
 
    function updateTimerDisplay(val) {
        const el = document.getElementById('neon-timer');
        if (el) el.innerText = typeof val === 'number' ? `${val}s` : val;
    }
 
    function updateRemainingDisplay(val) {
        const el = document.getElementById('neon-remaining');
        if (el) el.innerText = val > 0 ? val : 0;
    }
 
    function togglePanel(show) {
        const panel = document.getElementById('neon-panel');
        if (panel) {
            if (show) panel.classList.add('show');
            else panel.classList.remove('show');
        }
    }
 
    GM_addStyle(`
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap');
        :root { --neon-bg: rgba(20, 20, 25, 0.75); --neon-border: rgba(255, 255, 255, 0.1); --neon-primary: #00f2ea; --neon-secondary: #ff0055; --neon-text: #ffffff; --glass-blur: blur(16px); }
        #neon-fab { position: fixed; bottom: 30px; right: 30px; width: 50px; height: 50px; background: var(--neon-bg); backdrop-filter: var(--glass-blur); border: 1px solid var(--neon-border); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10000; box-shadow: 0 8px 32px rgba(0,0,0,0.3); transition: all 0.3s; }
        #neon-fab:hover { transform: scale(1.1); border-color: var(--neon-primary); box-shadow: 0 0 15px rgba(0, 242, 234, 0.3); }
        #neon-fab svg { width: 24px; height: 24px; fill: var(--neon-primary); }
        #neon-panel { position: fixed; bottom: 90px; right: 30px; width: 300px; background: var(--neon-bg); backdrop-filter: var(--glass-blur); border: 1px solid var(--neon-border); border-radius: 16px; padding: 20px; z-index: 10000; font-family: 'Inter', sans-serif; color: var(--neon-text); box-shadow: 0 16px 48px rgba(0,0,0,0.4); opacity: 0; visibility: hidden; transform: translateY(20px) scale(0.95); transition: all 0.3s; pointer-events: none; }
        #neon-panel.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); pointer-events: auto; }
        .neon-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 10px; }
        .neon-title { font-weight: 800; font-size: 14px; background: linear-gradient(90deg, #fff, #bbb); -webkit-background-clip: text; -webkit-text-fill-color: transparent; max-width: 160px; }
        .neon-controls { display: flex; align-items: center; gap: 10px; }
        .neon-refresh { font-size: 12px; color: #a0a0a0; cursor: pointer; transition: color 0.2s; }
        .neon-refresh:hover { color: var(--neon-primary); }
        .neon-close { font-size: 20px; color: #a0a0a0; cursor: pointer; line-height: 1; transition: color 0.2s; font-family: sans-serif; }
        .neon-close:hover { color: var(--neon-secondary); }
        .neon-row { margin-bottom: 12px; }
        .neon-label-row { display: flex; justify-content: space-between; font-size: 12px; color: #a0a0a0; margin-bottom: 4px; }
        .neon-progress-bg { width: 100%; height: 4px; background: rgba(255,255,255,0.05); border-radius: 2px; overflow: hidden; }
        .neon-progress-bar { height: 100%; background: linear-gradient(90deg, var(--neon-primary), #00c2ff); width: 0%; transition: width 0.6s ease; box-shadow: 0 0 8px rgba(0, 242, 234, 0.4); }
        .neon-dashboard { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
        .neon-card { background: rgba(255,255,255,0.03); border-radius: 12px; padding: 10px; text-align: center; position: relative; }
        .neon-card.wide { grid-column: span 2; display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; }
        .neon-card.wide .neon-card-val { margin-top: 0; font-size: 24px; color: #ffeb3b; text-shadow: 0 0 10px rgba(255, 235, 59, 0.3); }
        .neon-card-label { font-size: 11px; color: #a0a0a0; text-transform: uppercase; letter-spacing: 1px; }
        .neon-card-val { font-size: 20px; font-weight: 800; margin-top: 5px; color: var(--neon-primary); }
        #neon-action-btn { width: 100%; margin-top: 20px; padding: 12px; background: var(--neon-primary); color: #000; font-weight: 800; border: none; border-radius: 8px; cursor: pointer; transition: all 0.2s; text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }
        #neon-action-btn:hover { box-shadow: 0 0 20px rgba(0, 242, 234, 0.5); transform: translateY(-1px); }
        #neon-action-btn:disabled { background: #333; color: #666; cursor: not-allowed; box-shadow: none; transform: none; }
        .neon-pulse { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--neon-secondary); opacity: 0.2; transition: all 0.3s; }
        .neon-pulse.active { opacity: 1; box-shadow: 0 0 10px var(--neon-secondary); }
    `);
 
    function createUI() {
        if (document.getElementById('neon-fab')) return;
        const fab = document.createElement('div');
        fab.id = 'neon-fab';
        fab.innerHTML = `<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>`;
        document.body.appendChild(fab);
 
        const panel = document.createElement('div');
        panel.id = 'neon-panel';
        panel.innerHTML = `
            <div class="neon-header">
                <span class="neon-title">Microsoft Rewards</span>
                <div class="neon-controls">
                    <span class="neon-refresh" id="neon-refresh" title="同步数据">手动同步</span>
                    <span class="neon-close" id="neon-close" title="隐藏面板">×</span>
                </div>
            </div>
            <div id="neon-content"><div style="text-align:center; color:#666; font-size:12px; padding:20px;">正在初始化...</div></div>
            <div class="neon-dashboard">
                <div class="neon-card wide">
                    <div class="neon-card-label">总积分 BALANCE</div>
                    <div class="neon-card-val" id="neon-total-points">--</div>
                </div>
                <div class="neon-card"><div class="neon-pulse"></div><div class="neon-card-label">本设备剩余</div><div class="neon-card-val" id="neon-remaining">--</div></div>
                <div class="neon-card"><div class="neon-card-label">下次搜索</div><div class="neon-card-val" id="neon-timer" style="color:#fff;">--</div></div>
            </div>
            <button id="neon-action-btn">开始运行</button>
        `;
        document.body.appendChild(panel);
 
        fab.addEventListener('click', () => panel.classList.toggle('show'));
        document.getElementById('neon-refresh').addEventListener('click', () => {
            GM_openInTab(CONFIG.rewardsUrl, { active: false, insert: true });
        });
 
        document.getElementById('neon-close').addEventListener('click', (e) => {
            e.stopPropagation();
            panel.classList.remove('show');
        });
 
        document.addEventListener('click', (e) => {
            if (!panel.contains(e.target) && !fab.contains(e.target) && panel.classList.contains('show')) panel.classList.remove('show');
        });
        updateUI();
    }
 
    function updateUI(isCompleted = false) {
        const container = document.getElementById('neon-content');
        if (!container) return;
 
        const l1 = GM_getValue(CONFIG.keys.l1);
        const l2 = GM_getValue(CONFIG.keys.l2);
        const totalPointsData = GM_getValue(CONFIG.keys.total); 
        const remaining = getRemainingTasks();
        const remainingEl = document.getElementById('neon-remaining');
        if (remainingEl) remainingEl.innerText = remaining;
 
        const totalEl = document.getElementById('neon-total-points');
        if (totalEl) {
            let totalTxt = "--";
            if (totalPointsData && totalPointsData.points) totalTxt = totalPointsData.points;
            totalEl.innerText = totalTxt;
        }
 
        let html = '';
        if (l2) {
            const pc = parsePoints(l2.pc);
            const mob = parsePoints(l2.mobile);
            const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
            const pcStyle = !isMobile ? 'color:#fff; font-weight:bold;' : 'color:#a0a0a0;';
            const mobStyle = isMobile ? 'color:#fff; font-weight:bold;' : 'color:#a0a0a0;';
 
            html += `
                <div class="neon-row"><div class="neon-label-row"><span style="${pcStyle}">PC 端 ${!isMobile ? '(当前)' : ''}</span> <span>${l2.pc}</span></div><div class="neon-progress-bg"><div class="neon-progress-bar" style="width:${pc.percent}%"></div></div></div>
                <div class="neon-row"><div class="neon-label-row"><span style="${mobStyle}">移动端 ${isMobile ? '(当前)' : ''}</span> <span>${l2.mobile}</span></div><div class="neon-progress-bg"><div class="neon-progress-bar" style="width:${mob.percent}%; background: linear-gradient(90deg, #ff0055, #ff5e00);"></div></div></div>
            `;
        } else if (l1) {
            const pc = parsePoints(l1.pc);
            html += `<div class="neon-row"><div class="neon-label-row"><span>积分进度</span> <span>${l1.pc}</span></div><div class="neon-progress-bg"><div class="neon-progress-bar" style="width:${pc.percent}%"></div></div></div>`;
        } else {
            html = `<div style="text-align:center; color:#aaa; font-size:12px; padding:10px;">暂无 PC/移动端积分数据 (点击手动同步)</div>`;
        }
        container.innerHTML = html;
 
        const btn = document.getElementById('neon-action-btn');
        const newBtn = btn.cloneNode(true);
        btn.parentNode.replaceChild(newBtn, btn);
 
        if (state.isRunning) {
            newBtn.innerText = "停止运行";
            newBtn.disabled = false;
            newBtn.style.opacity = "1";
            newBtn.style.background = "var(--neon-secondary)";
            newBtn.style.color = "#fff";
            newBtn.onclick = () => stopLoop(false);
        } else if (state.isRemoteRunning) {
            newBtn.innerText = "停止 (后台运行中)";
            newBtn.disabled = false;
            newBtn.style.opacity = "1";
            newBtn.style.background = "#555";
            newBtn.onclick = () => stopLoop(false);
        } else if (isCompleted || (remaining <= 0 && (l1 || l2))) {
            newBtn.innerText = "当前设备任务完成";
            newBtn.disabled = true;
            newBtn.style.background = "rgba(255,255,255,0.1)";
            newBtn.style.color = "#aaa";
        } else {
            newBtn.innerText = "开始运行";
            newBtn.disabled = false;
            newBtn.style.opacity = "1";
            newBtn.style.background = "var(--neon-primary)";
            newBtn.style.color = "#000";
            newBtn.onclick = startLoop;
        }
    }
 
    GM_addValueChangeListener(CONFIG.keys.l1, () => updateUI());
    GM_addValueChangeListener(CONFIG.keys.l2, () => updateUI());
    GM_addValueChangeListener(CONFIG.keys.total, () => updateUI()); 
 
    window.addEventListener('load', () => {
        createUI();
        fetchHotSearchKeywords();
        
        if (location.hostname.includes('bing.com')) {
            setTimeout(updateTotalPointsFromBing, 2000); 
        }
 
 
        const triggerTime = GM_getValue(CONFIG.keys.trigger);
        if (triggerTime && (Date.now() - triggerTime < 15000)) {
            if (location.hostname.includes("bing.com")) {
                console.log("[Rewards] 检测到启动信号,本页面接管任务...");
                GM_setValue(CONFIG.keys.trigger, 0);
                setTimeout(startLoop, 1000);
                return;
            }
        }
 
        const currentStatus = GM_getValue(CONFIG.keys.status);
        if (currentStatus && currentStatus.isRunning && currentStatus.owner !== INSTANCE_ID) {
            if (Date.now() - currentStatus.timestamp < 180000) {
                state.isRemoteRunning = true;
                if (currentStatus.nextSearchTime) startSlaveCountdown(currentStatus.nextSearchTime);
                updateUI();
            } else {
                updateGlobalStatus(false);
            }
        }
        
        setTimeout(() => {
            if (!GM_getValue(CONFIG.keys.l1) && !GM_getValue(CONFIG.keys.l2)) {
                GM_openInTab(CONFIG.rewardsUrl, { active: false, insert: true });
            }
        }, 1500);
    });
 
})();