LaStampa.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 LaStampa.it: Hide the "Using AdBlock" popup
  3. // @name:it LaStampa.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://*.lastampa.it/*
  7. // @grant none
  8. //// @run-at document-start
  9. // @version 1.0.4
  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("==> LaStampa_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(`==> LaStampa_it_HideAdBlockPopup: onDOMContentLoaded - document.readyState=${document.readyState}`);
  37. // DO NOTHING!
  38. }
  39.  
  40. function onWindowLoaded()
  41. {
  42. console_log(`==> LaStampa_it_HideAdBlockPopup: onWindowLoaded - document.readyState=${document.readyState}`);
  43. // DO NOTHING!
  44. }
  45.  
  46. function onMutationList(mutationList, observer)
  47. {
  48. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - mutationList.length=${mutationList.length}`);
  49. mutationList.forEach((mutation, i) =>
  50. {
  51. //console_log(`==> LaStampa_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(`==> LaStampa_it_HideAdBlockPopup: onMutationList - mutation[${i}] - addedNodes.length=${addedNodes.length}`);
  58. addedNodes.forEach((addedNode, j) =>
  59. {
  60. let searchedDiv = searchVisibleNode(addedNode, "div.fc-dialog-container");
  61. if (searchedDiv !== null)
  62. {
  63. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - searchedDiv.outerHTML='${searchedDiv.outerHTML}'`);
  64.  
  65. let parentElement = searchedDiv.parentElement;
  66. console_log(`==> LaStampa_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(`==> LaStampa_it_HideAdBlockPopup: onMutationList - 'fc-dialog-container' - mutation[${i}], addedNode[${j}] - searchedDiv.tagName='${searchedDiv.tagName}', searchedDiv.classList='${searchedDiv.classList}' ---> HIDDEN/REMOVED`);
  72. }
  73.  
  74. /**/
  75. let searchedDiv2 = searchVisibleNode(addedNode, "div#iubenda-cs-banner");
  76. if (searchedDiv2 !== null)
  77. {
  78. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - searchedDiv2.outerHTML='${searchedDiv2.outerHTML}'`);
  79.  
  80. let parentElement = searchedDiv2.parentElement;
  81. console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
  82.  
  83. searchedDiv2.style.display = "none"; // Hide node.
  84. document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
  85. searchedDiv2.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
  86. console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - 'iubenda-cs-banner' - mutation[${i}], addedNode[${j}] - searchedDiv2.tagName='${searchedDiv2.tagName}', searchedDiv2.classList='${searchedDiv2.classList}' ---> HIDDEN/REMOVED`);
  87. }
  88. /**/
  89. });
  90. }
  91. }
  92. });
  93. }
  94.  
  95. function searchVisibleNode(node, selector)
  96. {
  97. let parentElement = node.parentElement;
  98. return (parentElement === null ? null : parentElement.querySelector(`${selector}:not([style*=\"display:none\"]):not([style*=\"display: none\"])`));
  99. }
  100.  
  101. function createMutationObserver()
  102. {
  103. console_log("==> LaStampa_it_HideAdBlockPopup: createMutationObserver");
  104.  
  105. // SEE: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
  106. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  107.  
  108. // Create an observer instance linked to the callback function.
  109. const observer = new MutationObserver(onMutationList);
  110.  
  111. // Options for the observer (which mutations to observe).
  112. const config = {subtree: true, childList: true};
  113.  
  114. // Start observing the target node for configured mutations.
  115. observer.observe(document, config);
  116. }
  117.  
  118. console_log("==> LaStampa_it_HideAdBlockPopup: Script loaded");
  119. })();