Gazzetta.it: Hide the "Using AdBlock" popup

This script hides the "Using AdBlock" popup that is shown when you use an ad-block.

当前为 2025-04-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Gazzetta.it: Hide the "Using AdBlock" popup
  3. // @name:it Gazzetta.it: Nasconde il popup "AdBlock In Uso"
  4. // @description This script hides the "Using AdBlock" popup that is shown when you use an ad-block.
  5. // @description:it Questo script nasconde il popup "AdBlock In Uso" che viene visualizzato quando si usa un ad-block.
  6. // @match https://*.gazzetta.it/*
  7. // @grant none
  8. //// @run-at document-start
  9. // @version 1.0.1
  10. // @author Cyrano68
  11. // @license MIT
  12. // @namespace https://greasyfork.org/users/788550
  13. // ==/UserScript==
  14.  
  15. (function()
  16. {
  17. "use strict";
  18.  
  19. function console_log(text)
  20. {
  21. const dateNow = new Date();
  22. //let now = dateNow.toISOString();
  23. let now = dateNow.toLocaleString() + "." + dateNow.getMilliseconds();
  24. console.log(`${now} ${text}`);
  25. }
  26.  
  27. console_log("==> Gazzetta_it_HideAdBlockPopup: HELLO! Loading script...");
  28.  
  29. document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
  30. window.addEventListener("load", onWindowLoaded);
  31.  
  32. createMutationObserver();
  33.  
  34. function onDOMContentLoaded()
  35. {
  36. console_log(`==> Gazzetta_it_HideAdBlockPopup: onDOMContentLoaded - document.readyState=${document.readyState}`);
  37. // DO NOTHING!
  38. }
  39.  
  40. function onWindowLoaded()
  41. {
  42. console_log(`==> Gazzetta_it_HideAdBlockPopup: onWindowLoaded - document.readyState=${document.readyState}`);
  43. // DO NOTHING!
  44. }
  45.  
  46. function onMutationList(mutationList, observer)
  47. {
  48. //console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - mutationList.length=${mutationList.length}`);
  49. mutationList.forEach((mutation, i) =>
  50. {
  51. //console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - mutation[${i}] - mutation.type=${mutation.type}`);
  52. if (mutation.type === "childList")
  53. {
  54. let addedNodes = mutation.addedNodes;
  55. if (addedNodes.length > 0)
  56. {
  57. //console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - mutation[${i}] - addedNodes.length=${addedNodes.length}`);
  58. addedNodes.forEach((addedNode, j) =>
  59. {
  60. let searchedDiv = searchVisibleNode(addedNode, "div.privacy-cp-wall");
  61. if (searchedDiv !== null)
  62. {
  63. //console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - searchedDiv.outerHTML='${searchedDiv.outerHTML}'`);
  64.  
  65. let parentElement = searchedDiv.parentElement;
  66. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
  67.  
  68. searchedDiv.style.display = "none"; // Hide node.
  69. document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
  70. searchedDiv.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
  71. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - 'privacy-cp-wall' - mutation[${i}], addedNode[${j}] - searchedDiv.tagName='${searchedDiv.tagName}', searchedDiv.classList='${searchedDiv.classList}' ---> HIDDEN/REMOVED`);
  72. }
  73.  
  74. let searchedDiv2 = searchVisibleNode(addedNode, "div.adblock__container");
  75. if (searchedDiv2 !== null)
  76. {
  77. //console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - searchedDiv2.outerHTML='${searchedDiv2.outerHTML}'`);
  78.  
  79. let parentElement = searchedDiv2.parentElement;
  80. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
  81.  
  82. searchedDiv2.style.display = "none"; // Hide node.
  83. document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
  84. searchedDiv2.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
  85. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - 'adblock__container' - mutation[${i}], addedNode[${j}] - searchedDiv2.tagName='${searchedDiv2.tagName}', searchedDiv2.classList='${searchedDiv2.classList}' ---> HIDDEN/REMOVED`);
  86. }
  87. });
  88. }
  89. }
  90. else if (mutation.type === "attributes")
  91. {
  92. //console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - mutation.attributeName='${mutation.attributeName}', mutation.oldValue='${mutation.oldValue}'`);
  93.  
  94. if ((mutation.target.tagName === "HTML") && (mutation.attributeName === "class") && mutation.target.classList.contains("has--adblock"))
  95. {
  96. let newValue = mutation.target.getAttribute(mutation.attributeName);
  97. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - newValue='${newValue}'`);
  98. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - BEFORE: mutation.target.classList='${mutation.target.classList}'`);
  99. mutation.target.classList.remove("has--adblock");
  100. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - AFTER: mutation.target.classList='${mutation.target.classList}'`);
  101. }
  102. else if ((mutation.target.tagName === "BODY") && (mutation.attributeName === "class") && mutation.target.classList.contains("noScroll"))
  103. {
  104. let newValue = mutation.target.getAttribute(mutation.attributeName);
  105. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - newValue='${newValue}'`);
  106. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - BEFORE: mutation.target.classList='${mutation.target.classList}'`);
  107. mutation.target.classList.remove("noScroll");
  108. console_log(`==> Gazzetta_it_HideAdBlockPopup: onMutationList - AFTER: mutation.target.classList='${mutation.target.classList}'`);
  109. }
  110. }
  111. });
  112. }
  113.  
  114. function searchVisibleNode(node, selector)
  115. {
  116. let parentElement = node.parentElement;
  117. return (parentElement === null ? null : parentElement.querySelector(`${selector}:not([style*=\"display:none\"]):not([style*=\"display: none\"])`));
  118. }
  119.  
  120. function createMutationObserver()
  121. {
  122. console_log("==> Gazzetta_it_HideAdBlockPopup: createMutationObserver");
  123.  
  124. // SEE: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
  125. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  126.  
  127. // Create an observer instance linked to the callback function.
  128. const observer = new MutationObserver(onMutationList);
  129.  
  130. // Options for the observer (which mutations to observe).
  131. const config = {subtree: true, childList: true, attributes: true, attributeOldValue: true};
  132.  
  133. // Start observing the target node for configured mutations.
  134. observer.observe(document, config);
  135. }
  136.  
  137. console_log("==> Gazzetta_it_HideAdBlockPopup: Script loaded");
  138. })();