max-mapper / tabby

a browser with almost no UI
345 stars 30 forks source link

adblock support #18

Open arussellsaw opened 8 years ago

arussellsaw commented 8 years ago

i know this is a little extreme, so i'm opening this issue for ideas and suggestions as to how one might implement adblock inside an electron app, things like ublock are js based, so porting is not out of the question, i guess it depends on how heavily it relies on the chrome extension apis.

RangerMauve commented 8 years ago

I mean, you could just do adblocking with your hosts file through your OS.

cbluth commented 7 years ago

@RangerMauve Ads are much more complicated than just blocking a hostname. Supporting defacto-standard-ish stuff like ABP and uBlock would be more ideal than messing with hosts file. Also, the most comprehensive hosts list I've been able to find doesnt block ads very well: https://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=1&mimetype=plaintext

ungoldman commented 7 years ago

The min browser, a similar project, uses https://easylist.to and a modified version of the adblock plus filter parser to do some basic ad and tracker filtering.

myfrndjk commented 7 years ago

Even I had a similar use case. Ad block is 2 step process. [Block the URLs and hide the elements]

1.Block the URLs

Electron has an option to block URLs before making the request.Add the following code in your main.js file.This is my custom filter if you find any website is not working properly because of this filter just add them in white list.

    session.defaultSession.webRequest.onBeforeRequest(['*://*./*'], function(details, callback) {

        var test_url = details.url;
            var check_block_list =/rtcpeerconnection|\.(gr|hk|fm|eu|it|es|is|net|ke|me||tz|za|zm|uk|us|in|com|de|fr|zw|tv|sk|se|php|pk|pl)\/ads?[\-_./\?]|(stats?|rankings?|tracks?|trigg|webtrends?|webtrekk|statistiche|visibl|searchenginejournal|visit|webstat|survey|spring).*.(com|net|de|fr|co|it|se)|cloudflare|\/statistics\/|torrent|[\-_./]ga[\-_./]|[\-_./]counter[\-_./\?]|ad\.admitad\.|\/widgets?[\-_./]?ads?|\/videos?[\-_./]?ads?|\/valueclick|userad|track[\-_./]?ads?|\/top[\-_./]?ads?|\/sponsor[\-_./]?ads?|smartadserver|\/sidebar[\-_]?ads?|popunder|\/includes\/ads?|\/iframe[-_]?ads?|\/header[-_]?ads?|\/framead|\/get[-_]?ads?|\/files\/ad*|exoclick|displayad|\ajax\/ad|adzone|\/assets\/ad*|advertisement|\/adv\/*\.|ad-frame|\.com\/bads\/|follow-us|connect-|-social-|googleplus.|linkedin|footer-social.|social-media|gmail|commission|adserv\.|omniture|netflix|huffingtonpost|dlpageping|log204|geoip\.|baidu|reporting\.|paypal|maxmind|geo\.|api\.bit|hits|predict|cdn-cgi|record_|\.ve$|radar|\.pop|\.tinybar\.|\.ranking|.cash|\.banner\.|adzerk|gweb|alliance|adf\.ly|monitor|urchin_post|imrworldwide|gen204|twitter|naukri|hulu.com|baidu|seotools|roi-|revenue|tracking.js|\/tracking[\-_./]?|elitics|demandmedia|bizrate|click-|bidsystem|affiliates?\.|beacon|hit\.|googleadservices|metrix|googleanal|dailymotion|ga.js|survey|trekk|visit_|arcadebanners?|ielsen|cts\.|link_|ga-track|FacebookTracking|quantc|traffic|evenuescien|roitra|pixelt|pagetra|metrics|[-_/.]?stats?[.-_/]?|common_|accounts\.|contentad|iqadtile|boxad|audsci.js|ebtrekk|seotrack|clickalyzer|youtube|\/tracker\/|ekomi|clicky|[-_/.]?tracking?[.-_/]?|[-_/.]?track?[.-_/]?|ghostery|hscrm|watchvideo|clicks4ads|mkt[0-9]|createsend|analytix|shoppingshadow|clicktracks|admeld|google-analytics|-analytic|googletagservices|googletagmanager|tracking\.|thirdparty|track\.|pflexads|smaato|medialytics|doubleclick|cloudfront|-static|-static-|static-|sponsored-banner|static_|_static_|_static|sponsored_link|sponsored_ad|googleadword|analytics\.|googletakes|adsbygoogle|analytics-|-analytic|analytic-|googlesyndication|google_adsense2|googleAdIndexTop|\/ads\/|google-ad-|google-ad?|google-adsense-|google-adsense.|google-adverts-|google-adwords|google-afc-|google-afc.|google\/ad\?|google\/adv\.|google160.|google728.|_adv|google_afc.|google_afc_|google_afs.|google_afs_widget|google_caf.js|google_lander2.js|google_radlinks_|googlead|googleafc.|googleafs.|googleafvadrenderer.|googlecontextualads.|googleheadad.|googleleader.|googleleads.|googlempu.|ads_|_ads_|_ads|easyads|easyads|easyadstrack|ebayads|[.\-_/\?](ads?|clicks?|tracks?|tracking|logs?)[.\-_/]?(banners?|mid|trends|pathmedia|tech|units?|vert*|fox|area|loc|nxs|format|call|script|final|systems?|show|tag\.?|collect*|slot|right|space|taily|vids?|supply|true|targeting|counts?|nectar|net|onion|parlor|2srv|searcher|fundi|nimation|context|stats?|vertising|class|infuse|includes?|spacers?|code|images?|vers|texts?|work*|tail|track|streams?|ability||world*|zone|position|vertisers?|servers?|view|partner|data)[.\-_/]?/gi
            var check_white_list =/chrome|panopticlick|status|premoa.*.jpg|rakuten|nitori-net|search\?tbs\=sbi\:|google.*\/search|ebay.*static.*g|\/shopping\/product|aclk?|translate.googleapis.com|encrypted-|product|www.googleadservices.com\/pagead\/aclk|target.com|.css/gi;
            var block_me = check_block_list.test(test_url);
            var release_me = check_white_list.test(test_url);

            if(release_me){
                callback({cancel: false})
            }else if(block_me){
                console.log('bloclked'  + test_url)
                callback({cancel: true});

            }else{
                callback({cancel: false})
            }

    });

2.Hide the elements from target website.Add below lines in preload.js file and inject that into hosts website while loading Add your class and ids to be hidden.This will help to block ads/trckers temporarily until electron supports chrome extensions.

//remove_ads
document.addEventListener("DOMContentLoaded", function(event) {
    document.onreadystatechange = function () {
        if (document.readyState == "complete") {

            var class_to_hide, each_class;
            class_to_hide = ['ads-ad','srba','ad_','ads','Adsense'];
            for (each_class = 0; each_class < class_to_hide.length; each_class++) {
                console.log('inside remove das' + class_to_hide[each_class]);
                var class_to_searh = '[class^='+class_to_hide[each_class]+']';
                console.log(class_to_searh);
                var appBanners = document.querySelectorAll(class_to_searh);
                console.log(appBanners);
                if(appBanners.length > 0){
                    for (var i = 0; i < appBanners.length; i++) {
                        appBanners[i].style.display = 'none';
                        console.log('hided' + appBanners[i] );
                    }
                }

            }
        }
        //document.querySelectorAll('[id^=ads]')
    }
});