CC98 Tools - Block List

CC98 tools for blocking user, title, content and board.

  1. // ==UserScript==
  2. // @name CC98 Tools - Block List
  3. // @version 0.0.4
  4. // @description CC98 tools for blocking user, title, content and board.
  5. // @icon https://www.cc98.org/static/98icon.ico
  6.  
  7. // @author ml98
  8. // @namespace https://www.cc98.org/user/name/ml98
  9. // @license MIT
  10.  
  11. // @match https://www.cc98.org/*
  12. // @match https://www-cc98-org-s.webvpn.zju.edu.cn:8001/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. /* 屏蔽列表 */
  17. const CONFIG = {
  18. userName: [], /* 用户名,如 ["ml98"] */
  19. title: [], /* 标题关键字或正则表达式,如 ["男生进", "女生进"] */
  20. content: [], /* 帖子内容关键字或正则表达式,如 ["欧蓝德", /^bd$/] */
  21. board: [], /* 版面id,如 [182, 357, 758] */
  22. };
  23.  
  24.  
  25. const log = () => {};
  26. CONFIG.content.push(...(CONFIG.userName).map(userName => `楼:用户${userName}在`));
  27. CONFIG.title = CONFIG.title.map((t) => new RegExp(t));
  28. CONFIG.content = CONFIG.content.map((c) => new RegExp(c));
  29. log('config', CONFIG);
  30.  
  31. const isBlockedId = (_id) => _id && CONFIG.userName.includes(_id);
  32. const isBlockedTitle = (_title) => _title && CONFIG.title.some((t) => t.test(_title));
  33. const isBlockedContent = (_content) => _content && CONFIG.content.some((c) => c.test(_content));
  34. const isBlockedBoard = (_boardId) => _boardId && CONFIG.board.includes(_boardId);
  35.  
  36. const topicRegExp = new RegExp("/board/\\d+/topic");
  37. const postRegExp = new RegExp("/Topic/\\d+/(hot-)?post");
  38.  
  39. const isTopicAPI = (url) => url.includes("/topic/new") ||
  40. url.includes("/me/custom-board/topic") ||
  41. url.includes("/topic/search?keyword=") ||
  42. topicRegExp.test(url);
  43. const isPostAPI = (url) => postRegExp.test(url);
  44. const isIndexAPI = (url) => url.includes("/config/index");
  45.  
  46. const resolve = (url, data) => {
  47. log(url);
  48. log('before', data);
  49. if (isTopicAPI(url)) {
  50. data = data.filter(
  51. (r) =>
  52. !(
  53. isBlockedId(r.userName) ||
  54. isBlockedTitle(r.title) ||
  55. isBlockedBoard(r.boardId)
  56. )
  57. );
  58. } else if (isPostAPI(url)) {
  59. data = data.filter(
  60. (r) =>
  61. !(
  62. isBlockedId(r.userName) ||
  63. isBlockedContent(r.content) ||
  64. isBlockedBoard(r.boardId)
  65. )
  66. );
  67. } else if (isIndexAPI(url)) {
  68. data.hotTopic = data.hotTopic.filter(
  69. (r) =>
  70. !(
  71. isBlockedId(r.authorName) ||
  72. isBlockedTitle(r.title) ||
  73. isBlockedBoard(r.boardId)
  74. )
  75. );
  76. }
  77. log('after', data);
  78. return data;
  79. };
  80.  
  81. const origResponseJSON = Response.prototype.json;
  82. Response.prototype.json = function () {
  83. return origResponseJSON.call(this).then((data) => resolve(this.url, data));
  84. };