Вот несколько способов создания скрипта для удаления рекламы на JavaScript:
-
Использование CSS-инъекции:
// Create a style element to hide ads using CSS var style = document.createElement('style'); style.innerHTML = '.ad { display: none !important; }'; // Append the style element to the document's head document.head.appendChild(style); -
Использование манипуляций с DOM:
// Find all elements with a specific class or attribute indicating an ad var adElements = document.querySelectorAll('.ad'); // Remove each ad element from the DOM adElements.forEach(function(adElement) { adElement.remove(); }); -
Использование MutationObserver:
// Create a new MutationObserver instance var observer = new MutationObserver(function(mutations) { // Iterate over each mutation mutations.forEach(function(mutation) { // Check if the mutation added any elements with a specific class or attribute indicating an ad var adElements = mutation.addedNodes.querySelectorAll('.ad'); // Remove each ad element from the DOM adElements.forEach(function(adElement) { adElement.remove(); }); }); }); // Start observing the document for mutations observer.observe(document, { childList: true, subtree: true });
Обратите внимание, что эти методы, возможно, потребуется адаптировать в зависимости от конкретной структуры и реализации целевого веб-сайта. Кроме того, важно соблюдать условия обслуживания и политику посещаемых вами веб-сайтов, поскольку некоторые из них могут запрещать или ограничивать использование блокировщиков рекламы.