HideAnnoyingPopupsLib

This script hides the annoying popups that are shown in a web page.

当前为 2025-05-10 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/535551/1586473/HideAnnoyingPopupsLib.js

  1. // ==UserScript==
  2. // @name HideAnnoyingPopupsLib
  3. // @description This script hides the annoying popups that are shown in a web page.
  4. // @grant none
  5. // @run-at document-start
  6. // @version 1.0.2
  7. // @author Cyrano68
  8. // @license MIT
  9. // @namespace https://gf.qytechs.cn/users/788550
  10. // ==/UserScript==
  11.  
  12. (function()
  13. {
  14. "use strict";
  15.  
  16. //----------------------------------------------------------------------------------------------------
  17.  
  18. const myVersion = "1.0.2"; // It must be the same value indicated in @version.
  19. consoleLog(`==> HideAnnoyingPopupsLib: HELLO! Loading script (version: ${myVersion})...`);
  20.  
  21. let mutatedNodesConfig;
  22. let mutatedAttributesConfig;
  23.  
  24. function getZeroFilledMillisecs(dateNow)
  25. {
  26. const millisecs = dateNow.getMilliseconds();
  27. return ("00" + millisecs).slice(-3);
  28. }
  29.  
  30. function consoleLog(text)
  31. {
  32. const dateNow = new Date();
  33. //const now = dateNow.toISOString();
  34. const now = dateNow.toLocaleString() + "." + getZeroFilledMillisecs(dateNow);
  35. console.log(`${now} ${text}`);
  36. }
  37.  
  38. function searchVisibleNode(node, selector)
  39. {
  40. const parentElement = node.parentElement;
  41. return (parentElement === null ? null : parentElement.querySelector(`${selector}:not([style*=\"display:none\"]):not([style*=\"display: none\"])`));
  42. }
  43.  
  44. function onMutationList(mutationList, observer)
  45. {
  46. //consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - mutationList.length=${mutationList.length}`);
  47. mutationList.forEach((mutation, i) =>
  48. {
  49. //consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - mutation[${i}] - mutation.type=${mutation.type}`);
  50. if (mutation.type === "childList")
  51. {
  52. const addedNodes = mutation.addedNodes;
  53. if (addedNodes.length > 0)
  54. {
  55. //consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - mutation[${i}] - addedNodes.length=${addedNodes.length}`);
  56. addedNodes.forEach((addedNode, j) =>
  57. {
  58. if ((mutatedNodesConfig !== undefined) && (mutatedNodesConfig !== null))
  59. {
  60. const selectors = mutatedNodesConfig.selectors;
  61. const onMutatedNode = mutatedNodesConfig.onMutatedNode;
  62.  
  63. if ((selectors !== undefined) && (selectors !== null))
  64. {
  65. for (let i = 0; i < selectors.length; ++i)
  66. {
  67. const selector = selectors[i];
  68. const foundNode = searchVisibleNode(addedNode, selector);
  69.  
  70. if ((foundNode !== undefined) && (foundNode !== null))
  71. {
  72. let stopExecution = false;
  73. if (onMutatedNode && (typeof(onMutatedNode) === "function"))
  74. {
  75. stopExecution = onMutatedNode(foundNode);
  76. }
  77.  
  78. if (!stopExecution)
  79. {
  80. const parentElement = foundNode.parentElement;
  81. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - selector='${selector}' - parentElement: tagName='${parentElement.tagName}', id='${parentElement.id}'`);
  82.  
  83. foundNode.style.display = "none"; // Hide node.
  84. foundNode.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
  85. document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
  86. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - selector='${selector}' - foundNode: tagName='${foundNode.tagName}', classList='${foundNode.classList}' ---> HIDDEN/REMOVED`);
  87. }
  88. }
  89. }
  90. }
  91. }
  92. });
  93. }
  94. }
  95. else if (mutation.type === "attributes")
  96. {
  97. if ((mutatedAttributesConfig !== undefined) && (mutatedAttributesConfig !== null))
  98. {
  99. const attributeInfos = mutatedAttributesConfig.attributeInfos;
  100. const onMutatedAttribute = mutatedAttributesConfig.onMutatedAttribute;
  101.  
  102. if ((attributeInfos !== undefined) && (attributeInfos !== null))
  103. {
  104. for (let i = 0; i < attributeInfos.length; ++i)
  105. {
  106. let attributeInfo = attributeInfos[i];
  107. let attributeName = attributeInfo.attributeName;
  108. let targetTagName = attributeInfo.targetTagName;
  109.  
  110. if ((mutation.attributeName === attributeName) && (mutation.target.tagName === targetTagName))
  111. {
  112. let stopExecution = false;
  113. if (onMutatedAttribute && (typeof(onMutatedAttribute) === "function"))
  114. {
  115. stopExecution = onMutatedAttribute(mutation);
  116. }
  117.  
  118. if (!stopExecution)
  119. {
  120. if ((mutation.attributeName === "class") && (mutation.target.tagName === "HTML") && mutation.target.classList.contains("has--adblock"))
  121. {
  122. let newAttributeValue = mutation.target.getAttribute(mutation.attributeName);
  123. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - newAttributeValue='${newAttributeValue}'`);
  124. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - BEFORE: mutation.target.classList='${mutation.target.classList}'`);
  125. mutation.target.classList.remove("has--adblock");
  126. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - AFTER: mutation.target.classList='${mutation.target.classList}'`);
  127. }
  128. else if ((mutation.attributeName === "class") && (mutation.target.tagName === "BODY") && mutation.target.classList.contains("noScroll"))
  129. {
  130. let newAttributeValue = mutation.target.getAttribute(mutation.attributeName);
  131. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - newAttributeValue='${newAttributeValue}'`);
  132. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - BEFORE: mutation.target.classList='${mutation.target.classList}'`);
  133. mutation.target.classList.remove("noScroll");
  134. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - AFTER: mutation.target.classList='${mutation.target.classList}'`);
  135. }
  136. else if ((mutation.attributeName === "style") && (mutation.target.tagName === "HTML") && (mutation.target.style.overflow === "hidden"))
  137. {
  138. let newAttributeValue = mutation.target.getAttribute(mutation.attributeName);
  139. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - newAttributeValue='${newAttributeValue}'`);
  140. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - BEFORE: mutation.target.style.overflow='${mutation.target.style.overflow}'`);
  141. mutation.target.style.overflow = "";
  142. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - AFTER: mutation.target.style.overflow='${mutation.target.style.overflow}'`);
  143. }
  144. else if ((mutation.attributeName === "style") && (mutation.target.tagName === "BODY") && (mutation.target.style.overflow === "hidden"))
  145. {
  146. let newAttributeValue = mutation.target.getAttribute(mutation.attributeName);
  147. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - newAttributeValue='${newAttributeValue}'`);
  148. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - BEFORE: mutation.target.style.overflow='${mutation.target.style.overflow}'`);
  149. mutation.target.style.overflow = "";
  150. consoleLog(`==> HideAnnoyingPopupsLib: onMutationList - AFTER: mutation.target.style.overflow='${mutation.target.style.overflow}'`);
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. });
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------------------
  162.  
  163. function configure(inMutationObserverConfig, mutatedNodesConfigIn, mutatedAttributesConfigIn)
  164. {
  165. consoleLog(`==> HideAnnoyingPopupsLib: configure - BEGIN`);
  166.  
  167. // SEE: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
  168. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  169.  
  170. // Create an observer instance linked to the callback function.
  171. const mutationObserver = new MutationObserver(onMutationList);
  172.  
  173. mutatedNodesConfig = mutatedNodesConfigIn;
  174. mutatedAttributesConfig = mutatedAttributesConfigIn;
  175.  
  176. let arrayLength = 0;
  177. if ((mutatedNodesConfig !== undefined) && (mutatedNodesConfig !== null))
  178. {
  179. const selectors = mutatedNodesConfig.selectors;
  180. if ((selectors !== undefined) && (selectors !== null))
  181. {
  182. arrayLength = mutatedNodesConfig.selectors.length;
  183. }
  184. }
  185. consoleLog(`==> HideAnnoyingPopupsLib: configure - mutatedNodesConfig.selectors.length=${arrayLength}`);
  186.  
  187. arrayLength = 0;
  188. if ((mutatedAttributesConfig !== undefined) && (mutatedAttributesConfig !== null))
  189. {
  190. const attributeInfos = mutatedAttributesConfig.attributeInfos;
  191. if ((attributeInfos !== undefined) && (attributeInfos !== null))
  192. {
  193. arrayLength = mutatedAttributesConfig.attributeInfos.length;
  194. }
  195. }
  196. consoleLog(`==> HideAnnoyingPopupsLib: configure - mutatedAttributesConfig.attributeInfos.length=${arrayLength}`);
  197.  
  198. // Start observing the target node for configured mutations.
  199. mutationObserver.observe(document, inMutationObserverConfig);
  200.  
  201. consoleLog(`==> HideAnnoyingPopupsLib: configure - END`);
  202. }
  203.  
  204. function getVersion()
  205. {
  206. return myVersion;
  207. }
  208.  
  209. // Expose the public interface by returning an object
  210. window.HideAnnoyingPopupsLib =
  211. {
  212. configure: configure,
  213. getVersion: getVersion
  214. };
  215.  
  216. consoleLog("==> HideAnnoyingPopupsLib: Script loaded");
  217. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址