移除搜索关键词

去你妈的傻逼高亮搜索关键词。

  1. // ==UserScript==
  2. // @name No Keywords
  3. // @name:zh-CN 移除搜索关键词
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.3.3
  6. // @description Get rid of fucking highlighted search keywords.
  7. // @description:zh-CN 去你妈的傻逼高亮搜索关键词。
  8. // @author PRO
  9. // @match https://zhidao.baidu.com/question/*
  10. // @match https://www.bilibili.com/*
  11. // @match https://blog.csdn.net/*
  12. // @icon https://cors.cdn.bcebos.com/amis/namespaces/m-activity/iknow-duck/2022-12/1671625780490/%E6%90%9C%E7%B4%A2wap.png
  13. // @grant none
  14. // @license gpl-3.0
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19. const name = GM_info.script.name;
  20. const log = console.log.bind(console, `[${name}]`);
  21. // Adapted from https://www.abeautifulsite.net/posts/querying-through-shadow-roots/
  22. function shadowQueryAll(selector, rootNode = document) {
  23. const selectors = String(selector).split('>>>');
  24. let currentNodes = [rootNode];
  25. selectors.forEach((selector) => {
  26. let nextNodes = [];
  27. currentNodes.forEach(node => {
  28. if (node instanceof Element && node.shadowRoot) {
  29. nextNodes.push(...node.shadowRoot.querySelectorAll(selector));
  30. } else if (node === rootNode) {
  31. nextNodes.push(...rootNode.querySelectorAll(selector));
  32. }
  33. });
  34. currentNodes = nextNodes;
  35. });
  36. return currentNodes;
  37. }
  38. function fuck(kw) { // `kw` is the element to be fixed
  39. const txt = kw.textContent;
  40. const tn = document.createTextNode(txt);
  41. kw.parentElement.replaceChild(tn, kw);
  42. log(`Removed keyword "${txt}"`);
  43. }
  44. function purify(config) {
  45. for (const keyword of config.keywords) {
  46. shadowQueryAll(keyword).forEach(fuck);
  47. }
  48. for (const icon of config.icons) {
  49. shadowQueryAll(icon).forEach(icon => icon.remove());
  50. }
  51. }
  52. const allConfig = {
  53. "zhidao.baidu.com": {
  54. keywords: [".rich-content-container a[highlight='true']"],
  55. icons: [],
  56. persistent: false
  57. },
  58. "www.bilibili.com": {
  59. keywords: [
  60. "bili-comments >>> bili-comment-thread-renderer >>> bili-comment-renderer >>> bili-rich-text >>> a[data-keyword]",
  61. "bili-comments >>> bili-comment-thread-renderer >>> bili-comment-replies-renderer >>> bili-comment-reply-renderer >>> bili-rich-text >>> a[data-keyword]"
  62. ],
  63. icons: ["bili-comments >>> bili-comment-thread-renderer >>> bili-comment-renderer >>> bili-rich-text >>> a[data-keyword] > img"],
  64. persistent: true
  65. },
  66. "blog.csdn.net": {
  67. keywords: ["a.hl-1", "span.edu-hl.hl-1", "span.words-blog.hl-git-1"],
  68. icons: [],
  69. persistent: false
  70. }
  71. }
  72. if (!(window.location.hostname in allConfig)) return;
  73. const config = allConfig[window.location.hostname];
  74. if (config.persistent) {
  75. window.setInterval(() => {
  76. purify(config);
  77. }, 1000);
  78. } else {
  79. purify(config);
  80. }
  81. })();