Block Sub-Links

Removes all links and scripts with predefined domains on all sites.

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/478532/1272142/Block%20Sub-Links.js

  1. // ==UserScript==
  2. // @name Block Sub-Links
  3. // @description Removes all links and scripts with predefined domains on all sites.
  4. // @author HIDDEN-lo
  5. // @version 1.0
  6. // @match *://*/*
  7. // @match *://akuma.moe/*
  8. // @license MIT
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var blockedLinks = [
  16. 'enquirysavagely.com',
  17. 'janzuyejxmm.com',
  18. 'fzkqshbim.com',
  19. 'bootstrap.js',
  20. '2734478852/a.js',
  21. 'googletagmanager.com',
  22. 'jads.co',
  23. 'hammer.js',
  24. 'jquery.typeahead.min.js',
  25. 'app.js',
  26. 'reader.js',
  27. 'betteradsystem.com',
  28. 'window.adsbyjuicy',
  29. 'betteradsystem.com',
  30. 'adsco.re',
  31. 'trackwilltrk.com',
  32. 'adsbyjuicy',
  33. 'onclickalgo.com'
  34. ];
  35.  
  36. var blockedScriptContent = [
  37. 'f128e7d4965281fb9bfdd3dbeb9285be',
  38. 'betteradsystem.com',
  39. 'adsbyjuicy',
  40. 'gtag'
  41. ];
  42.  
  43. function removeElement(element) {
  44. if (element && element.parentNode) {
  45. element.parentNode.removeChild(element);
  46. }
  47. };
  48.  
  49. function checkBlocked() {
  50. // Checks each of the blockedLinks and sees if one matches the current page. If so, close the page.
  51. console.log('Checking for blocked links...');
  52. blockedLinks.forEach(function(link) {
  53. if (window.location.href.indexOf(link) > -1) {
  54. window.close();
  55. console.log('Removed redirect: ' + window.location.href);
  56. }
  57. });
  58. };
  59.  
  60. function checkAndRemoveLinks() {
  61. console.log('Checking for blocked links...');
  62. var links = document.querySelectorAll('a');
  63. for (var i = 0; i < links.length; i++) {
  64. for (var j = 0; j < blockedLinks.length; j++) {
  65. if (links[i].href.includes(blockedLinks[j])) {
  66. removeElement(links[i]);
  67. console.log("Removed blocked link: " + links[i].href);
  68. }
  69. }
  70. }
  71. };
  72.  
  73. function checkAndRemoveRedirects() {
  74. console.log('Checking for blocked redirects...');
  75. var metaRefreshTags = document.querySelectorAll('meta[http-equiv="refresh"]');
  76. for (var i = 0; i < metaRefreshTags.length; i++) {
  77. var content = metaRefreshTags[i].getAttribute('content');
  78. for (var j = 0; j < blockedLinks.length; j++) {
  79. if (content.includes(blockedLinks[j])) {
  80. removeElement(metaRefreshTags[i]);
  81. console.log("Removed blocked redirect: " + content);
  82. }
  83. }
  84. }
  85. };
  86.  
  87. function checkAndRemoveScripts() {
  88. console.log('Checking for blocked scripts...');
  89. var scripts = document.querySelectorAll('script');
  90. for (var i = 0; i < scripts.length; i++) {
  91. var scriptSrc = scripts[i].getAttribute('src');
  92. var scriptContent = scripts[i].textContent || scripts[i].innerText;
  93. // Check the script's content and src attribute for blocked links and specific script content
  94. for (var j = 0; j < blockedLinks.length; j++) {
  95. if (scriptSrc && scriptSrc.includes(blockedLinks[j])) {
  96. removeElement(scripts[i]);
  97. console.log("Removed blocked script (by src): " + scriptSrc);
  98. } else if (scriptContent.includes(blockedScriptContent[j])) {
  99. removeElement(scripts[i]);
  100. console.log("Removed blocked script (by content): " + scriptContent);
  101. }
  102. }
  103. }
  104. };
  105.  
  106. function checkAndRemoveIframes() {
  107. console.log('Checking for blocked iframes...');
  108. var iframes = document.querySelectorAll('iframe');
  109. for (var i = 0; i < iframes.length; i++) {
  110. var iframeSrc = iframes[i].getAttribute('src');
  111. for (var j = 0; j < blockedLinks.length; j++) {
  112. if (iframeSrc && iframeSrc.includes(blockedLinks[j])) {
  113. removeElement(iframes[i]);
  114. console.log("Removed blocked iframe: " + iframeSrc);
  115. }
  116. }
  117. }
  118. };
  119.  
  120.  
  121.  
  122. // Check and remove links, redirects, and scripts on page load
  123. checkAll();
  124. function checkAll() {
  125. checkBlocked();
  126. checkAndRemoveLinks();
  127. checkAndRemoveRedirects();
  128. checkAndRemoveScripts();
  129. checkAndRemoveIframes();
  130. };
  131.  
  132. // Timer to slow loops, as ads dont appear as ofter after a set time.
  133. var interval = 1000;
  134.  
  135. function timerCounter() {
  136. if (interval <= 6000) {
  137. interval = interval + 200;
  138. }
  139. };
  140. function executeWithDynamicInterval() {
  141. timerCounter();
  142. checkAll();
  143. console.log("Interval: " + interval);
  144. setTimeout(executeWithDynamicInterval, interval);
  145. };
  146.  
  147. executeWithDynamicInterval();
  148.  
  149. document.addEventListener("DOMContentLoaded", function () {
  150. console.log('DOM loaded! Checking...');
  151. checkAll();
  152. });
  153.  
  154. // Listen for DOM changes and check/remove links, redirects, and scripts again
  155. var observer = new MutationObserver(function(mutations) {
  156. mutations.forEach(function(mutation) {
  157. console.log('Mutation detected! Removing...');
  158. checkAll();
  159. });
  160. });
  161.  
  162. // Use a MutationObserver to detect dynamic script additions
  163. var scriptObserver = new MutationObserver(function(mutations) {
  164. mutations.forEach(function(mutation) {
  165. if (mutation.addedNodes) {
  166. console.log('Script Mutation Found! Checking...');
  167. for (var i = 0; i < mutation.addedNodes.length; i++) {
  168. var addedNode = mutation.addedNodes[i];
  169. if (addedNode.tagName === 'SCRIPT') {
  170. console.log('Mutation detected! Removing...');
  171. checkAll();
  172. }
  173. }
  174. }
  175. });
  176. });
  177.  
  178. observer.observe(document.body, { subtree: true, childList: true });
  179. scriptObserver.observe(document, { childList: true, subtree: true });
  180.  
  181. })();