Block sensitive words

Block sensitive words on a specific news website.

目前为 2025-02-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Block sensitive words
  3. // @namespace http://tampermonkey.net/
  4. // @version 2025-02-16
  5. // @description Block sensitive words on a specific news website.
  6. // @author You
  7. // @match https://www.index.hr/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=index.hr
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const trigger = () => {
  17. const sensitiveWords = [
  18. "magarc",
  19. "magarac",
  20. "konj",
  21. "mačk",
  22. "mačak",
  23. "tovar",
  24. "životinj",
  25. "ljubimac",
  26. "ljubimci",
  27. ];
  28.  
  29. console.log(`Blocking ${sensitiveWords.length} sensitive words`);
  30.  
  31. try {
  32. if (sensitiveWords.some(x => document.title.toLowerCase().includes(x))) {
  33. document.title = "";
  34.  
  35. document.querySelector("#comments-container").innerHTML = "";
  36. }
  37. } catch {
  38. //
  39. }
  40.  
  41. try {
  42. if (sensitiveWords.some(x => document.URL.toLowerCase().includes(x))) {
  43. window.history.pushState('/', 'Title', '/');
  44. }
  45. } catch {
  46. //
  47. }
  48.  
  49. const isSensitive = (text) => {
  50. try {
  51. return sensitiveWords.some(x => text.toLowerCase().includes(x));
  52. } catch {
  53. console.log("Something failed with checking isSensitive");
  54. return false;
  55. }
  56. }
  57.  
  58. const elements = document.querySelectorAll('h1,h2,h3,.title,div.summary,a,p,.text-holder');
  59. const length = elements.length;
  60.  
  61. console.log(`Found ${length} elements`);
  62.  
  63. for (let i = 0; i < length - 1; i++) {
  64. try {
  65. if (isSensitive(elements[i].innerHTML)) {
  66. elements[i].innerHTML = "";
  67. }
  68. } catch {
  69. //
  70. }
  71. }
  72.  
  73. const images = document.querySelectorAll('img');
  74. const imgLength = elements.length;
  75.  
  76. console.log(`Found ${imgLength} images`);
  77.  
  78. for (let z = 0; z < imgLength - z; z++) {
  79. try {
  80. if (isSensitive(images[z].alt)) {
  81. images[z].parentElement.innerHTML = "";
  82. }
  83. } catch {
  84. //
  85. }
  86. }
  87. };
  88.  
  89. trigger();
  90.  
  91. const resizeObserver = new ResizeObserver(() => {
  92. trigger();
  93. });
  94.  
  95. resizeObserver.observe(document.querySelector("body"));
  96. })();