mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 11:22:38 +01:00
code review, jshint
This commit is contained in:
parent
e7016f851b
commit
c8c01a8f91
@ -19,7 +19,12 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global µBlock */
|
/* global vAPI, µBlock */
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -48,7 +53,7 @@
|
|||||||
|
|
||||||
var i = exceptions.length;
|
var i = exceptions.length;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
if ( this.matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
|
if ( matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
|
||||||
// console.log('"%s" matche url "%s"', exceptions[i], keyURL);
|
// console.log('"%s" matche url "%s"', exceptions[i], keyURL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -98,7 +103,7 @@
|
|||||||
// Remove from exception list whatever causes current URL to be whitelisted
|
// Remove from exception list whatever causes current URL to be whitelisted
|
||||||
var i = exceptions.length;
|
var i = exceptions.length;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
if ( this.matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
|
if ( matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
|
||||||
exceptions.splice(i, 1);
|
exceptions.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +122,7 @@
|
|||||||
// TODO: Need to harden it against edge cases, like when an asterisk is used in
|
// TODO: Need to harden it against edge cases, like when an asterisk is used in
|
||||||
// place of protocol.
|
// place of protocol.
|
||||||
|
|
||||||
µBlock.matchWhitelistException = function(url, hostname, exception) {
|
var matchWhitelistException = function(url, hostname, exception) {
|
||||||
// Exception is a plain hostname
|
// Exception is a plain hostname
|
||||||
if ( exception.indexOf('/') === -1 ) {
|
if ( exception.indexOf('/') === -1 ) {
|
||||||
return hostname.slice(-exception.length) === exception;
|
return hostname.slice(-exception.length) === exception;
|
||||||
@ -129,17 +134,17 @@
|
|||||||
// Regex escape code inspired from:
|
// Regex escape code inspired from:
|
||||||
// "Is there a RegExp.escape function in Javascript?"
|
// "Is there a RegExp.escape function in Javascript?"
|
||||||
// http://stackoverflow.com/a/3561711
|
// http://stackoverflow.com/a/3561711
|
||||||
var reStr = exception.replace(this.whitelistExceptionEscape, '\\$&')
|
var reStr = exception.replace(whitelistExceptionEscape, '\\$&')
|
||||||
.replace(this.whitelistExceptionEscapeAsterisk, '.*');
|
.replace(whitelistExceptionEscapeAsterisk, '.*');
|
||||||
var re = new RegExp(reStr);
|
var re = new RegExp(reStr);
|
||||||
return re.test(url);
|
return re.test(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Any special regexp char will be escaped
|
// Any special regexp char will be escaped
|
||||||
µBlock.whitelistExceptionEscape = /[-\/\\^$+?.()|[\]{}]/g;
|
var whitelistExceptionEscape = /[-\/\\^$+?.()|[\]{}]/g;
|
||||||
|
|
||||||
// All `*` will be expanded into `.*`
|
// All `*` will be expanded into `.*`
|
||||||
µBlock.whitelistExceptionEscapeAsterisk = /\*/g;
|
var whitelistExceptionEscapeAsterisk = /\*/g;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -280,3 +285,7 @@
|
|||||||
this.XAL.keyvalSetOne('dynamicFilteringSelfie', this.userSettings.dynamicFilteringSelfie);
|
this.XAL.keyvalSetOne('dynamicFilteringSelfie', this.userSettings.dynamicFilteringSelfie);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user