1919 Home: https://github.com/gorhill/uBlock
2020*/
2121
22- 'use strict' ;
23-
2422/******************************************************************************/
2523
26- import publicSuffixList from '../lib/publicsuffixlist/publicsuffixlist.js' ;
27- import punycode from '../lib/punycode.js' ;
24+ import * as sfp from './static-filtering-parser.js' ;
2825
29- import io from './assets.js' ;
26+ import { CompiledListReader , CompiledListWriter } from './static-filtering-io.js' ;
27+ import { LineIterator , orphanizeString } from './text-utils.js' ;
3028import { 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+
3137import cosmeticFilteringEngine from './cosmetic-filtering.js' ;
38+ import { hostnameFromURI } from './uri-utils.js' ;
39+ import io from './assets.js' ;
3240import logger from './logger.js' ;
3341import 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' ;
3445import staticExtFilteringEngine from './static-ext-filtering.js' ;
3546import staticFilteringReverseLookup from './reverselookup.js' ;
3647import staticNetFilteringEngine from './static-net-filtering.js' ;
3748import µ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' ;
4949
50- import {
51- CompiledListReader ,
52- CompiledListWriter ,
53- } from './static-filtering-io.js' ;
50+ /******************************************************************************/
5451
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 ) ;
5955
6056/******************************************************************************/
6157
@@ -191,7 +187,7 @@ import {
191187 for ( const entry of adminSettings ) {
192188 if ( entry . length < 1 ) { continue ; }
193189 const name = entry [ 0 ] ;
194- if ( usDefault . hasOwnProperty ( name ) === false ) { continue ; }
190+ if ( hasOwnProperty ( usDefault , name ) === false ) { continue ; }
195191 const value = entry . length < 2
196192 ? usDefault [ name ]
197193 : this . settingValueFromString ( usDefault , name , entry [ 1 ] ) ;
@@ -220,8 +216,8 @@ import {
220216
221217 const toRemove = [ ] ;
222218 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 ; }
225221 toRemove . push ( key ) ;
226222 }
227223 if ( toRemove . length !== 0 ) {
@@ -258,7 +254,7 @@ import {
258254 for ( const entry of advancedSettings ) {
259255 if ( entry . length < 1 ) { continue ; }
260256 const name = entry [ 0 ] ;
261- if ( hsDefault . hasOwnProperty ( name ) === false ) { continue ; }
257+ if ( hasOwnProperty ( hsDefault , name ) === false ) { continue ; }
262258 const value = entry . length < 2
263259 ? hsDefault [ name ]
264260 : this . hiddenSettingValueFromString ( name , entry [ 1 ] ) ;
@@ -292,8 +288,8 @@ import {
292288 }
293289
294290 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 ; }
297293 if ( typeof hs [ key ] !== typeof hsDefault [ key ] ) { continue ; }
298294 this . hiddenSettings [ key ] = hs [ key ] ;
299295 }
@@ -338,8 +334,8 @@ onBroadcast(msg => {
338334 const matches = / ^ \s * ( \S + ) \s + ( .+ ) $ / . exec ( line ) ;
339335 if ( matches === null || matches . length !== 3 ) { continue ; }
340336 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 ; }
343339 const value = this . hiddenSettingValueFromString ( name , matches [ 2 ] ) ;
344340 if ( value !== undefined ) {
345341 out [ name ] = value ;
@@ -351,7 +347,7 @@ onBroadcast(msg => {
351347µb . hiddenSettingValueFromString = function ( name , value ) {
352348 if ( typeof name !== 'string' || typeof value !== 'string' ) { return ; }
353349 const hsDefault = this . hiddenSettingsDefault ;
354- if ( hsDefault . hasOwnProperty ( name ) === false ) { return ; }
350+ if ( hasOwnProperty ( hsDefault , name ) === false ) { return ; }
355351 let r ;
356352 switch ( typeof hsDefault [ name ] ) {
357353 case 'boolean' :
@@ -588,7 +584,6 @@ onBroadcast(msg => {
588584 // https://github.com/gorhill/uBlock/issues/1022
589585 // Be sure to end with an empty line.
590586 content = content . trim ( ) ;
591- if ( content !== '' ) { content += '\n' ; }
592587 this . removeCompiledFilterList ( this . userFiltersPath ) ;
593588 return io . put ( this . userFiltersPath , content ) ;
594589} ;
@@ -696,7 +691,7 @@ onBroadcast(msg => {
696691µb . autoSelectRegionalFilterLists = function ( lists ) {
697692 const selectedListKeys = [ this . userFiltersPath ] ;
698693 for ( const key in lists ) {
699- if ( lists . hasOwnProperty ( key ) === false ) { continue ; }
694+ if ( hasOwnProperty ( lists , key ) === false ) { continue ; }
700695 const list = lists [ key ] ;
701696 if ( list . content !== 'filters' ) { continue ; }
702697 if ( list . off !== true ) {
@@ -950,7 +945,7 @@ onBroadcast(msg => {
950945 let acceptedCount = snfe . acceptedCount + sxfe . acceptedCount ;
951946 let discardedCount = snfe . discardedCount + sxfe . discardedCount ;
952947 µb . applyCompiledFilters ( compiled , assetKey === µb . userFiltersPath ) ;
953- if ( µb . availableFilterLists . hasOwnProperty ( assetKey ) ) {
948+ if ( hasOwnProperty ( µb . availableFilterLists , assetKey ) ) {
954949 const entry = µb . availableFilterLists [ assetKey ] ;
955950 entry . entryCount = snfe . acceptedCount + sxfe . acceptedCount -
956951 acceptedCount ;
@@ -986,7 +981,7 @@ onBroadcast(msg => {
986981 // content.
987982 const toLoad = [ ] ;
988983 for ( const assetKey in lists ) {
989- if ( lists . hasOwnProperty ( assetKey ) === false ) { continue ; }
984+ if ( hasOwnProperty ( lists , assetKey ) === false ) { continue ; }
990985 if ( lists [ assetKey ] . off ) { continue ; }
991986 toLoad . push (
992987 µb . getCompiledFilterList ( assetKey ) . then ( details => {
@@ -1438,8 +1433,8 @@ onBroadcast(msg => {
14381433 const µbus = this . userSettings ;
14391434 const adminus = data . userSettings ;
14401435 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 ; }
14431438 bin [ name ] = adminus [ name ] ;
14441439 binNotEmpty = true ;
14451440 }
@@ -1502,13 +1497,21 @@ onBroadcast(msg => {
15021497 vAPI . storage . set ( bin ) ;
15031498 }
15041499
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 ( ) ;
15101503 } 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+ }
15121515 }
15131516} ;
15141517
@@ -1602,7 +1605,7 @@ onBroadcast(msg => {
16021605 if ( topic === 'before-asset-updated' ) {
16031606 if ( details . type === 'filters' ) {
16041607 if (
1605- this . availableFilterLists . hasOwnProperty ( details . assetKey ) === false ||
1608+ hasOwnProperty ( this . availableFilterLists , details . assetKey ) === false ||
16061609 this . selectedFilterLists . indexOf ( details . assetKey ) === - 1 ||
16071610 this . badLists . get ( details . assetKey )
16081611 ) {
@@ -1617,7 +1620,7 @@ onBroadcast(msg => {
16171620 // Skip selfie-related content.
16181621 if ( details . assetKey . startsWith ( 'selfie/' ) ) { return ; }
16191622 const cached = typeof details . content === 'string' && details . content !== '' ;
1620- if ( this . availableFilterLists . hasOwnProperty ( details . assetKey ) ) {
1623+ if ( hasOwnProperty ( this . availableFilterLists , details . assetKey ) ) {
16211624 if ( cached ) {
16221625 if ( this . selectedFilterLists . indexOf ( details . assetKey ) !== - 1 ) {
16231626 this . extractFilterListMetadata (
0 commit comments