1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

minor code review: just tidying

This commit is contained in:
gorhill 2014-09-20 10:44:04 -04:00
parent 987e26e41c
commit 102dc8b596
3 changed files with 57 additions and 48 deletions

View File

@ -89,7 +89,7 @@ return {
firstUpdateAfter: 5 * oneMinute, firstUpdateAfter: 5 * oneMinute,
nextUpdateAfter: 7 * oneHour, nextUpdateAfter: 7 * oneHour,
selfieMagic: 'gcygyxptwycl', selfieMagic: 'hdnliuyxkoeg',
selfieAfter: 7 * oneMinute, selfieAfter: 7 * oneMinute,
pageStores: {}, pageStores: {},

View File

@ -31,29 +31,27 @@
var µb = µBlock; var µb = µBlock;
// fedcba9876543210 // fedcba9876543210
// ||| | | | // | | | |||
// ||| | | | // | | | |||
// ||| | | | // | | | |||
// ||| | | | // | | | |||
// ||| | | +---- bit 0-6: unused // | | | ||+---- bit 0: [BlockAction | AllowAction]
// ||| | +---- bit 8-7: party [0 - 3] // | | | |+---- bit 1: `important`
// ||| +---- bit 12-9: type [0 - 15] // | | | +---- bit 2-3: party [0 - 3]
// ||+---- bit 13: `important` // | | +---- bit 4-7: type [0 - 15]
// |+---- bit 14: [BlockAction | AllowAction] // | +---- bit 8-15: unused
// +---- bit 15: unused (to ensure valid unicode character) // +---- bit 15: never use! (to ensure valid unicode character)
const BlockAction = 0 << 14; const BlockAction = 0 << 0;
const AllowAction = 1 << 14; const AllowAction = 1 << 0;
const ToggleAction = BlockAction ^ AllowAction; const ToggleAction = BlockAction ^ AllowAction;
const Important = 1 << 13; const Important = 1 << 1;
const AnyType = 1 << 9;
const AnyParty = 0 << 7; const AnyParty = 0 << 2;
const FirstParty = 1 << 7; const FirstParty = 1 << 2;
const ThirdParty = 2 << 7; const ThirdParty = 2 << 2;
const SpecificParty = 3 << 7; const SpecificParty = 3 << 2;
const BlockAnyTypeAnyParty = BlockAction | AnyType | AnyParty; const BlockAnyTypeAnyParty = BlockAction | AnyType | AnyParty;
const BlockAnyType1stParty = BlockAction | AnyType | FirstParty; const BlockAnyType1stParty = BlockAction | AnyType | FirstParty;
@ -71,6 +69,19 @@ const AllowAnyType = AllowAction | AnyType;
const AllowAnyParty = AllowAction | AnyParty; const AllowAnyParty = AllowAction | AnyParty;
const AllowOneParty = AllowAction | SpecificParty; const AllowOneParty = AllowAction | SpecificParty;
const AnyType = 1 << 4;
var typeNameToTypeValue = {
'stylesheet': 2 << 4,
'image': 3 << 4,
'object': 4 << 4,
'script': 5 << 4,
'xmlhttprequest': 6 << 4,
'sub_frame': 7 << 4,
'other': 8 << 4,
'popup': 9 << 4
};
var pageHostname = ''; var pageHostname = '';
var reIgnoreEmpty = /^\s+$/; var reIgnoreEmpty = /^\s+$/;
@ -80,17 +91,6 @@ var reHostnameToken = /^[0-9a-z]+/g;
var reGoodToken = /[%0-9a-z]{2,}/g; var reGoodToken = /[%0-9a-z]{2,}/g;
var reURLPostHostnameAnchors = /[\/?#]/; var reURLPostHostnameAnchors = /[\/?#]/;
var typeNameToTypeValue = {
'stylesheet': 2 << 9,
'image': 3 << 9,
'object': 4 << 9,
'script': 5 << 9,
'xmlhttprequest': 6 << 9,
'sub_frame': 7 << 9,
'other': 8 << 9,
'popup': 9 << 9
};
// ABP filters: https://adblockplus.org/en/filters // ABP filters: https://adblockplus.org/en/filters
// regex tester: http://regex101.com/ // regex tester: http://regex101.com/
@ -824,12 +824,16 @@ FilterManyWildcardsHostname.fromSelfie = function(s) {
// here because the special treatment would be only for a few specific tokens, // here because the special treatment would be only for a few specific tokens,
// not systematically done for all tokens. // not systematically done for all tokens.
// key=Ȁ ad count=655 // key=?? ad count=657
// key=Ȁ ads count=432 // key=?? ads count=431
// key=̀ doubleclick count= 94 // key=?? mdn count=267
// key=Ȁ adv count= 89 // key=?? google count=181
// key=Ȁ google count= 67 // key=?? pagead2 count=166
// key=Ȁ banner count= 55 // key=?? doubleclick count=118
// key=?? g count=100
// key=?? doubleclick count=94
// key=?? js count=88
// key=?? adv count=88
var FilterBucket = function(a, b) { var FilterBucket = function(a, b) {
this.f = null; this.f = null;
@ -843,6 +847,9 @@ var FilterBucket = function(a, b) {
}; };
FilterBucket.prototype.add = function(a) { FilterBucket.prototype.add = function(a) {
// If filter count > n, create dictionary in which filter buckets will be
// keyed on prefix-suffix string. There will be a special bucket, always
// evaluated for those filters who can't supply a two-char keys.
this.filters.push(a); this.filters.push(a);
}; };

View File

@ -224,17 +224,19 @@
/******************************************************************************/ /******************************************************************************/
µBlock.transposeType = function(type, path) { µBlock.transposeType = function(type, path) {
if ( type === 'other' ) { if ( type !== 'other' ) {
var pos = path.lastIndexOf('.'); return type;
if ( pos > 0 ) { }
var ext = path.slice(pos); var pos = path.lastIndexOf('.');
if ( '.eot.ttf.otf.svg.woff'.indexOf(ext) >= 0 ) { if ( pos === -1 ) {
return 'stylesheet'; return type;
} }
if ( '.ico.png'.indexOf(ext) >= 0 ) { var ext = path.slice(pos);
return 'image'; if ( '.eot.ttf.otf.svg.woff'.indexOf(ext) !== -1 ) {
} return 'stylesheet';
} }
if ( '.ico.png.gif.jpg.jpeg'.indexOf(ext) !== -1 ) {
return 'image';
} }
return type; return type;
}; };