Comments (4)
I mean, you could just do adblocking with your hosts file through your OS.
from tabby.
@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.
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.
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)
- Toggle DevTools is toggling the Electron Devtools, not <webview> HOT 2
- Screenshots HOT 3
- CMD+T just takes the current window back to newtab.html HOT 3
- Settings
- Contextual menu doesn't work as expected HOT 2
- after resizing the window background tabs do not render correctly until you resize again
- Google search crashes tab HOT 1
- "Always on top" feature
- Text on new tab isn't selectable, including the link to PRs
- Opening the location bar while on newtab.html shows "weird looking" URL HOT 1
- ESC while locationBar is active should close the locationBar
- Reload & Hard Reload don't appear to be working? HOT 1
- Location bar fails to load page without protocol, but looks fine
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tabby.