This script hides the "Using AdBlock" popup that is shown when you use an ad-block.
当前为
// ==UserScript==
// @name Corriere.it: Hide the "Using AdBlock" popup
// @name:it Corriere.it: Nasconde il popup "AdBlock In Uso"
// @description This script hides the "Using AdBlock" popup that is shown when you use an ad-block.
// @description:it Questo script nasconde il popup "AdBlock In Uso" che viene visualizzato quando si usa un ad-block.
// @match https://*.corriere.it/*
// @grant none
//// @run-at document-start
// @version 1.0.1
// @author Cyrano68
// @license MIT
// @namespace https://greasyfork.org/users/788550
// ==/UserScript==
(function()
{
"use strict";
function console_log(text)
{
const dateNow = new Date();
//let now = dateNow.toISOString();
let now = dateNow.toLocaleString() + "." + dateNow.getMilliseconds();
console.log(`${now} ${text}`);
}
var myVersion = GM_info.script.version;
console_log(`==> Corriere_it_HideAdBlockPopup: HELLO! Loading script (version: ${myVersion})...`);
document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
window.addEventListener("load", onWindowLoaded);
createMutationObserver();
function onDOMContentLoaded()
{
console_log(`==> Corriere_it_HideAdBlockPopup: onDOMContentLoaded - document.readyState=${document.readyState}`);
// DO NOTHING!
}
function onWindowLoaded()
{
console_log(`==> Corriere_it_HideAdBlockPopup: onWindowLoaded - document.readyState=${document.readyState}`);
// DO NOTHING!
}
function onMutationList(mutationList, observer)
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - mutationList.length=${mutationList.length}`);
mutationList.forEach((mutation, i) =>
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - mutation[${i}] - mutation.type=${mutation.type}`);
if (mutation.type === "childList")
{
let addedNodes = mutation.addedNodes;
if (addedNodes.length > 0)
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - mutation[${i}] - addedNodes.length=${addedNodes.length}`);
addedNodes.forEach((addedNode, j) =>
{
let searchedDiv = searchVisibleNode(addedNode, "div.privacy-cp-wall");
if (searchedDiv !== null)
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - searchedDiv.outerHTML='${searchedDiv.outerHTML}'`);
let parentElement = searchedDiv.parentElement;
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
searchedDiv.style.display = "none"; // Hide node.
document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
searchedDiv.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - 'privacy-cp-wall' - mutation[${i}], addedNode[${j}] - searchedDiv.tagName='${searchedDiv.tagName}', searchedDiv.classList='${searchedDiv.classList}' ---> HIDDEN/REMOVED`);
}
//let searchedDiv2 = searchVisibleNode(addedNode, "div.adblock__container");
let searchedDiv2 = searchVisibleNode(addedNode, "div.bck-adblock");
if (searchedDiv2 !== null)
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - searchedDiv2.outerHTML='${searchedDiv2.outerHTML}'`);
let parentElement = searchedDiv2.parentElement;
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
searchedDiv2.style.display = "none"; // Hide node.
document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
searchedDiv2.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - 'bck-adblock' - mutation[${i}], addedNode[${j}] - searchedDiv2.tagName='${searchedDiv2.tagName}', searchedDiv2.classList='${searchedDiv2.classList}' ---> HIDDEN/REMOVED`);
}
//let searchedDiv3 = searchVisibleNode(addedNode, "div.adblock__container");
let searchedDiv3 = searchVisibleNode(addedNode, "div.tp-container-inner");
if (searchedDiv3 !== null)
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - searchedDiv3.outerHTML='${searchedDiv3.outerHTML}'`);
let parentElement = searchedDiv3.parentElement;
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - parentElement: tagName='${parentElement.tagName}' id='${parentElement.id}'`);
searchedDiv3.style.display = "none"; // Hide node.
document.body.style.overflowY = "scroll"; // Show vertical scrollbar.
searchedDiv3.remove(); // Remove node. IMPORTANT: Without this instruction the script does NOT work properly.
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - 'tp-container-inner' - mutation[${i}], addedNode[${j}] - searchedDiv3.tagName='${searchedDiv3.tagName}', searchedDiv3.classList='${searchedDiv3.classList}' ---> HIDDEN/REMOVED`);
}
});
}
}
else if (mutation.type === "attributes")
{
//console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - mutation.attributeName='${mutation.attributeName}', mutation.oldValue='${mutation.oldValue}'`);
if ((mutation.target.tagName === "HTML") && (mutation.attributeName === "class") && mutation.target.classList.contains("has--adblock"))
{
let newValue = mutation.target.getAttribute(mutation.attributeName);
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - newValue='${newValue}'`);
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - BEFORE: mutation.target.classList='${mutation.target.classList}'`);
mutation.target.classList.remove("has--adblock");
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - AFTER: mutation.target.classList='${mutation.target.classList}'`);
}
else if ((mutation.target.tagName === "BODY") && (mutation.attributeName === "class") && mutation.target.classList.contains("noScroll"))
{
let newValue = mutation.target.getAttribute(mutation.attributeName);
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - newValue='${newValue}'`);
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - BEFORE: mutation.target.classList='${mutation.target.classList}'`);
mutation.target.classList.remove("noScroll");
console_log(`==> Corriere_it_HideAdBlockPopup: onMutationList - AFTER: mutation.target.classList='${mutation.target.classList}'`);
}
}
});
}
function searchVisibleNode(node, selector)
{
let parentElement = node.parentElement;
return (parentElement === null ? null : parentElement.querySelector(`${selector}:not([style*=\"display:none\"]):not([style*=\"display: none\"])`));
}
function createMutationObserver()
{
console_log("==> Corriere_it_HideAdBlockPopup: createMutationObserver");
// SEE: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
// Create an observer instance linked to the callback function.
const observer = new MutationObserver(onMutationList);
// Options for the observer (which mutations to observe).
const config = {subtree: true, childList: true, attributes: true, attributeOldValue: true, attributeFilter: ["class"]};
// Start observing the target node for configured mutations.
observer.observe(document, config);
}
console_log("==> Corriere_it_HideAdBlockPopup: Script loaded");
})();