(name, userid, reload)
| 801 | |
| 802 | // 屏蔽用户按钮绑定事件(添加) |
| 803 | function blockUsers_button_add(name, userid, reload) { |
| 804 | if (!name || !userid) return |
| 805 | let users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表 |
| 806 | index = users.indexOf(name); |
| 807 | if (index === -1) { |
| 808 | users.push(name); // 追加用户名 |
| 809 | GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表 |
| 810 | // 加入知乎自带的黑名单(和本脚本互补~ |
| 811 | GM_xmlhttpRequest({url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`,method: 'POST',timeout: 2000}); |
| 812 | // 是否刷新本页 |
| 813 | if (reload) { |
| 814 | setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟 200 毫秒,避免知乎反应慢~ |
| 815 | } else { |
| 816 | GM_notification({text: `该用户已被屏蔽~\n刷新网页后生效~`, timeout: 3000}); |
| 817 | } |
| 818 | } else { |
| 819 | GM_notification({text: `该用户已经被屏蔽啦,无需重复屏蔽~`, timeout: 3000}); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | |
| 824 | // 屏蔽用户按钮绑定事件(删除) |
no test coverage detected