Skip to content

Commit 0c10413

Browse files
Remove the need for the build replacements for all non chrome platforms (#344)
1 parent c6f61ea commit 0c10413

File tree

7 files changed

+45
-49
lines changed

7 files changed

+45
-49
lines changed

inject/android.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
/* global contentScopeFeatures */
21
/**
32
* @module Android integration
43
* @category Content Scope Scripts Integrations
54
*/
5+
import { load, init } from '../src/content-scope-features.js'
66
import { processConfig, isGloballyDisabled } from './../src/utils'
77

8-
function init () {
8+
function initCode () {
99
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
1010
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
1111
if (isGloballyDisabled(processedConfig)) {
1212
return
1313
}
1414

15-
contentScopeFeatures.load({
15+
load({
1616
platform: processedConfig.platform
1717
})
1818

19-
contentScopeFeatures.init(processedConfig)
19+
init(processedConfig)
2020

2121
// Not supported:
22-
// contentScopeFeatures.update(message)
22+
// update(message)
2323
}
2424

25-
init()
25+
initCode()

inject/apple.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
/* global contentScopeFeatures */
21
/**
3-
* @module Apple integration
4-
* @category Content Scope Scripts Integrations
5-
*/
6-
2+
* @module Apple integration
3+
* @category Content Scope Scripts Integrations
4+
*/
5+
import { load, init } from '../src/content-scope-features.js'
76
import { processConfig, isGloballyDisabled } from './../src/utils'
87

9-
function init () {
8+
function initCode () {
109
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
1110
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
1211
if (isGloballyDisabled(processedConfig)) {
1312
return
1413
}
1514

16-
contentScopeFeatures.load({
15+
load({
1716
platform: processedConfig.platform
1817
})
1918

20-
contentScopeFeatures.init(processedConfig)
19+
init(processedConfig)
2120

2221
// Not supported:
23-
// contentScopeFeatures.update(message)
22+
// update(message)
2423
}
2524

26-
init()
25+
initCode()

inject/chrome-mv3.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
/* global contentScopeFeatures */
21
/**
3-
* @module Chrome MV3 integration
4-
* @category Content Scope Scripts Integrations
5-
*/
6-
2+
* @module Chrome MV3 integration
3+
* @category Content Scope Scripts Integrations
4+
*/
5+
import { load, init, update } from '../src/content-scope-features.js'
76
import { isTrackerOrigin } from '../src/trackers'
87

98
const secret = (crypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32).toString().replace('0.', '')
109

11-
contentScopeFeatures.load({
10+
load({
1211
platform: {
1312
name: 'extension'
1413
},
@@ -24,12 +23,12 @@ window.addEventListener(secret, ({ detail: message }) => {
2423

2524
switch (message.type) {
2625
case 'update':
27-
contentScopeFeatures.update(message)
26+
update(message)
2827
break
2928
case 'register':
3029
if (message.argumentsObject) {
3130
message.argumentsObject.messageSecret = secret
32-
contentScopeFeatures.init(message.argumentsObject)
31+
init(message.argumentsObject)
3332
}
3433
break
3534
}

inject/integration.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global contentScopeFeatures */
1+
import { load, init } from '../src/content-scope-features.js'
22
function getTopLevelURL () {
33
try {
44
// FROM: https://stackoverflow.com/a/7739035/73479
@@ -66,19 +66,19 @@ function mergeDeep (target, ...sources) {
6666
return mergeDeep(target, ...sources)
6767
}
6868

69-
async function init () {
69+
async function initCode () {
7070
const topLevelUrl = getTopLevelURL()
7171
const processedConfig = generateConfig()
7272

73-
await contentScopeFeatures.load({
73+
await load({
7474
platform: processedConfig.platform
7575
})
7676

7777
// mark this phase as loaded
7878
setStatus('loaded')
7979

8080
if (!topLevelUrl.searchParams.has('wait-for-init-args')) {
81-
await contentScopeFeatures.init(processedConfig)
81+
await init(processedConfig)
8282
setStatus('initialized')
8383
return
8484
}
@@ -88,7 +88,7 @@ async function init () {
8888
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
8989
const merged = mergeDeep(processedConfig, evt.detail)
9090
// init features
91-
await contentScopeFeatures.init(merged)
91+
await init(merged)
9292

9393
// set status to initialized so that tests can resume
9494
setStatus('initialized')
@@ -103,4 +103,4 @@ function setStatus (status) {
103103
window.__content_scope_status = status
104104
}
105105

106-
init()
106+
initCode()

inject/mozilla.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* global contentScopeFeatures */
21
/**
3-
* @module Mozilla integration
4-
* @category Content Scope Scripts Integrations
5-
*/
2+
* @module Mozilla integration
3+
* @category Content Scope Scripts Integrations
4+
*/
5+
import { load, init, update } from '../src/content-scope-features.js'
66
import { isTrackerOrigin } from '../src/trackers'
77

88
const allowedMessages = [
@@ -20,8 +20,8 @@ function randomString () {
2020
return num.toString().replace('0.', '')
2121
}
2222

23-
function init () {
24-
contentScopeFeatures.load({
23+
function initCode () {
24+
load({
2525
platform: {
2626
name: 'extension'
2727
},
@@ -53,13 +53,13 @@ function init () {
5353
})
5454
}
5555
message.messageSecret = messageSecret
56-
contentScopeFeatures.init(message)
56+
init(message)
5757
})
5858

5959
chrome.runtime.onMessage.addListener((message) => {
6060
// forward update messages to the embedded script
6161
if (message && message.type === 'update') {
62-
contentScopeFeatures.update(message)
62+
update(message)
6363
}
6464
})
6565

@@ -82,9 +82,9 @@ function init () {
8282
response
8383
}
8484

85-
contentScopeFeatures.update(message)
85+
update(message)
8686
})
8787
})
8888
}
8989

90-
init()
90+
initCode()

inject/windows.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
/* global contentScopeFeatures */
21
/**
32
* @module Windows integration
43
* @category Content Scope Scripts Integrations
54
*/
5+
import { load, init } from '../src/content-scope-features.js'
66
import { processConfig, isGloballyDisabled, windowsSpecificFeatures } from './../src/utils'
77

8-
function init () {
8+
function initCode () {
99
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
1010
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$, windowsSpecificFeatures)
1111
if (isGloballyDisabled(processedConfig)) {
1212
return
1313
}
1414

15-
contentScopeFeatures.load({
15+
load({
1616
platform: processedConfig.platform
1717
})
1818

19-
contentScopeFeatures.init(processedConfig)
19+
init(processedConfig)
2020

2121
// Not supported:
22-
// contentScopeFeatures.update(message)
22+
// update(message)
2323
}
2424

25-
init()
25+
initCode()

scripts/inject.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ async function init () {
2525
}
2626

2727
async function initOther (injectScriptPath, platformName) {
28-
const replaceString = '/* global contentScopeFeatures */'
2928
const injectScript = await rollupScript(injectScriptPath, `inject${platformName}`)
30-
const contentScope = await rollupScript(contentScopePath, contentScopeName)
31-
const outputScript = injectScript.toString().replace(replaceString, contentScope.toString())
29+
const outputScript = injectScript
3230
console.log(outputScript)
3331
}
3432

0 commit comments

Comments
 (0)