From 80c2ef47bcd1072aad3de04a46c3cc438d38ad6e Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 25 Nov 2015 19:38:05 -0500 Subject: [PATCH] code review + removal of obsolete exception filters --- assets/checksums.txt | 4 +-- assets/ublock/redirect-resources.txt | 52 ++++++++++++++++++++++++---- assets/ublock/unbreak.txt | 11 +----- src/js/redirect-engine.js | 24 +++++++------ 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/assets/checksums.txt b/assets/checksums.txt index fc6a03253..724698fd3 100644 --- a/assets/checksums.txt +++ b/assets/checksums.txt @@ -1,5 +1,5 @@ -d25ad715e4fdf47684422131b2377e1e assets/ublock/unbreak.txt -e65fbcaa573c028770f1d0afada55672 assets/ublock/redirect-resources.txt +a65d3b35ba116f897c7ef5db2046da73 assets/ublock/unbreak.txt +56b94e0f8a6b0d010d358ba4f7b7d5c9 assets/ublock/redirect-resources.txt 7a04294b44b88baa34cf3e4bfe0e59db assets/ublock/privacy.txt b2dbf435507aa0262b289c67cbef2142 assets/ublock/filters.txt 146704ad1c0393e342afdb416762c183 assets/ublock/badware.txt diff --git a/assets/ublock/redirect-resources.txt b/assets/ublock/redirect-resources.txt index a96c1cf08..be9b36800 100644 --- a/assets/ublock/redirect-resources.txt +++ b/assets/ublock/redirect-resources.txt @@ -8,17 +8,55 @@ # If the encoding is absent, the data will be converted to base64, and the # encoding will be set to `;base64`. + hd-main.js application/javascript var L = (function(){ - var l = {}; - var fn = function(){}; - var props = ["pf","ed","Qe","fd","xh","Uc","ef","zd","Ad","Qc","Ri","Wc","Vc","Xc","Wg","rd","qd","sd","Pe","Id","Hd","Jd","fg","Fd","Ed","Gd","ek","Cd","Bd","Dd","Nj","Sc","Rc","Tc","wg","xd","wd","yd","fh","ld","md","nd","Re","cd","Pc","ke","Yc","Xg","jd","kd","oh","ad","bd","mi","gd","hd","ae","dd","fk","ij","ud","td","vd","ig","od","pd","Yd","$j","Oc","bf"]; - for ( var i = 0; i < props.length; i++ ) { - l[props[i]] = fn; - } - return l; + var l = {}; + var noopfn = function() {}; + var props = ["pf", "ed", "Qe", "fd", "xh", "Uc", "ef", "zd", "Ad", "Qc", "Ri", "Wc", "Vc", "Xc", "Wg", "rd", "qd", "sd", "Pe", "Id", "Hd", "Jd", "fg", "Fd", "Ed", "Gd", "ek", "Cd", "Bd", "Dd", "Nj", "Sc", "Rc", "Tc", "wg", "xd", "wd", "yd", "fh", "ld", "md", "nd", "Re", "cd", "Pc", "ke", "Yc", "Xg", "jd", "kd", "oh", "ad", "bd", "mi", "gd", "hd", "ae", "dd", "fk", "ij", "ud", "td", "vd", "ig", "od", "pd", "Yd", "$j", "Oc", "bf"]; + for (var i = 0; i < props.length; i++) { + l[props[i]] = noopfn; + } + return l; })(); + # http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever handtinytrans.gif image/gif;base64 R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== + + +# To neutralize GA scripts. The goal is to provide the minimal API +# expected by clients of these scripts so that the end users are able +# to wholly block GA while minimizing risks of page breakage. +# Test cases (need way more): +# - https://github.com/chrisaljoudi/uBlock/issues/119 + +#www.google-analytics.com/ga.js application/javascript +#(function() { +# var noopfn = function() {}; +# // +# var gaq = function() {}; +# gaq.push = function(a) { +# if ( typeof a === 'function' ) { +# a(); +# } +# }; +# // +# var tracker = function() {}; +# tracker._getLinkerUrl = function(a) { return a; }; +# // +# var gat = function() {}; +# gat._getTrackerByName = function() { return tracker; }; +# window._gat = gat; +# // +# (function() { +# var aa = window._gaq || []; +# if ( Array.isArray(aa) ) { +# while ( aa[0] ) { +# gaq.push(aa.shift()); +# } +# } +# })(); +# window._gaq = gaq; +#})(); diff --git a/assets/ublock/unbreak.txt b/assets/ublock/unbreak.txt index 59d35ef3b..3da0e20c3 100644 --- a/assets/ublock/unbreak.txt +++ b/assets/ublock/unbreak.txt @@ -3,20 +3,15 @@ # https://twitter.com/JarkkoRytkonen/status/540052376015888385 # https://github.com/chrisaljoudi/uBlock/issues/119 -# https://github.com/chrisaljoudi/uBlock/issues/822 # https://github.com/chrisaljoudi/uBlock/issues/940 # To counter `google-analytics.com` in Peter Lowe's list -@@||google-analytics.com^$domain=avianca.com|jackbox.tv|musixmatch.com|bikstok.sonymusicshop.dk +@@||google-analytics.com^$domain=avianca.com|jackbox.tv|bikstok.sonymusicshop.dk # From Chrome store: "Go to site http://www.vd.nl/ ... links from dropdown top menu do not work" # To counter Dan Pollock's, hpHosts, MVPS, Peter Lowe's @@||google-analytics.com/analytics.js$script,domain=www.vd.nl @@||google-analytics.com/plugins/ua/ec.js$script,domain=www.vd.nl -# https://github.com/chrisaljoudi/uBlock/issues/821 -# => blocking counterpart in Peter Lowe's Ad Server -@@||google-analytics.com/ga.js^$script,domain=zie.nl - # https://github.com/gorhill/uBlock/issues/939 @@||google-analytics.com/urchin.js$script,domain=live.euroleague.net @@ -93,10 +88,6 @@ # To counter `2mdn.net` in Peter Lowe's, `s0.2mdn.net` in hpHosts @@||s0.2mdn.net/instream/*$object,script,domain=wsmv.com -# Videos broken on weather.com -# To counter `www.googletagservices.com` in MVPS, hpHosts, Dan Pollock's -@@||www.googletagservices.com/tag/js/gpt.js^$script,domain=weather.com - # https://github.com/chrisaljoudi/uBlock/issues/409 @@||c.speedtest.net^$~third-party diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index 670093b5e..3c271bd70 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -222,14 +222,14 @@ RedirectEngine.prototype.supportedTypes = (function() { RedirectEngine.prototype.resourcesFromString = function(text) { var textEnd = text.length; var lineBeg = 0, lineEnd; - var line, fields; + var line, fields, encoded; + var reNonEmptyLine = /\S/; - var resourceFromFields = function(fields) { - var encoded = fields[1].indexOf(';') !== -1; + var resourceFromFields = function(fields, encoded) { var data = fields.slice(2).join(encoded ? '' : '\n'); this.resources[fields[0]] = 'data:' + - fields[1] + + fields[1] + (encoded ? '' : ';base64') + ',' + (encoded ? data : btoa(data)); @@ -245,7 +245,7 @@ RedirectEngine.prototype.resourcesFromString = function(text) { lineEnd = textEnd; } } - line = text.slice(lineBeg, lineEnd).trim(); + line = text.slice(lineBeg, lineEnd); lineBeg = lineEnd + 1; if ( line.charAt(0) === '#' ) { @@ -253,27 +253,29 @@ RedirectEngine.prototype.resourcesFromString = function(text) { } if ( fields === undefined ) { - fields = line.split(/\s+/); - if ( fields.length !== 2 ) { + fields = line.trim().split(/\s+/); + if ( fields.length === 2 ) { + encoded = fields[1].indexOf(';') !== -1; + } else { fields = undefined; } continue; } - if ( line !== '' ) { - fields.push(line); + if ( reNonEmptyLine.test(line) ) { + fields.push(encoded ? line.trim() : line); continue; } // No more data, add the resource. - resourceFromFields(fields); + resourceFromFields(fields, encoded); fields = undefined; } // Process pending resource data. if ( fields !== undefined ) { - resourceFromFields(fields); + resourceFromFields(fields, encoded); } };