aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-03-02 16:22:23 -0500
committergorhill <rhill@raymondhill.net>2015-03-02 16:22:23 -0500
commit82c0342f233d34d995e101f18c84579403231c0b (patch)
tree23214635f3df202e4eaabbd6c015f0d4f733e13b /src/js
parent1d3205ea817ccb8a2f03bbaecc9daf19440e300b (diff)
downloaduBlock-82c0342f233d34d995e101f18c84579403231c0b.zip
uBlock-82c0342f233d34d995e101f18c84579403231c0b.tar.gz
uBlock-82c0342f233d34d995e101f18c84579403231c0b.tar.bz2
hostname-based version of #915
Diffstat (limited to 'src/js')
-rw-r--r--src/js/background.js2
-rw-r--r--src/js/static-net-filtering.js56
2 files changed, 52 insertions, 6 deletions
diff --git a/src/js/background.js b/src/js/background.js
index d9bb7c9..c640a3c 100644
--- a/src/js/background.js
+++ b/src/js/background.js
@@ -85,7 +85,7 @@ return {
// read-only
systemSettings: {
- compiledMagic: 'fkaywfqahncj',
+ compiledMagic: 'shztbfhkfjit',
selfieMagic: 'spqmeuaftfra'
},
diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js
index 8faf9dd..85c3a31 100644
--- a/src/js/static-net-filtering.js
+++ b/src/js/static-net-filtering.js
@@ -921,6 +921,40 @@ FilterGenericHnAnchored.fromSelfie = function(s) {
/******************************************************************************/
+var FilterGenericHnAnchoredHostname = function(s, hostname) {
+ FilterGenericHnAnchored.call(this, s);
+ this.hostname = hostname;
+};
+FilterGenericHnAnchoredHostname.prototype = Object.create(FilterGenericHnAnchored.prototype);
+
+FilterGenericHnAnchoredHostname.prototype.match = function(url) {
+ if ( pageHostnameRegister.slice(-this.hostname.length) !== this.hostname ) {
+ return false;
+ }
+ return FilterGenericHnAnchored.prototype.match.call(this. url);
+};
+
+FilterGenericHnAnchoredHostname.fid = FilterGenericHnAnchoredHostname.prototype.fid = '||_h';
+
+FilterGenericHnAnchoredHostname.prototype.toString = function() {
+ return '||' + this.s + '$domain=' + this.hostname;
+};
+
+FilterGenericHnAnchoredHostname.prototype.toSelfie = function() {
+ return this.s + '\t' + this.hostname;
+};
+
+FilterGenericHnAnchoredHostname.compile = function(details, hostname) {
+ return details.f + '\t' + hostname;
+};
+
+FilterGenericHnAnchoredHostname.fromSelfie = function(s) {
+ var pos = s.indexOf('\t');
+ return new FilterGenericHnAnchoredHostname(s.slice(0, pos), s.slice(pos + 1));
+};
+
+/******************************************************************************/
+
// With many wildcards, a regex is best.
// Ref: regex escaper taken from:
@@ -1417,6 +1451,9 @@ var getHostnameBasedFilterClass = function(details) {
var s = details.f;
var wcOffset = s.indexOf('*');
if ( wcOffset !== -1 ) {
+ if ( details.hostnameAnchored ) {
+ return FilterGenericHnAnchoredHostname;
+ }
if ( s.indexOf('*', wcOffset + 1) !== -1 ) {
return details.anchor === 0 ? FilterManyWildcardsHostname : null;
}
@@ -1735,17 +1772,23 @@ var findFirstGoodToken = function(s) {
reGoodToken.lastIndex = 0;
var matches;
while ( matches = reGoodToken.exec(s) ) {
+ if ( s.charAt(reGoodToken.lastIndex) === '*' ) {
+ continue;
+ }
if ( badTokens.hasOwnProperty(matches[0]) ) {
continue;
}
+ return matches;
+ }
+ // No good token found, try again without minding "bad" tokens
+ reGoodToken.lastIndex = 0;
+ while ( matches = reGoodToken.exec(s) ) {
if ( s.charAt(reGoodToken.lastIndex) === '*' ) {
continue;
}
return matches;
}
- // No good token found, just return the first token from left
- reGoodToken.lastIndex = 0;
- return reGoodToken.exec(s);
+ return null;
};
var findHostnameToken = function(s) {
@@ -1753,6 +1796,8 @@ var findHostnameToken = function(s) {
return reHostnameToken.exec(s);
};
+/******************************************************************************/
+
FilterParser.prototype.makeToken = function() {
if ( this.isRegex ) {
this.token = '*';
@@ -1774,7 +1819,7 @@ FilterParser.prototype.makeToken = function() {
}
matches = findFirstGoodToken(this.f);
- if ( !matches || matches[0].length === 0 ) {
+ if ( matches === null || matches[0].length === 0 ) {
return;
}
this.tokenBeg = matches.index;
@@ -1864,7 +1909,8 @@ FilterContainer.prototype.factories = {
'//': FilterRegex,
'//h': FilterRegexHostname,
'{h}': FilterHostnameDict,
- '||_': FilterGenericHnAnchored
+ '||_': FilterGenericHnAnchored,
+ '||_h': FilterGenericHnAnchoredHostname
};
/******************************************************************************/