File tree 12 files changed +51
-11
lines changed
Sources/ContentScopeScripts/dist
12 files changed +51
-11
lines changed Original file line number Diff line number Diff line change 1
- - ntp: support default background colors (#1596 )
1
+ - Setting of document for tracker analysis (#1613 )
Original file line number Diff line number Diff line change 885
885
const style = createStyleElement ( css ) ;
886
886
getInjectionElement ( ) . appendChild ( style ) ;
887
887
}
888
+ function getGlobal ( ) {
889
+ return globalObj ;
890
+ }
888
891
function nextRandom ( v ) {
889
892
return Math . abs ( v >> 1 | ( v << 62 ^ v << 61 ) & ~ ( ~ 0 << 63 ) << 62 ) ;
890
893
}
2578
2581
2579
2582
// src/trackers.js
2580
2583
init_define_import_meta_trackerLookup ( ) ;
2581
- function isTrackerOrigin ( trackerLookup , originHostname = document . location . hostname ) {
2584
+ function isTrackerOrigin ( trackerLookup , originHostname = getGlobal ( ) . document . location . hostname ) {
2582
2585
const parts = originHostname . split ( "." ) . reverse ( ) ;
2583
2586
let node = trackerLookup ;
2584
2587
for ( const sub of parts ) {
Original file line number Diff line number Diff line change 1607
1607
function registerMessageSecret(secret) {
1608
1608
messageSecret = secret;
1609
1609
}
1610
+ function getGlobal() {
1611
+ return globalObj;
1612
+ }
1610
1613
var exemptionLists = {};
1611
1614
var debug = false;
1612
1615
function initStringExemptionLists(args) {
3133
3136
3134
3137
// src/trackers.js
3135
3138
init_define_import_meta_trackerLookup();
3136
- function isTrackerOrigin(trackerLookup, originHostname = document.location.hostname) {
3139
+ function isTrackerOrigin(trackerLookup, originHostname = getGlobal(). document.location.hostname) {
3137
3140
const parts = originHostname.split(".").reverse();
3138
3141
let node = trackerLookup;
3139
3142
for (const sub of parts) {
Original file line number Diff line number Diff line change 49
49
function registerMessageSecret ( secret ) {
50
50
messageSecret = secret ;
51
51
}
52
+ function getGlobal ( ) {
53
+ return globalObj ;
54
+ }
52
55
var exemptionLists = { } ;
53
56
function shouldExemptUrl ( type , url ) {
54
57
for ( const regex of exemptionLists [ type ] ) {
1719
1722
} ;
1720
1723
1721
1724
// src/trackers.js
1722
- function isTrackerOrigin ( trackerLookup , originHostname = document . location . hostname ) {
1725
+ function isTrackerOrigin ( trackerLookup , originHostname = getGlobal ( ) . document . location . hostname ) {
1723
1726
const parts = originHostname . split ( "." ) . reverse ( ) ;
1724
1727
let node = trackerLookup ;
1725
1728
for ( const sub of parts ) {
Original file line number Diff line number Diff line change 1573
1573
function registerMessageSecret ( secret ) {
1574
1574
messageSecret = secret ;
1575
1575
}
1576
+ function getGlobal ( ) {
1577
+ return globalObj ;
1578
+ }
1576
1579
var exemptionLists = { } ;
1577
1580
var debug = false ;
1578
1581
function initStringExemptionLists ( args ) {
3093
3096
3094
3097
// src/trackers.js
3095
3098
init_define_import_meta_trackerLookup ( ) ;
3096
- function isTrackerOrigin ( trackerLookup , originHostname = document . location . hostname ) {
3099
+ function isTrackerOrigin ( trackerLookup , originHostname = getGlobal ( ) . document . location . hostname ) {
3097
3100
const parts = originHostname . split ( "." ) . reverse ( ) ;
3098
3101
let node = trackerLookup ;
3099
3102
for ( const sub of parts ) {
Original file line number Diff line number Diff line change 885
885
const style = createStyleElement ( css ) ;
886
886
getInjectionElement ( ) . appendChild ( style ) ;
887
887
}
888
+ function getGlobal ( ) {
889
+ return globalObj ;
890
+ }
888
891
function nextRandom ( v ) {
889
892
return Math . abs ( v >> 1 | ( v << 62 ^ v << 61 ) & ~ ( ~ 0 << 63 ) << 62 ) ;
890
893
}
3089
3092
3090
3093
// src/trackers.js
3091
3094
init_define_import_meta_trackerLookup ( ) ;
3092
- function isTrackerOrigin ( trackerLookup , originHostname = document . location . hostname ) {
3095
+ function isTrackerOrigin ( trackerLookup , originHostname = getGlobal ( ) . document . location . hostname ) {
3093
3096
const parts = originHostname . split ( "." ) . reverse ( ) ;
3094
3097
let node = trackerLookup ;
3095
3098
for ( const sub of parts ) {
Original file line number Diff line number Diff line change 855
855
const style = createStyleElement ( css ) ;
856
856
getInjectionElement ( ) . appendChild ( style ) ;
857
857
}
858
+ function getGlobal ( ) {
859
+ return globalObj ;
860
+ }
858
861
function nextRandom ( v ) {
859
862
return Math . abs ( v >> 1 | ( v << 62 ^ v << 61 ) & ~ ( ~ 0 << 63 ) << 62 ) ;
860
863
}
2549
2552
} ;
2550
2553
2551
2554
// src/trackers.js
2552
- function isTrackerOrigin ( trackerLookup2 , originHostname = document . location . hostname ) {
2555
+ function isTrackerOrigin ( trackerLookup2 , originHostname = getGlobal ( ) . document . location . hostname ) {
2553
2556
const parts = originHostname . split ( "." ) . reverse ( ) ;
2554
2557
let node = trackerLookup2 ;
2555
2558
for ( const sub of parts ) {
Original file line number Diff line number Diff line change 855
855
const style = createStyleElement ( css ) ;
856
856
getInjectionElement ( ) . appendChild ( style ) ;
857
857
}
858
+ function getGlobal ( ) {
859
+ return globalObj ;
860
+ }
858
861
function nextRandom ( v ) {
859
862
return Math . abs ( v >> 1 | ( v << 62 ^ v << 61 ) & ~ ( ~ 0 << 63 ) << 62 ) ;
860
863
}
2549
2552
} ;
2550
2553
2551
2554
// src/trackers.js
2552
- function isTrackerOrigin ( trackerLookup2 , originHostname = document . location . hostname ) {
2555
+ function isTrackerOrigin ( trackerLookup2 , originHostname = getGlobal ( ) . document . location . hostname ) {
2553
2556
const parts = originHostname . split ( "." ) . reverse ( ) ;
2554
2557
let node = trackerLookup2 ;
2555
2558
for ( const sub of parts ) {
Original file line number Diff line number Diff line change 2367
2367
const style = createStyleElement(css);
2368
2368
getInjectionElement().appendChild(style);
2369
2369
}
2370
+ function getGlobal() {
2371
+ return globalObj;
2372
+ }
2370
2373
function nextRandom(v) {
2371
2374
return Math.abs(v >> 1 | (v << 62 ^ v << 61) & ~(~0 << 63) << 62);
2372
2375
}
4586
4589
4587
4590
// src/trackers.js
4588
4591
init_define_import_meta_trackerLookup();
4589
- function isTrackerOrigin(trackerLookup2, originHostname = document.location.hostname) {
4592
+ function isTrackerOrigin(trackerLookup2, originHostname = getGlobal(). document.location.hostname) {
4590
4593
const parts = originHostname.split(".").reverse();
4591
4594
let node = trackerLookup2;
4592
4595
for (const sub of parts) {
Original file line number Diff line number Diff line change 2367
2367
const style = createStyleElement(css);
2368
2368
getInjectionElement().appendChild(style);
2369
2369
}
2370
+ function getGlobal() {
2371
+ return globalObj;
2372
+ }
2370
2373
function nextRandom(v) {
2371
2374
return Math.abs(v >> 1 | (v << 62 ^ v << 61) & ~(~0 << 63) << 62);
2372
2375
}
4119
4122
4120
4123
// src/trackers.js
4121
4124
init_define_import_meta_trackerLookup();
4122
- function isTrackerOrigin(trackerLookup2, originHostname = document.location.hostname) {
4125
+ function isTrackerOrigin(trackerLookup2, originHostname = getGlobal(). document.location.hostname) {
4123
4126
const parts = originHostname.split(".").reverse();
4124
4127
let node = trackerLookup2;
4125
4128
for (const sub of parts) {
Original file line number Diff line number Diff line change
1
+ import { getGlobal } from './utils.js';
2
+
1
3
/**
2
4
* Check if the current document origin is on the tracker list, using the provided lookup trie.
3
5
* @param {object} trackerLookup Trie lookup of tracker domains
4
6
* @returns {boolean} True iff the origin is a tracker.
7
+ *
8
+ * Note: getGlobal() is used in testing to get the global object,
9
+ * it's a work around for ESM modules are essentially singletons preventing overriding of global variables.
5
10
*/
6
- export function isTrackerOrigin(trackerLookup, originHostname = document.location.hostname) {
11
+ export function isTrackerOrigin(trackerLookup, originHostname = getGlobal(). document.location.hostname) {
7
12
const parts = originHostname.split('.').reverse();
8
13
let node = trackerLookup;
9
14
for (const sub of parts) {
Original file line number Diff line number Diff line change @@ -49,6 +49,14 @@ export function setGlobal(globalObjIn) {
49
49
Error = globalObj.Error;
50
50
}
51
51
52
+ /**
53
+ * Used for testing to allow other files to override the globals used within this file.
54
+ * @returns {globalThis} the global object
55
+ */
56
+ export function getGlobal() {
57
+ return globalObj;
58
+ }
59
+
52
60
// linear feedback shift register to find a random approximation
53
61
export function nextRandom(v) {
54
62
return Math.abs((v >> 1) | (((v << 62) ^ (v << 61)) & (~(~0 << 63) << 62)));
You can’t perform that action at this time.
0 commit comments