HideAnnoyingPopupsLib

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

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

QingJ © 2025

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