@duckduckgo/autoconsent 4.4.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,148 +1,142 @@
1
- (function () {
2
- 'use strict';
3
-
4
- const manifestVersion = chrome.runtime.getManifest().manifest_version;
5
- // Storage abstraction: MV2 keeps everything in memory, MV3 uses chrome.storage
6
- const storage = {};
7
- async function storageSet(obj) {
8
- if (manifestVersion === 2) {
9
- Object.assign(storage, obj);
10
- return;
11
- }
12
- return chrome.storage.local.set(obj);
13
- }
14
- async function storageGet(key) {
15
- if (key === null) {
16
- if (manifestVersion === 2) {
17
- return storage;
18
- }
19
- return await chrome.storage.local.get(null);
20
- }
21
- if (manifestVersion === 2) {
22
- return storage[key];
23
- }
24
- return (await chrome.storage.local.get(key))?.[key];
1
+ (() => {
2
+ // addon/mv-compat.ts
3
+ var manifestVersion = chrome.runtime.getManifest().manifest_version;
4
+ var storage = {};
5
+ async function storageSet(obj) {
6
+ if (manifestVersion === 2) {
7
+ Object.assign(storage, obj);
8
+ return;
25
9
  }
26
-
27
- let backgroundPageConnection;
28
- function sendBackgroundMessage(msg) {
29
- backgroundPageConnection.postMessage(msg);
10
+ return chrome.storage.local.set(obj);
11
+ }
12
+ async function storageGet(key) {
13
+ if (key === null) {
14
+ if (manifestVersion === 2) {
15
+ return storage;
16
+ }
17
+ return await chrome.storage.local.get(null);
30
18
  }
31
- function getRowForInstance(instanceId) {
32
- const rowId = `instance-${instanceId}`;
33
- if (document.getElementById(rowId) !== null) {
34
- // update existing row
35
- const td = document.getElementById(rowId).querySelectorAll("td");
36
- return td;
37
- }
38
- else {
39
- const template = document.querySelector("#row");
40
- const table = document.querySelector("tbody");
41
- const clone = template.content.cloneNode(true);
42
- const td = clone.querySelectorAll("td");
43
- table.appendChild(clone);
44
- table.lastElementChild.id = rowId;
45
- return td;
46
- }
19
+ if (manifestVersion === 2) {
20
+ return storage[key];
47
21
  }
48
- function reconnect() {
49
- backgroundPageConnection = chrome.runtime.connect({
50
- name: "devtools-panel",
51
- });
52
- sendBackgroundMessage({
53
- type: "init",
54
- tabId: chrome.devtools.inspectedWindow.tabId,
55
- });
56
- backgroundPageConnection.onMessage.addListener(function (message) {
57
- if (message.type === "report") {
58
- const td = getRowForInstance(message.instanceId);
59
- td[0].innerText = `${message.frameId}`;
60
- td[1].innerText = message.url;
61
- td[2].innerText = message.state.lifecycle;
62
- td[3].innerText = message.state.prehideOn ? "yes" : "no";
63
- td[4].innerText = `${message.state.findCmpAttempts}`;
64
- td[5].innerText = message.state.detectedCmps.join(", ");
65
- td[6].innerText = message.state.detectedPopups.join(", ");
66
- }
67
- else if (message.type === "instanceTerminated") {
68
- document
69
- .getElementById(`instance-${message.instanceId}`)
70
- ?.classList.add("dead");
71
- }
72
- });
73
- backgroundPageConnection.onDisconnect.addListener(() => {
74
- reconnect();
75
- });
76
- return backgroundPageConnection;
22
+ return (await chrome.storage.local.get(key))?.[key];
23
+ }
24
+
25
+ // addon/devtools/panel.ts
26
+ var backgroundPageConnection;
27
+ function sendBackgroundMessage(msg) {
28
+ backgroundPageConnection.postMessage(msg);
29
+ }
30
+ function getRowForInstance(instanceId) {
31
+ const rowId = `instance-${instanceId}`;
32
+ if (document.getElementById(rowId) !== null) {
33
+ const td = document.getElementById(rowId).querySelectorAll("td");
34
+ return td;
35
+ } else {
36
+ const template = document.querySelector("#row");
37
+ const table = document.querySelector("tbody");
38
+ const clone = template.content.cloneNode(true);
39
+ const td = clone.querySelectorAll("td");
40
+ table.appendChild(clone);
41
+ table.lastElementChild.id = rowId;
42
+ return td;
77
43
  }
78
- const clearStorageCheckbox = document.querySelector("#clear-storage");
79
- const clearPanel = () => {
80
- const tbody = document.querySelector("tbody");
81
- while (tbody.firstChild) {
82
- tbody.removeChild(tbody.firstChild);
83
- }
84
- };
85
- document.getElementById("clear").addEventListener("click", clearPanel);
86
- document.getElementById("reload").addEventListener("click", async () => {
87
- if (clearStorageCheckbox.checked) {
88
- const tab = await chrome.tabs.get(chrome.devtools.inspectedWindow.tabId);
89
- const url = new URL(tab.url);
90
- await chrome.browsingData.remove({
91
- origins: [url.origin],
92
- }, {
93
- cookies: true,
94
- localStorage: true,
95
- indexedDB: true,
96
- });
97
- }
98
- clearPanel();
99
- chrome.devtools.inspectedWindow.reload({});
44
+ }
45
+ function reconnect() {
46
+ backgroundPageConnection = chrome.runtime.connect({
47
+ name: "devtools-panel"
100
48
  });
101
- document.getElementById("mode").addEventListener("change", async () => {
102
- const storedConfig = await storageGet("config");
103
- let autoAction = document
104
- .querySelector("#mode > option:checked")
105
- .getAttribute("data-autoaction");
106
- if (autoAction === "null") {
107
- autoAction = null;
108
- }
109
- storedConfig.autoAction = autoAction;
110
- storageSet({
111
- config: storedConfig,
112
- });
49
+ sendBackgroundMessage({
50
+ type: "init",
51
+ tabId: chrome.devtools.inspectedWindow.tabId
113
52
  });
114
- document.getElementById("optin").addEventListener("click", () => {
115
- chrome.tabs.sendMessage(chrome.devtools.inspectedWindow.tabId, {
116
- type: "optIn",
117
- });
53
+ backgroundPageConnection.onMessage.addListener(function(message) {
54
+ if (message.type === "report") {
55
+ const td = getRowForInstance(message.instanceId);
56
+ td[0].innerText = `${message.frameId}`;
57
+ td[1].innerText = message.url;
58
+ td[2].innerText = message.state.lifecycle;
59
+ td[3].innerText = message.state.prehideOn ? "yes" : "no";
60
+ td[4].innerText = `${message.state.findCmpAttempts}`;
61
+ td[5].innerText = message.state.detectedCmps.join(", ");
62
+ td[6].innerText = message.state.detectedPopups.join(", ");
63
+ } else if (message.type === "instanceTerminated") {
64
+ document.getElementById(`instance-${message.instanceId}`)?.classList.add("dead");
65
+ }
118
66
  });
119
- document.getElementById("optout").addEventListener("click", () => {
120
- chrome.tabs.sendMessage(chrome.devtools.inspectedWindow.tabId, {
121
- type: "optOut",
122
- });
67
+ backgroundPageConnection.onDisconnect.addListener(() => {
68
+ reconnect();
123
69
  });
124
- function onConfigUpdated(config) {
125
- const modeOptions = document.querySelectorAll("#mode > option");
126
- switch (config.autoAction) {
127
- case "optIn":
128
- modeOptions[1].selected = true;
129
- break;
130
- case "optOut":
131
- modeOptions[2].selected = true;
132
- break;
133
- default:
134
- modeOptions[0].selected = true;
135
- }
70
+ return backgroundPageConnection;
71
+ }
72
+ var clearStorageCheckbox = document.querySelector("#clear-storage");
73
+ var clearPanel = () => {
74
+ const tbody = document.querySelector("tbody");
75
+ while (tbody.firstChild) {
76
+ tbody.removeChild(tbody.firstChild);
136
77
  }
137
- chrome.storage.local.onChanged.addListener((changes) => {
138
- if (changes.config) {
139
- onConfigUpdated(changes.config.newValue);
78
+ };
79
+ document.getElementById("clear").addEventListener("click", clearPanel);
80
+ document.getElementById("reload").addEventListener("click", async () => {
81
+ if (clearStorageCheckbox.checked) {
82
+ const tab = await chrome.tabs.get(chrome.devtools.inspectedWindow.tabId);
83
+ const url = new URL(tab.url);
84
+ await chrome.browsingData.remove(
85
+ {
86
+ origins: [url.origin]
87
+ },
88
+ {
89
+ cookies: true,
90
+ localStorage: true,
91
+ indexedDB: true
140
92
  }
93
+ );
94
+ }
95
+ clearPanel();
96
+ chrome.devtools.inspectedWindow.reload({});
97
+ });
98
+ document.getElementById("mode").addEventListener("change", async () => {
99
+ const storedConfig = await storageGet("config");
100
+ let autoAction = document.querySelector("#mode > option:checked").getAttribute("data-autoaction");
101
+ if (autoAction === "null") {
102
+ autoAction = null;
103
+ }
104
+ storedConfig.autoAction = autoAction;
105
+ storageSet({
106
+ config: storedConfig
141
107
  });
142
- (async () => {
143
- const config = await storageGet("config");
144
- onConfigUpdated(config);
145
- })();
146
- reconnect();
147
-
108
+ });
109
+ document.getElementById("optin").addEventListener("click", () => {
110
+ chrome.tabs.sendMessage(chrome.devtools.inspectedWindow.tabId, {
111
+ type: "optIn"
112
+ });
113
+ });
114
+ document.getElementById("optout").addEventListener("click", () => {
115
+ chrome.tabs.sendMessage(chrome.devtools.inspectedWindow.tabId, {
116
+ type: "optOut"
117
+ });
118
+ });
119
+ function onConfigUpdated(config) {
120
+ const modeOptions = document.querySelectorAll("#mode > option");
121
+ switch (config.autoAction) {
122
+ case "optIn":
123
+ modeOptions[1].selected = true;
124
+ break;
125
+ case "optOut":
126
+ modeOptions[2].selected = true;
127
+ break;
128
+ default:
129
+ modeOptions[0].selected = true;
130
+ }
131
+ }
132
+ chrome.storage.local.onChanged.addListener((changes) => {
133
+ if (changes.config) {
134
+ onConfigUpdated(changes.config.newValue);
135
+ }
136
+ });
137
+ (async () => {
138
+ const config = await storageGet("config");
139
+ onConfigUpdated(config);
140
+ })();
141
+ reconnect();
148
142
  })();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Autoconsent",
4
- "version": "2023.6.22",
4
+ "version": "2023.7.13",
5
5
  "background": {
6
6
  "service_worker": "background.bundle.js"
7
7
  },
@@ -1,180 +1,169 @@
1
- (function () {
2
- 'use strict';
3
-
4
- const manifestVersion = chrome.runtime.getManifest().manifest_version;
5
- // Storage abstraction: MV2 keeps everything in memory, MV3 uses chrome.storage
6
- const storage = {};
7
- async function storageSet(obj) {
8
- if (manifestVersion === 2) {
9
- Object.assign(storage, obj);
10
- return;
11
- }
12
- return chrome.storage.local.set(obj);
1
+ (() => {
2
+ // addon/mv-compat.ts
3
+ var manifestVersion = chrome.runtime.getManifest().manifest_version;
4
+ var storage = {};
5
+ async function storageSet(obj) {
6
+ if (manifestVersion === 2) {
7
+ Object.assign(storage, obj);
8
+ return;
9
+ }
10
+ return chrome.storage.local.set(obj);
11
+ }
12
+ async function storageGet(key) {
13
+ if (key === null) {
14
+ if (manifestVersion === 2) {
15
+ return storage;
16
+ }
17
+ return await chrome.storage.local.get(null);
13
18
  }
14
- async function storageGet(key) {
15
- if (key === null) {
16
- if (manifestVersion === 2) {
17
- return storage;
18
- }
19
- return await chrome.storage.local.get(null);
20
- }
21
- if (manifestVersion === 2) {
22
- return storage[key];
23
- }
24
- return (await chrome.storage.local.get(key))?.[key];
19
+ if (manifestVersion === 2) {
20
+ return storage[key];
25
21
  }
26
- async function storageRemove(key) {
27
- if (manifestVersion === 2) {
28
- delete storage[key];
29
- return;
30
- }
31
- return chrome.storage.local.remove(key);
22
+ return (await chrome.storage.local.get(key))?.[key];
23
+ }
24
+ async function storageRemove(key) {
25
+ if (manifestVersion === 2) {
26
+ delete storage[key];
27
+ return;
32
28
  }
29
+ return chrome.storage.local.remove(key);
30
+ }
33
31
 
34
- async function showOptOutStatus(tabId, status, cmp = '') {
35
- let title = "";
36
- let icon = "icons/cookie-idle.png";
37
- if (status === "success") {
38
- title = `Opt out successful! (${cmp})`;
39
- icon = "icons/party.png";
40
- }
41
- else if (status === "complete") {
42
- title = `Opt out complete! (${cmp})`;
43
- icon = "icons/tick.png";
44
- }
45
- else if (status === "working") {
46
- title = `Processing... (${cmp})`;
47
- icon = "icons/cog.png";
48
- }
49
- else if (status === "verified") {
50
- title = `Verified (${cmp})`;
51
- icon = "icons/verified.png";
52
- }
53
- else if (status === "idle") {
54
- title = "Idle";
55
- icon = "icons/cookie-idle.png";
56
- }
57
- else if (status === "available") {
58
- title = `Click to opt out (${cmp})`;
59
- icon = "icons/cookie.png";
60
- }
61
- const action = chrome.action || chrome.pageAction;
62
- if (chrome.pageAction) {
63
- chrome.pageAction.show(tabId);
64
- }
65
- await action.setTitle({
66
- tabId,
67
- title,
68
- });
69
- await action.setIcon({
70
- tabId,
71
- path: icon,
72
- });
32
+ // lib/config.ts
33
+ var enableLogs = false;
34
+
35
+ // addon/utils.ts
36
+ async function showOptOutStatus(tabId, status, cmp = "") {
37
+ let title = "";
38
+ let icon = "icons/cookie-idle.png";
39
+ if (status === "success") {
40
+ title = `Opt out successful! (${cmp})`;
41
+ icon = "icons/party.png";
42
+ } else if (status === "complete") {
43
+ title = `Opt out complete! (${cmp})`;
44
+ icon = "icons/tick.png";
45
+ } else if (status === "working") {
46
+ title = `Processing... (${cmp})`;
47
+ icon = "icons/cog.png";
48
+ } else if (status === "verified") {
49
+ title = `Verified (${cmp})`;
50
+ icon = "icons/verified.png";
51
+ } else if (status === "idle") {
52
+ title = "Idle";
53
+ icon = "icons/cookie-idle.png";
54
+ } else if (status === "available") {
55
+ title = `Click to opt out (${cmp})`;
56
+ icon = "icons/cookie.png";
57
+ }
58
+ enableLogs && console.log("Setting action state to", status);
59
+ const action = chrome.action || chrome.pageAction;
60
+ if (chrome.pageAction) {
61
+ chrome.pageAction.show(tabId);
73
62
  }
63
+ await action.setTitle({
64
+ tabId,
65
+ title
66
+ });
67
+ await action.setIcon({
68
+ tabId,
69
+ path: icon
70
+ });
71
+ }
74
72
 
75
- async function init() {
76
- const autoconsentConfig = await storageGet('config');
77
- const enabledCheckbox = document.querySelector('input#enabled');
78
- const optOutRadio = document.querySelector('input#optout');
79
- const optInRadio = document.querySelector('input#optin');
80
- const promptRadio = document.querySelector('input#prompt');
81
- const prehideOnRadio = document.querySelector('input#prehide-on');
82
- const prehideOffRadio = document.querySelector('input#prehide-off');
83
- const cosmeticOnRadio = document.querySelector('input#cosmetic-on');
84
- const cosmeticOffRadio = document.querySelector('input#cosmetic-off');
85
- const retriesInput = document.querySelector('input#retries');
86
- const ruleReloadButton = document.querySelector('#reload');
87
- // enable proceed button when necessary
88
- const [currentTab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
89
- const tabId = currentTab.id;
90
- const detectedKey = `detected${tabId}`;
91
- console.log('detectedKey', detectedKey);
92
- const frameId = await storageGet(detectedKey);
93
- console.log('frameId', frameId, typeof frameId);
94
- if (typeof frameId === 'number') {
95
- const proceedButton = document.createElement('button');
96
- proceedButton.innerText = 'Manage popup';
97
- proceedButton.id = 'proceed';
98
- proceedButton.addEventListener('click', () => {
99
- storageRemove(detectedKey);
100
- showOptOutStatus(tabId, "working");
101
- chrome.tabs.sendMessage(tabId, {
102
- type: "optOut",
103
- }, {
104
- frameId,
105
- });
106
- proceedButton.remove();
107
- window.close();
108
- });
109
- document.body.prepend(proceedButton);
110
- }
111
- // set form initial values
112
- enabledCheckbox.checked = autoconsentConfig.enabled;
113
- retriesInput.value = autoconsentConfig.detectRetries.toString();
114
- if (autoconsentConfig.autoAction === 'optIn') {
115
- optInRadio.checked = true;
116
- }
117
- else if (autoconsentConfig.autoAction === 'optOut') {
118
- optOutRadio.checked = true;
119
- }
120
- else {
121
- promptRadio.checked = true;
122
- }
123
- if (autoconsentConfig.enablePrehide) {
124
- prehideOnRadio.checked = true;
125
- }
126
- else {
127
- prehideOffRadio.checked = true;
128
- }
129
- if (autoconsentConfig.enableCosmeticRules) {
130
- cosmeticOnRadio.checked = true;
131
- }
132
- else {
133
- cosmeticOffRadio.checked = true;
134
- }
135
- // set form event listeners
136
- enabledCheckbox.addEventListener('change', () => {
137
- autoconsentConfig.enabled = enabledCheckbox.checked;
138
- storageSet({ config: autoconsentConfig });
139
- });
140
- retriesInput.addEventListener('change', () => {
141
- autoconsentConfig.detectRetries = parseInt(retriesInput.value, 10);
142
- storageSet({ config: autoconsentConfig });
143
- });
144
- function modeChange() {
145
- if (optInRadio.checked) {
146
- autoconsentConfig.autoAction = 'optIn';
147
- }
148
- else if (optOutRadio.checked) {
149
- autoconsentConfig.autoAction = 'optOut';
150
- }
151
- else {
152
- autoconsentConfig.autoAction = null;
153
- }
154
- storageSet({ config: autoconsentConfig });
155
- }
156
- optInRadio.addEventListener('change', modeChange);
157
- optOutRadio.addEventListener('change', modeChange);
158
- promptRadio.addEventListener('change', modeChange);
159
- function prehideChange() {
160
- autoconsentConfig.enablePrehide = prehideOnRadio.checked;
161
- storageSet({ config: autoconsentConfig });
162
- }
163
- prehideOnRadio.addEventListener('change', prehideChange);
164
- prehideOffRadio.addEventListener('change', prehideChange);
165
- function cosmeticChange() {
166
- autoconsentConfig.enableCosmeticRules = cosmeticOnRadio.checked;
167
- storageSet({ config: autoconsentConfig });
168
- }
169
- cosmeticOnRadio.addEventListener('change', cosmeticChange);
170
- cosmeticOffRadio.addEventListener('change', cosmeticChange);
171
- ruleReloadButton.addEventListener('click', async () => {
172
- const res = await fetch("./rules.json");
173
- storageSet({
174
- rules: await res.json(),
175
- });
73
+ // addon/popup.ts
74
+ async function init() {
75
+ const autoconsentConfig = await storageGet("config");
76
+ const enabledCheckbox = document.querySelector("input#enabled");
77
+ const optOutRadio = document.querySelector("input#optout");
78
+ const optInRadio = document.querySelector("input#optin");
79
+ const promptRadio = document.querySelector("input#prompt");
80
+ const prehideOnRadio = document.querySelector("input#prehide-on");
81
+ const prehideOffRadio = document.querySelector("input#prehide-off");
82
+ const cosmeticOnRadio = document.querySelector("input#cosmetic-on");
83
+ const cosmeticOffRadio = document.querySelector("input#cosmetic-off");
84
+ const retriesInput = document.querySelector("input#retries");
85
+ const ruleReloadButton = document.querySelector("#reload");
86
+ const [currentTab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
87
+ const tabId = currentTab.id;
88
+ const detectedKey = `detected${tabId}`;
89
+ console.log("detectedKey", detectedKey);
90
+ const frameId = await storageGet(detectedKey);
91
+ console.log("frameId", frameId, typeof frameId);
92
+ if (typeof frameId === "number") {
93
+ const proceedButton = document.createElement("button");
94
+ proceedButton.innerText = "Manage popup";
95
+ proceedButton.id = "proceed";
96
+ proceedButton.addEventListener("click", () => {
97
+ storageRemove(detectedKey);
98
+ showOptOutStatus(tabId, "working");
99
+ chrome.tabs.sendMessage(tabId, {
100
+ type: "optOut"
101
+ }, {
102
+ frameId
176
103
  });
104
+ proceedButton.remove();
105
+ window.close();
106
+ });
107
+ document.body.prepend(proceedButton);
177
108
  }
178
- init();
179
-
109
+ enabledCheckbox.checked = autoconsentConfig.enabled;
110
+ retriesInput.value = autoconsentConfig.detectRetries.toString();
111
+ if (autoconsentConfig.autoAction === "optIn") {
112
+ optInRadio.checked = true;
113
+ } else if (autoconsentConfig.autoAction === "optOut") {
114
+ optOutRadio.checked = true;
115
+ } else {
116
+ promptRadio.checked = true;
117
+ }
118
+ if (autoconsentConfig.enablePrehide) {
119
+ prehideOnRadio.checked = true;
120
+ } else {
121
+ prehideOffRadio.checked = true;
122
+ }
123
+ if (autoconsentConfig.enableCosmeticRules) {
124
+ cosmeticOnRadio.checked = true;
125
+ } else {
126
+ cosmeticOffRadio.checked = true;
127
+ }
128
+ enabledCheckbox.addEventListener("change", () => {
129
+ autoconsentConfig.enabled = enabledCheckbox.checked;
130
+ storageSet({ config: autoconsentConfig });
131
+ });
132
+ retriesInput.addEventListener("change", () => {
133
+ autoconsentConfig.detectRetries = parseInt(retriesInput.value, 10);
134
+ storageSet({ config: autoconsentConfig });
135
+ });
136
+ function modeChange() {
137
+ if (optInRadio.checked) {
138
+ autoconsentConfig.autoAction = "optIn";
139
+ } else if (optOutRadio.checked) {
140
+ autoconsentConfig.autoAction = "optOut";
141
+ } else {
142
+ autoconsentConfig.autoAction = null;
143
+ }
144
+ storageSet({ config: autoconsentConfig });
145
+ }
146
+ optInRadio.addEventListener("change", modeChange);
147
+ optOutRadio.addEventListener("change", modeChange);
148
+ promptRadio.addEventListener("change", modeChange);
149
+ function prehideChange() {
150
+ autoconsentConfig.enablePrehide = prehideOnRadio.checked;
151
+ storageSet({ config: autoconsentConfig });
152
+ }
153
+ prehideOnRadio.addEventListener("change", prehideChange);
154
+ prehideOffRadio.addEventListener("change", prehideChange);
155
+ function cosmeticChange() {
156
+ autoconsentConfig.enableCosmeticRules = cosmeticOnRadio.checked;
157
+ storageSet({ config: autoconsentConfig });
158
+ }
159
+ cosmeticOnRadio.addEventListener("change", cosmeticChange);
160
+ cosmeticOffRadio.addEventListener("change", cosmeticChange);
161
+ ruleReloadButton.addEventListener("click", async () => {
162
+ const res = await fetch("./rules.json");
163
+ storageSet({
164
+ rules: await res.json()
165
+ });
166
+ });
167
+ }
168
+ init();
180
169
  })();