|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 知乎增强 |
3 | | -// @version 1.4.8 |
| 3 | +// @version 1.4.9 |
4 | 4 | // @author X.I.U |
5 | | -// @description 移除登录弹窗、一键收起回答、收起当前回答/评论(点击两侧空白处)、快捷回到顶部(右键两侧空白处)、屏蔽指定用户、屏蔽指定关键词(标题)、屏蔽盐选内容、置顶显示时间、显示问题时间、区分问题文章、默认高清原图、默认站外直链 |
| 5 | +// @description 移除登录弹窗、一键收起回答、收起当前回答/评论(点击两侧空白处)、快捷回到顶部(右键两侧空白处)、屏蔽用户 (发布的内容)、屏蔽关键词(标题)、屏蔽盐选内容、置顶显示时间、显示问题时间、区分问题文章、默认高清原图、默认站外直链 |
6 | 6 | // @match *://www.zhihu.com/* |
7 | 7 | // @match *://zhuanlan.zhihu.com/* |
8 | 8 | // @icon https://static.zhihu.com/heifetz/favicon.ico |
@@ -406,54 +406,44 @@ function blockUsers(type) { |
406 | 406 | // 屏蔽用户按钮绑定事件(添加) |
407 | 407 | function blockUsers_button_add(name, userid, reload) { |
408 | 408 | if (!name || !userid) return |
409 | | - let users = menu_value('menu_customBlockUsers'); // 读取屏蔽列表 |
410 | | - for (let num = 0;num<users.length;num++) { // 判断是否已存在 |
411 | | - if (users[num] === name) { |
412 | | - GM_notification({text: `该用户已经被屏蔽啦,无需重复屏蔽~`, timeout: 3000}); |
413 | | - return |
| 409 | + let users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表 |
| 410 | + index = users.indexOf(name); |
| 411 | + if (index === -1) { |
| 412 | + users.push(name); // 追加用户名 |
| 413 | + GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表 |
| 414 | + // 加入知乎自带的黑名单(和本脚本互补~ |
| 415 | + GM_xmlhttpRequest({url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`,method: 'POST',timeout: 2000}); |
| 416 | + // 是否刷新本页 |
| 417 | + if (reload) { |
| 418 | + setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟 200 毫秒,避免知乎反应慢~ |
| 419 | + } else { |
| 420 | + GM_notification({text: `该用户已被屏蔽~\n刷新网页后生效~`, timeout: 3000}); |
414 | 421 | } |
415 | | - }; |
416 | | - users.push(name); // 追加用户名 |
417 | | - GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表 |
418 | | - |
419 | | - GM_xmlhttpRequest({ // 加入知乎自带的黑名单(和本脚本互补~ |
420 | | - url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`, |
421 | | - method: 'POST', |
422 | | - timeout: 2000 |
423 | | - }); |
424 | | - |
425 | | - if (reload) { |
426 | | - setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟一下,避免知乎反应慢~ |
427 | 422 | } else { |
428 | | - GM_notification({text: `该用户已被屏蔽~\n刷新网页后生效~`, timeout: 3000}); |
| 423 | + GM_notification({text: `该用户已经被屏蔽啦,无需重复屏蔽~`, timeout: 3000}); |
429 | 424 | } |
430 | 425 | } |
431 | 426 |
|
432 | 427 |
|
433 | 428 | // 屏蔽用户按钮绑定事件(删除) |
434 | 429 | function blockUsers_button_del(name, userid, reload) { |
435 | 430 | if (!name || !userid) return |
436 | | - let users = menu_value('menu_customBlockUsers'); // 读取屏蔽列表 |
437 | | - for (let num = 0;num<users.length;num++) { // 判断是否已存在 |
438 | | - if (users[num] === name) { |
439 | | - users.splice(num, 1); // 移除用户名 |
440 | | - GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表 |
441 | | - |
442 | | - GM_xmlhttpRequest({ // 移除知乎自带的黑名单 |
443 | | - url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`, |
444 | | - method: 'DELETE', |
445 | | - timeout: 2000 |
446 | | - }); |
447 | | - |
448 | | - if (reload) { |
449 | | - setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟一下,避免知乎反应慢~ |
450 | | - } else { |
451 | | - GM_notification({text: `该用户已取消屏蔽啦~\n刷新网页后生效~`, timeout: 3000}); |
452 | | - } |
453 | | - return |
| 431 | + let users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表 |
| 432 | + index = users.indexOf(name); |
| 433 | + if (index > -1) { |
| 434 | + users.splice(index, 1); // 移除用户名 |
| 435 | + GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表 |
| 436 | + // 移除知乎自带的黑名单 |
| 437 | + GM_xmlhttpRequest({url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`,method: 'DELETE',timeout: 2000}); |
| 438 | + // 是否刷新本页 |
| 439 | + if (reload) { |
| 440 | + setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟 200 毫秒,避免知乎反应慢~ |
| 441 | + } else { |
| 442 | + GM_notification({text: `该用户已取消屏蔽啦~\n刷新网页后生效~`, timeout: 3000}); |
454 | 443 | } |
455 | | - }; |
456 | | - GM_notification({text: `没有在屏蔽列表中找到该用户...`, timeout: 3000}); |
| 444 | + } else { |
| 445 | + GM_notification({text: `没有在屏蔽列表中找到该用户...`, timeout: 3000}); |
| 446 | + } |
457 | 447 | } |
458 | 448 | } |
459 | 449 |
|
|
0 commit comments