V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
vsitebon
V2EX  ›  分享发现

[发现] 屏蔽标题含关键词的帖子的油猴脚本

  •  
  •   vsitebon · 2023-02-23 15:13:18 +08:00 · 527 次点击
    这是一个创建于 448 天前的主题,其中的信息可能已经有所发展或是发生改变。

    将判断条件改成正则就好了。问题来了,有办法屏蔽同音字吗?

    1 条回复    2023-02-23 16:54:42 +08:00
    mjar
        1
    mjar  
       2023-02-23 16:54:42 +08:00
    用库把文字转成拼音,再用正则屏蔽拼音。

    BTW ,谢谢分享,我现在只是把“最热”用 ublock 屏蔽掉,已经感觉干净很多了。

    附一段出处你懂的代码作为参考(我没细看):

    ```
    const Pinyin = require('pinyin');

    function matchKeyword(keyword, text) {
    // 将中文字符串转换为拼音
    const keywordPinyin = Pinyin(keyword, {style: Pinyin.STYLE_NORMAL}).join('');
    const textPinyin = Pinyin(text, {style: Pinyin.STYLE_NORMAL}).join('');
    // 在转换后的拼音中进行正则表达式匹配
    const regex = new RegExp(keywordPinyin, 'i');
    return regex.test(textPinyin);
    }

    // 示例用法
    const keyword = '苹果';
    const text = 'pingguo';
    const matched = matchKeyword(keyword, text);
    console.log(matched); // 输出 true
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5727 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:02 · PVG 14:02 · LAX 23:02 · JFK 02:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.