LaStampa.it: Hide the "Using AdBlock" popup

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

  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.5
  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. var myVersion = GM_info.script.version;
  28. console_log(`==> LaStampa_it_HideAdBlockPopup: HELLO! Loading script (version: ${myVersion})...`);
  29.  
  30. document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
  31. window.addEventListener("load", onWindowLoaded);
  32.  
  33. createMutationObserver();
  34.  
  35. function onDOMContentLoaded()
  36. {
  37. console_log(`==> LaStampa_it_HideAdBlockPopup: onDOMContentLoaded - document.readyState=${document.readyState}`);
  38. // DO NOTHING!
  39. }
  40.  
  41. function onWindowLoaded()
  42. {
  43. console_log(`==> LaStampa_it_HideAdBlockPopup: onWindowLoaded - document.readyState=${document.readyState}`);
  44. // DO NOTHING!
  45. }
  46.  
  47. function onMutationList(mutationList, observer)
  48. {
  49. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - mutationList.length=${mutationList.length}`);
  50. mutationList.forEach((mutation, i) =>
  51. {
  52. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - mutation[${i}] - mutation.type=${mutation.type}`);
  53. if (mutation.type === "childList")
  54. {
  55. let addedNodes = mutation.addedNodes;
  56. if (addedNodes.length > 0)
  57. {
  58. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - mutation[${i}] - addedNodes.length=${addedNodes.length}`);
  59. addedNodes.forEach((addedNode, j) =>
  60. {
  61. let searchedDiv = searchVisibleNode(addedNode, "div.fc-dialog-container");
  62. if (searchedDiv !== null)
  63. {
  64. //console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - searchedDiv.outerHTML='${searchedDiv.outerHTML}'`);
  65.  
  66. let parentElement = searchedDiv.parentElement;
  67. console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
  68.  
  69. searchedDiv.style.display = "none"; // Hide node.
  70. document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
  71. searchedDiv.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
  72. console_log(`==> LaStampa_it_HideAdBlockPopup: onMutationList - 'fc-dialog-container' - mutation[${i}], addedNode[${j}] - searchedDiv.tagName='${searchedDiv.tagName}', searchedDiv.classList='${searchedDiv.classList}' ---> HIDDEN/REMOVED`);
  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. function searchVisibleNode(node, selector)
  95. {
  96. let parentElement = node.parentElement;
  97. return (parentElement === null ? null : parentElement.querySelector(`${selector}:not([style*=\"display:none\"]):not([style*=\"display: none\"])`));
  98. }
  99.  
  100. function createMutationObserver()
  101. {
  102. console_log("==> LaStampa_it_HideAdBlockPopup: createMutationObserver");
  103.  
  104. // SEE: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
  105. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  106.  
  107. // Create an observer instance linked to the callback function.
  108. const observer = new MutationObserver(onMutationList);
  109.  
  110. // Options for the observer (which mutations to observe).
  111. const config = {subtree: true, childList: true};
  112.  
  113. // Start observing the target node for configured mutations.
  114. observer.observe(document, config);
  115. }
  116.  
  117. console_log("==> LaStampa_it_HideAdBlockPopup: Script loaded");
  118. })();