@@ -731,7 +731,9 @@ var badTokens = {
731
731
'images' : true ,
732
732
'img' : true ,
733
733
'js' : true ,
734
+ 'net' : true ,
734
735
'news' : true ,
736
+ 'social' : true ,
735
737
'www' : true
736
738
} ;
737
739
@@ -1011,15 +1013,7 @@ var FilterContainer = function() {
1011
1013
1012
1014
// Used during URL matching
1013
1015
this . reAnyToken = / [ % 0 - 9 a - z ] + / g;
1014
- this . matches = null ;
1015
- this . bucket0 = undefined ;
1016
- this . bucket1 = undefined ;
1017
- this . bucket2 = undefined ;
1018
- this . bucket3 = undefined ;
1019
- this . bucket4 = undefined ;
1020
- this . bucket5 = undefined ;
1021
- this . bucket6 = undefined ;
1022
- this . bucket7 = undefined ;
1016
+ this . buckets = new Array ( 8 ) ;
1023
1017
} ;
1024
1018
1025
1019
/******************************************************************************/
@@ -1188,9 +1182,7 @@ FilterContainer.prototype.addFilter = function(parsed) {
1188
1182
1189
1183
FilterContainer . prototype . addFilterEntry = function ( filter , parsed , party , tokenBeg , tokenEnd ) {
1190
1184
var s = parsed . f ;
1191
- var prefixKey = trimChar ( s . substring ( tokenBeg - 1 , tokenBeg ) , '*' ) ;
1192
- var suffixKey = trimChar ( s . substring ( tokenEnd , tokenEnd + 1 ) , '*' ) ;
1193
- var tokenKey = prefixKey + s . slice ( tokenBeg , tokenEnd ) + suffixKey ;
1185
+ var tokenKey = s . slice ( tokenBeg , tokenEnd ) ;
1194
1186
if ( parsed . types . length === 0 ) {
1195
1187
this . addToCategory ( parsed . action | AnyType | party , tokenKey , filter ) ;
1196
1188
return ;
@@ -1240,7 +1232,7 @@ FilterContainer.prototype.reset = function() {
1240
1232
/******************************************************************************/
1241
1233
1242
1234
FilterContainer . prototype . freeze = function ( ) {
1243
- // histogram('allFilters', this.categories);
1235
+ //histogram('allFilters', this.categories);
1244
1236
this . blockedAnyPartyHostnames . freeze ( ) ;
1245
1237
this . blocked3rdPartyHostnames . freeze ( ) ;
1246
1238
this . duplicates = { } ;
@@ -1249,76 +1241,72 @@ FilterContainer.prototype.freeze = function() {
1249
1241
1250
1242
/******************************************************************************/
1251
1243
1252
- FilterContainer . prototype . matchToken = function ( bucket ) {
1253
- var url = this . url ;
1254
- var beg = this . matches . index ;
1255
- var end = this . reAnyToken . lastIndex ;
1256
- var f ;
1257
- if ( end !== url . length ) {
1258
- if ( beg !== 0 ) {
1259
- f = bucket [ url . slice ( beg - 1 , end + 1 ) ] ;
1260
- if ( f !== undefined && f . match ( url , beg ) !== false ) {
1261
- return f . s ;
1262
- }
1263
- }
1264
- f = bucket [ url . slice ( beg , end + 1 ) ] ;
1265
- if ( f !== undefined && f . match ( url , beg ) !== false ) {
1266
- return f . s ;
1267
- }
1268
- }
1269
- if ( beg !== 0 ) {
1270
- f = bucket [ url . slice ( beg - 1 , end ) ] ;
1271
- if ( f !== undefined && f . match ( url , beg ) !== false ) {
1272
- return f . s ;
1273
- }
1274
- }
1275
- f = bucket [ url . slice ( beg , end ) ] ;
1276
- if ( f !== undefined && f . match ( url , beg ) !== false ) {
1277
- return f . s ;
1278
- }
1279
- return false ;
1280
- } ;
1281
-
1282
- /******************************************************************************/
1283
-
1284
1244
FilterContainer . prototype . matchTokens = function ( ) {
1285
1245
var url = this . url ;
1286
1246
var re = this . reAnyToken ;
1287
- var r ;
1247
+ var matches , beg , token ;
1248
+ var buckets = this . buckets ;
1249
+ var bucket0 = buckets [ 0 ] ;
1250
+ var bucket1 = buckets [ 1 ] ;
1251
+ var bucket2 = buckets [ 2 ] ;
1252
+ var bucket3 = buckets [ 3 ] ;
1253
+ var bucket4 = buckets [ 4 ] ;
1254
+ var bucket5 = buckets [ 5 ] ;
1255
+ var bucket6 = buckets [ 6 ] ;
1256
+ var bucket7 = buckets [ 7 ] ;
1257
+ var f ;
1288
1258
1289
1259
re . lastIndex = 0 ;
1290
- while ( this . matches = re . exec ( url ) ) {
1291
- if ( this . bucket0 ) {
1292
- r = this . matchToken ( this . bucket0 ) ;
1293
- if ( r !== false ) { return r ; }
1260
+ while ( matches = re . exec ( url ) ) {
1261
+ beg = matches . index ;
1262
+ token = url . slice ( beg , re . lastIndex ) ;
1263
+ if ( bucket0 !== undefined ) {
1264
+ f = bucket0 [ token ] ;
1265
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1266
+ return f . s ;
1267
+ }
1294
1268
}
1295
- if ( this . bucket1 ) {
1296
- r = this . matchToken ( this . bucket1 ) ;
1297
- if ( r !== false ) { return r ; }
1269
+ if ( bucket1 !== undefined ) {
1270
+ f = bucket1 [ token ] ;
1271
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1272
+ return f . s ;
1273
+ }
1298
1274
}
1299
- if ( this . bucket2 ) {
1300
- r = this . matchToken ( this . bucket2 ) ;
1301
- if ( r !== false ) { return r ; }
1275
+ if ( bucket2 !== undefined ) {
1276
+ f = bucket2 [ token ] ;
1277
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1278
+ return f . s ;
1279
+ }
1302
1280
}
1303
- if ( this . bucket3 ) {
1304
- r = this . matchToken ( this . bucket3 ) ;
1305
- if ( r !== false ) { return r ; }
1281
+ if ( bucket3 !== undefined ) {
1282
+ f = bucket3 [ token ] ;
1283
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1284
+ return f . s ;
1285
+ }
1306
1286
}
1307
- if ( this . bucket4 ) {
1308
- r = this . matchToken ( this . bucket4 ) ;
1309
- if ( r !== false ) { return r ; }
1287
+ if ( bucket4 !== undefined ) {
1288
+ f = bucket4 [ token ] ;
1289
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1290
+ return f . s ;
1291
+ }
1310
1292
}
1311
- if ( this . bucket5 ) {
1312
- r = this . matchToken ( this . bucket5 ) ;
1313
- if ( r !== false ) { return r ; }
1293
+ if ( bucket5 !== undefined ) {
1294
+ f = bucket5 [ token ] ;
1295
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1296
+ return f . s ;
1297
+ }
1314
1298
}
1315
- if ( this . bucket6 ) {
1316
- r = this . matchToken ( this . bucket6 ) ;
1317
- if ( r !== false ) { return r ; }
1299
+ if ( bucket6 !== undefined ) {
1300
+ f = bucket6 [ token ] ;
1301
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1302
+ return f . s ;
1303
+ }
1318
1304
}
1319
- if ( this . bucket7 ) {
1320
- r = this . matchToken ( this . bucket7 ) ;
1321
- if ( r !== false ) { return r ; }
1305
+ if ( bucket7 !== undefined ) {
1306
+ f = bucket7 [ token ] ;
1307
+ if ( f !== undefined && f . match ( url , beg ) !== false ) {
1308
+ return f . s ;
1309
+ }
1322
1310
}
1323
1311
}
1324
1312
return false ;
@@ -1410,9 +1398,6 @@ FilterContainer.prototype.matchString = function(pageDetails, url, requestType,
1410
1398
var party = requestHostname . slice ( - pageDomain . length ) === pageDomain ?
1411
1399
FirstParty :
1412
1400
ThirdParty ;
1413
- var domainParty = this . toDomainBits ( pageDomain ) ;
1414
- var type = typeNameToTypeValue [ requestType ] ;
1415
- var categories = this . categories ;
1416
1401
1417
1402
// Test hostname-based block filters
1418
1403
var br = this . matchAnyPartyHostname ( requestHostname ) ;
@@ -1423,17 +1408,21 @@ FilterContainer.prototype.matchString = function(pageDetails, url, requestType,
1423
1408
// This will be used by hostname-based filters
1424
1409
pageHostname = pageDetails . pageHostname || '' ;
1425
1410
1411
+ var domainParty = this . toDomainBits ( pageDomain ) ;
1412
+ var type = typeNameToTypeValue [ requestType ] ;
1413
+ var categories = this . categories ;
1414
+ var buckets = this . buckets ;
1415
+
1426
1416
// Test against block filters
1427
1417
if ( br === false ) {
1428
- this . bucket0 = categories [ this . makeCategoryKey ( BlockAnyTypeAnyParty ) ] ;
1429
- this . bucket1 = categories [ this . makeCategoryKey ( BlockAnyType | party ) ] ;
1430
- this . bucket2 = categories [ this . makeCategoryKey ( BlockAnyTypeOneParty | domainParty ) ] ;
1431
- this . bucket3 = categories [ this . makeCategoryKey ( BlockAnyTypeOtherParties ) ] ;
1432
- this . bucket4 = categories [ this . makeCategoryKey ( BlockAnyParty | type ) ] ;
1433
- this . bucket5 = categories [ this . makeCategoryKey ( BlockAction | type | party ) ] ;
1434
- this . bucket6 = categories [ this . makeCategoryKey ( BlockOneParty | type | domainParty ) ] ;
1435
- this . bucket7 = categories [ this . makeCategoryKey ( BlockOtherParties | type ) ] ;
1436
-
1418
+ buckets [ 0 ] = categories [ this . makeCategoryKey ( BlockAnyTypeAnyParty ) ] ;
1419
+ buckets [ 1 ] = categories [ this . makeCategoryKey ( BlockAnyType | party ) ] ;
1420
+ buckets [ 2 ] = categories [ this . makeCategoryKey ( BlockAnyTypeOneParty | domainParty ) ] ;
1421
+ buckets [ 3 ] = categories [ this . makeCategoryKey ( BlockAnyTypeOtherParties ) ] ;
1422
+ buckets [ 4 ] = categories [ this . makeCategoryKey ( BlockAnyParty | type ) ] ;
1423
+ buckets [ 5 ] = categories [ this . makeCategoryKey ( BlockAction | type | party ) ] ;
1424
+ buckets [ 6 ] = categories [ this . makeCategoryKey ( BlockOneParty | type | domainParty ) ] ;
1425
+ buckets [ 7 ] = categories [ this . makeCategoryKey ( BlockOtherParties | type ) ] ;
1437
1426
br = this . matchTokens ( ) ;
1438
1427
}
1439
1428
@@ -1443,15 +1432,14 @@ FilterContainer.prototype.matchString = function(pageDetails, url, requestType,
1443
1432
}
1444
1433
1445
1434
// Test against allow filters
1446
- this . bucket0 = categories [ this . makeCategoryKey ( AllowAnyTypeAnyParty ) ] ;
1447
- this . bucket1 = categories [ this . makeCategoryKey ( AllowAnyType | party ) ] ;
1448
- this . bucket2 = categories [ this . makeCategoryKey ( AllowAnyTypeOneParty | domainParty ) ] ;
1449
- this . bucket3 = categories [ this . makeCategoryKey ( AllowAnyTypeOtherParties | domainParty ) ] ;
1450
- this . bucket4 = categories [ this . makeCategoryKey ( AllowAnyParty | type ) ] ;
1451
- this . bucket5 = categories [ this . makeCategoryKey ( AllowAction | type | party ) ] ;
1452
- this . bucket6 = categories [ this . makeCategoryKey ( AllowOneParty | type | domainParty ) ] ;
1453
- this . bucket7 = categories [ this . makeCategoryKey ( AllowOtherParties | type | domainParty ) ] ;
1454
-
1435
+ buckets [ 0 ] = categories [ this . makeCategoryKey ( AllowAnyTypeAnyParty ) ] ;
1436
+ buckets [ 1 ] = categories [ this . makeCategoryKey ( AllowAnyType | party ) ] ;
1437
+ buckets [ 2 ] = categories [ this . makeCategoryKey ( AllowAnyTypeOneParty | domainParty ) ] ;
1438
+ buckets [ 3 ] = categories [ this . makeCategoryKey ( AllowAnyTypeOtherParties | domainParty ) ] ;
1439
+ buckets [ 4 ] = categories [ this . makeCategoryKey ( AllowAnyParty | type ) ] ;
1440
+ buckets [ 5 ] = categories [ this . makeCategoryKey ( AllowAction | type | party ) ] ;
1441
+ buckets [ 6 ] = categories [ this . makeCategoryKey ( AllowOneParty | type | domainParty ) ] ;
1442
+ buckets [ 7 ] = categories [ this . makeCategoryKey ( AllowOtherParties | type | domainParty ) ] ;
1455
1443
var ar = this . matchTokens ( ) ;
1456
1444
if ( ar !== false ) {
1457
1445
return '@@' + ar ;
0 commit comments