You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求修改Tampermonkey脚本以支持多关键词检测及逻辑调整

多关键词检测的Tampermonkey脚本修改方案

完整修改代码

window.addEventListener('load', function() {
    console.log("Page loaded.");
    // 自定义多关键词数组,按需修改
    var lookForKeywords = ["cheese", "milk", "bread"];

    var content = document.body.textContent || document.body.innerText;
    // 遍历数组检测是否存在匹配关键词
    var foundKeyword = lookForKeywords.find(keyword => content.indexOf(keyword) !== -1);
    
    if(foundKeyword) {
        console.log(`Text found! Alerting: ${foundKeyword}`);
        alert(`Found: ${foundKeyword}`);
    } else {
        console.log("None of the keywords found - reloading.");
        location.reload();
    }
});

核心改动点

  • 将单个关键词变量替换为关键词数组lookForKeywords,可直接添加/删除需要检测的内容
  • 使用Array.find()方法快速定位第一个匹配的关键词,无匹配则返回undefined
  • 补全原脚本缺失的location.reload()语句,确保未检测到关键词时正常刷新页面
  • 弹窗内容会显示实际检测到的具体关键词,更直观

自定义提示

  • 支持中文关键词,比如把数组改成["优惠", "秒杀", "补货"]即可检测中文内容
  • 若需要区分大小写的精确匹配,可将content.indexOf(keyword) !== -1替换为content.includes(keyword)(效果一致,但更直观);如果需要忽略大小写,改用content.toLowerCase().includes(keyword.toLowerCase())

内容的提问来源于stack exchange,提问作者Haza jir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 22:42:33