()
| 876 | |
| 877 | // 将当前选中的文字直接加入 [自定义屏蔽关键词] 列表 |
| 878 | function addSelectedKeywordToBlocklist() { |
| 879 | if (!menu_value('menu_blockKeywords')) { |
| 880 | GM_notification({text: '请先开启 [屏蔽指定关键词] 功能~', timeout: 3000}); |
| 881 | return |
| 882 | } |
| 883 | |
| 884 | const keyword = getSelectedBlockKeywordText() || selectedTextForBlockKeywords; |
| 885 | if (!keyword) { |
| 886 | GM_notification({text: '未检测到选中的文字,请先选中内容后再使用该菜单~', timeout: 3000}); |
| 887 | return |
| 888 | } |
| 889 | |
| 890 | let keywords = (GM_getValue('menu_customBlockKeywords') || []).map(function(item){return normalizeBlockKeywordText(item)}).filter(function(item){return item !== ''}); |
| 891 | if (keywords.some(function(item){return item.toLowerCase() === keyword.toLowerCase();})) { |
| 892 | GM_notification({text: `屏蔽词 [${keyword}] 已存在,无需重复添加~`, timeout: 3000}); |
| 893 | return |
| 894 | } |
| 895 | |
| 896 | keywords.push(keyword); |
| 897 | GM_setValue('menu_customBlockKeywords', keywords); |
| 898 | registerMenuCommand(); // 同步刷新缓存的菜单值 |
| 899 | GM_notification({text: `已添加屏蔽词 [${keyword}]\n后续加载的标题/评论会按该关键词过滤~`, timeout: 4000}); |
| 900 | } |
| 901 | |
| 902 | |
| 903 | // 自定义屏蔽关键词(标题) |
no test coverage detected