Created
July 24, 2022 16:09
-
-
Save jamespsterling/e7c5b3a906f181c1d5fd77df26c47931 to your computer and use it in GitHub Desktop.
Hides Gmail ads as they appear
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = '.hidden { display: none; }'; | |
document.getElementsByTagName('head')[0].appendChild(style); | |
function blockAds() { | |
var spans = document.querySelectorAll('tr > td > div > span > span'); | |
var searchText = "Ad"; | |
for (var i = 0; i < spans.length; i++) { | |
if (spans[i].textContent == searchText) { | |
spans[i].parentElement.parentElement.parentElement.parentElement.style = 'display: none'; | |
spans[i].parentElement.parentElement.parentElement.parentElement.classList.toggle('hidden'); | |
} | |
} | |
} | |
function setup() { | |
blockAds(); | |
setInterval(function() { | |
blockAds(); | |
}, 1000); | |
// Listen for tab changes | |
document.querySelectorAll('[role="tab"]').forEach(function (el){ | |
el.addEventListener("click", function() { | |
blockAds(); | |
var counter = 0; | |
var look = setInterval(function() { | |
if (counter > 250) { | |
clearInterval(look); | |
} | |
blockAds(); | |
counter++; | |
}, 5); | |
}); | |
}); | |
} | |
var watcher = setInterval(function() { | |
if (document.querySelectorAll('[role="tab"]').length > 0) { | |
setup(); | |
clearInterval(watcher); | |
} | |
}, 5); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://greasyfork.org/en/scripts/416410-gmail-ad-blocker