19
19
Home: https://github.com/gorhill/uBlock
20
20
*/
21
21
22
- 'use strict' ;
23
-
24
22
/******************************************************************************/
25
23
26
- import publicSuffixList from '../lib/publicsuffixlist/publicsuffixlist.js' ;
27
- import punycode from '../lib/punycode.js' ;
24
+ import * as sfp from './static-filtering-parser.js' ;
28
25
29
- import io from './assets.js' ;
26
+ import { CompiledListReader , CompiledListWriter } from './static-filtering-io.js' ;
27
+ import { LineIterator , orphanizeString } from './text-utils.js' ;
30
28
import { broadcast , filteringBehaviorChanged , onBroadcast } from './broadcast.js' ;
29
+ import { i18n , i18n$ } from './i18n.js' ;
30
+ import {
31
+ permanentFirewall ,
32
+ permanentSwitches ,
33
+ permanentURLFiltering ,
34
+ } from './filtering-engines.js' ;
35
+ import { ubolog , ubologSet } from './console.js' ;
36
+
31
37
import cosmeticFilteringEngine from './cosmetic-filtering.js' ;
38
+ import { hostnameFromURI } from './uri-utils.js' ;
39
+ import io from './assets.js' ;
32
40
import logger from './logger.js' ;
33
41
import lz4Codec from './lz4.js' ;
42
+ import publicSuffixList from '../lib/publicsuffixlist/publicsuffixlist.js' ;
43
+ import punycode from '../lib/punycode.js' ;
44
+ import { redirectEngine } from './redirect-engine.js' ;
34
45
import staticExtFilteringEngine from './static-ext-filtering.js' ;
35
46
import staticFilteringReverseLookup from './reverselookup.js' ;
36
47
import staticNetFilteringEngine from './static-net-filtering.js' ;
37
48
import µb from './background.js' ;
38
- import { hostnameFromURI } from './uri-utils.js' ;
39
- import { i18n , i18n$ } from './i18n.js' ;
40
- import { redirectEngine } from './redirect-engine.js' ;
41
- import { ubolog , ubologSet } from './console.js' ;
42
- import * as sfp from './static-filtering-parser.js' ;
43
-
44
- import {
45
- permanentFirewall ,
46
- permanentSwitches ,
47
- permanentURLFiltering ,
48
- } from './filtering-engines.js' ;
49
49
50
- import {
51
- CompiledListReader ,
52
- CompiledListWriter ,
53
- } from './static-filtering-io.js' ;
50
+ /******************************************************************************/
54
51
55
- import {
56
- LineIterator ,
57
- orphanizeString ,
58
- } from './text-utils.js' ;
52
+ // https://eslint.org/docs/latest/rules/no-prototype-builtins
53
+ const hasOwnProperty = ( o , p ) =>
54
+ Object . prototype . hasOwnProperty . call ( o , p ) ;
59
55
60
56
/******************************************************************************/
61
57
@@ -191,7 +187,7 @@ import {
191
187
for ( const entry of adminSettings ) {
192
188
if ( entry . length < 1 ) { continue ; }
193
189
const name = entry [ 0 ] ;
194
- if ( usDefault . hasOwnProperty ( name ) === false ) { continue ; }
190
+ if ( hasOwnProperty ( usDefault , name ) === false ) { continue ; }
195
191
const value = entry . length < 2
196
192
? usDefault [ name ]
197
193
: this . settingValueFromString ( usDefault , name , entry [ 1 ] ) ;
@@ -220,8 +216,8 @@ import {
220
216
221
217
const toRemove = [ ] ;
222
218
for ( const key in this . userSettings ) {
223
- if ( this . userSettings . hasOwnProperty ( key ) === false ) { continue ; }
224
- if ( toSave . hasOwnProperty ( key ) ) { continue ; }
219
+ if ( hasOwnProperty ( this . userSettings , key ) === false ) { continue ; }
220
+ if ( hasOwnProperty ( toSave , key ) ) { continue ; }
225
221
toRemove . push ( key ) ;
226
222
}
227
223
if ( toRemove . length !== 0 ) {
@@ -258,7 +254,7 @@ import {
258
254
for ( const entry of advancedSettings ) {
259
255
if ( entry . length < 1 ) { continue ; }
260
256
const name = entry [ 0 ] ;
261
- if ( hsDefault . hasOwnProperty ( name ) === false ) { continue ; }
257
+ if ( hasOwnProperty ( hsDefault , name ) === false ) { continue ; }
262
258
const value = entry . length < 2
263
259
? hsDefault [ name ]
264
260
: this . hiddenSettingValueFromString ( name , entry [ 1 ] ) ;
@@ -292,8 +288,8 @@ import {
292
288
}
293
289
294
290
for ( const key in hsDefault ) {
295
- if ( hsDefault . hasOwnProperty ( key ) === false ) { continue ; }
296
- if ( hsAdmin . hasOwnProperty ( name ) ) { continue ; }
291
+ if ( hasOwnProperty ( hsDefault , key ) === false ) { continue ; }
292
+ if ( hasOwnProperty ( hsAdmin , name ) ) { continue ; }
297
293
if ( typeof hs [ key ] !== typeof hsDefault [ key ] ) { continue ; }
298
294
this . hiddenSettings [ key ] = hs [ key ] ;
299
295
}
@@ -338,8 +334,8 @@ onBroadcast(msg => {
338
334
const matches = / ^ \s * ( \S + ) \s + ( .+ ) $ / . exec ( line ) ;
339
335
if ( matches === null || matches . length !== 3 ) { continue ; }
340
336
const name = matches [ 1 ] ;
341
- if ( out . hasOwnProperty ( name ) === false ) { continue ; }
342
- if ( this . hiddenSettingsAdmin . hasOwnProperty ( name ) ) { continue ; }
337
+ if ( hasOwnProperty ( out , name ) === false ) { continue ; }
338
+ if ( hasOwnProperty ( this . hiddenSettingsAdmin , name ) ) { continue ; }
343
339
const value = this . hiddenSettingValueFromString ( name , matches [ 2 ] ) ;
344
340
if ( value !== undefined ) {
345
341
out [ name ] = value ;
@@ -351,7 +347,7 @@ onBroadcast(msg => {
351
347
µb . hiddenSettingValueFromString = function ( name , value ) {
352
348
if ( typeof name !== 'string' || typeof value !== 'string' ) { return ; }
353
349
const hsDefault = this . hiddenSettingsDefault ;
354
- if ( hsDefault . hasOwnProperty ( name ) === false ) { return ; }
350
+ if ( hasOwnProperty ( hsDefault , name ) === false ) { return ; }
355
351
let r ;
356
352
switch ( typeof hsDefault [ name ] ) {
357
353
case 'boolean' :
@@ -588,7 +584,6 @@ onBroadcast(msg => {
588
584
// https://github.com/gorhill/uBlock/issues/1022
589
585
// Be sure to end with an empty line.
590
586
content = content . trim ( ) ;
591
- if ( content !== '' ) { content += '\n' ; }
592
587
this . removeCompiledFilterList ( this . userFiltersPath ) ;
593
588
return io . put ( this . userFiltersPath , content ) ;
594
589
} ;
@@ -696,7 +691,7 @@ onBroadcast(msg => {
696
691
µb . autoSelectRegionalFilterLists = function ( lists ) {
697
692
const selectedListKeys = [ this . userFiltersPath ] ;
698
693
for ( const key in lists ) {
699
- if ( lists . hasOwnProperty ( key ) === false ) { continue ; }
694
+ if ( hasOwnProperty ( lists , key ) === false ) { continue ; }
700
695
const list = lists [ key ] ;
701
696
if ( list . content !== 'filters' ) { continue ; }
702
697
if ( list . off !== true ) {
@@ -950,7 +945,7 @@ onBroadcast(msg => {
950
945
let acceptedCount = snfe . acceptedCount + sxfe . acceptedCount ;
951
946
let discardedCount = snfe . discardedCount + sxfe . discardedCount ;
952
947
µb . applyCompiledFilters ( compiled , assetKey === µb . userFiltersPath ) ;
953
- if ( µb . availableFilterLists . hasOwnProperty ( assetKey ) ) {
948
+ if ( hasOwnProperty ( µb . availableFilterLists , assetKey ) ) {
954
949
const entry = µb . availableFilterLists [ assetKey ] ;
955
950
entry . entryCount = snfe . acceptedCount + sxfe . acceptedCount -
956
951
acceptedCount ;
@@ -986,7 +981,7 @@ onBroadcast(msg => {
986
981
// content.
987
982
const toLoad = [ ] ;
988
983
for ( const assetKey in lists ) {
989
- if ( lists . hasOwnProperty ( assetKey ) === false ) { continue ; }
984
+ if ( hasOwnProperty ( lists , assetKey ) === false ) { continue ; }
990
985
if ( lists [ assetKey ] . off ) { continue ; }
991
986
toLoad . push (
992
987
µb . getCompiledFilterList ( assetKey ) . then ( details => {
@@ -1438,8 +1433,8 @@ onBroadcast(msg => {
1438
1433
const µbus = this . userSettings ;
1439
1434
const adminus = data . userSettings ;
1440
1435
for ( const name in µbus ) {
1441
- if ( µbus . hasOwnProperty ( name ) === false ) { continue ; }
1442
- if ( adminus . hasOwnProperty ( name ) === false ) { continue ; }
1436
+ if ( hasOwnProperty ( µbus , name ) === false ) { continue ; }
1437
+ if ( hasOwnProperty ( adminus , name ) === false ) { continue ; }
1443
1438
bin [ name ] = adminus [ name ] ;
1444
1439
binNotEmpty = true ;
1445
1440
}
@@ -1502,13 +1497,21 @@ onBroadcast(msg => {
1502
1497
vAPI . storage . set ( bin ) ;
1503
1498
}
1504
1499
1505
- if (
1506
- Array . isArray ( toOverwrite . filters ) &&
1507
- toOverwrite . filters . length !== 0
1508
- ) {
1509
- this . saveUserFilters ( toOverwrite . filters . join ( '\n' ) ) ;
1500
+ let userFiltersAfter ;
1501
+ if ( Array . isArray ( toOverwrite . filters ) ) {
1502
+ userFiltersAfter = toOverwrite . filters . join ( '\n' ) . trim ( ) ;
1510
1503
} else if ( typeof data . userFilters === 'string' ) {
1511
- this . saveUserFilters ( data . userFilters ) ;
1504
+ userFiltersAfter = data . userFilters . trim ( ) ;
1505
+ }
1506
+ if ( typeof userFiltersAfter === 'string' ) {
1507
+ const bin = await vAPI . storage . get ( this . userFiltersPath ) ;
1508
+ const userFiltersBefore = bin && bin [ this . userFiltersPath ] || '' ;
1509
+ if ( userFiltersAfter !== userFiltersBefore ) {
1510
+ await Promise . all ( [
1511
+ this . saveUserFilters ( userFiltersAfter ) ,
1512
+ this . selfieManager . destroy ( ) ,
1513
+ ] ) ;
1514
+ }
1512
1515
}
1513
1516
} ;
1514
1517
@@ -1602,7 +1605,7 @@ onBroadcast(msg => {
1602
1605
if ( topic === 'before-asset-updated' ) {
1603
1606
if ( details . type === 'filters' ) {
1604
1607
if (
1605
- this . availableFilterLists . hasOwnProperty ( details . assetKey ) === false ||
1608
+ hasOwnProperty ( this . availableFilterLists , details . assetKey ) === false ||
1606
1609
this . selectedFilterLists . indexOf ( details . assetKey ) === - 1 ||
1607
1610
this . badLists . get ( details . assetKey )
1608
1611
) {
@@ -1617,7 +1620,7 @@ onBroadcast(msg => {
1617
1620
// Skip selfie-related content.
1618
1621
if ( details . assetKey . startsWith ( 'selfie/' ) ) { return ; }
1619
1622
const cached = typeof details . content === 'string' && details . content !== '' ;
1620
- if ( this . availableFilterLists . hasOwnProperty ( details . assetKey ) ) {
1623
+ if ( hasOwnProperty ( this . availableFilterLists , details . assetKey ) ) {
1621
1624
if ( cached ) {
1622
1625
if ( this . selectedFilterLists . indexOf ( details . assetKey ) !== - 1 ) {
1623
1626
this . extractFilterListMetadata (
0 commit comments