Giter Club home page Giter Club logo

Comments (4)

RangerMauve avatar RangerMauve commented on July 22, 2024

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

from tabby.

cbluth avatar cbluth commented on July 22, 2024

@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

from tabby.

ungoldman avatar ungoldman commented on July 22, 2024

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.

from tabby.

myfrndjk avatar myfrndjk commented on July 22, 2024

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]')
    }
});

from tabby.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.