mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
hostname-based version of #915
This commit is contained in:
parent
1d3205ea81
commit
82c0342f23
@ -85,7 +85,7 @@ return {
|
|||||||
|
|
||||||
// read-only
|
// read-only
|
||||||
systemSettings: {
|
systemSettings: {
|
||||||
compiledMagic: 'fkaywfqahncj',
|
compiledMagic: 'shztbfhkfjit',
|
||||||
selfieMagic: 'spqmeuaftfra'
|
selfieMagic: 'spqmeuaftfra'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -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.
|
// With many wildcards, a regex is best.
|
||||||
|
|
||||||
// Ref: regex escaper taken from:
|
// Ref: regex escaper taken from:
|
||||||
@ -1417,6 +1451,9 @@ var getHostnameBasedFilterClass = function(details) {
|
|||||||
var s = details.f;
|
var s = details.f;
|
||||||
var wcOffset = s.indexOf('*');
|
var wcOffset = s.indexOf('*');
|
||||||
if ( wcOffset !== -1 ) {
|
if ( wcOffset !== -1 ) {
|
||||||
|
if ( details.hostnameAnchored ) {
|
||||||
|
return FilterGenericHnAnchoredHostname;
|
||||||
|
}
|
||||||
if ( s.indexOf('*', wcOffset + 1) !== -1 ) {
|
if ( s.indexOf('*', wcOffset + 1) !== -1 ) {
|
||||||
return details.anchor === 0 ? FilterManyWildcardsHostname : null;
|
return details.anchor === 0 ? FilterManyWildcardsHostname : null;
|
||||||
}
|
}
|
||||||
@ -1735,17 +1772,23 @@ var findFirstGoodToken = function(s) {
|
|||||||
reGoodToken.lastIndex = 0;
|
reGoodToken.lastIndex = 0;
|
||||||
var matches;
|
var matches;
|
||||||
while ( matches = reGoodToken.exec(s) ) {
|
while ( matches = reGoodToken.exec(s) ) {
|
||||||
|
if ( s.charAt(reGoodToken.lastIndex) === '*' ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ( badTokens.hasOwnProperty(matches[0]) ) {
|
if ( badTokens.hasOwnProperty(matches[0]) ) {
|
||||||
continue;
|
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) === '*' ) {
|
if ( s.charAt(reGoodToken.lastIndex) === '*' ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
// No good token found, just return the first token from left
|
return null;
|
||||||
reGoodToken.lastIndex = 0;
|
|
||||||
return reGoodToken.exec(s);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var findHostnameToken = function(s) {
|
var findHostnameToken = function(s) {
|
||||||
@ -1753,6 +1796,8 @@ var findHostnameToken = function(s) {
|
|||||||
return reHostnameToken.exec(s);
|
return reHostnameToken.exec(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
FilterParser.prototype.makeToken = function() {
|
FilterParser.prototype.makeToken = function() {
|
||||||
if ( this.isRegex ) {
|
if ( this.isRegex ) {
|
||||||
this.token = '*';
|
this.token = '*';
|
||||||
@ -1774,7 +1819,7 @@ FilterParser.prototype.makeToken = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
matches = findFirstGoodToken(this.f);
|
matches = findFirstGoodToken(this.f);
|
||||||
if ( !matches || matches[0].length === 0 ) {
|
if ( matches === null || matches[0].length === 0 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.tokenBeg = matches.index;
|
this.tokenBeg = matches.index;
|
||||||
@ -1864,7 +1909,8 @@ FilterContainer.prototype.factories = {
|
|||||||
'//': FilterRegex,
|
'//': FilterRegex,
|
||||||
'//h': FilterRegexHostname,
|
'//h': FilterRegexHostname,
|
||||||
'{h}': FilterHostnameDict,
|
'{h}': FilterHostnameDict,
|
||||||
'||_': FilterGenericHnAnchored
|
'||_': FilterGenericHnAnchored,
|
||||||
|
'||_h': FilterGenericHnAnchoredHostname
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user