Gmail Ad Blocker

Hide gmail ads as they appear. Not super elegant but works.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Gmail Ad Blocker
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Hide gmail ads as they appear. Not super elegant but works.
// @author       James Sterling
// @match        https://mail.google.com/*
// @grant        none
// ==/UserScript==

(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);

})();