-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
361 lines (347 loc) · 11.8 KB
/
contentScript.js
File metadata and controls
361 lines (347 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
let jsonData = {};
// let jsonData = {
// warnings: [
// {
// warning_number: 1,
// category: "Online Services",
// icon_tag: "third-party-services",
// description:
// "This Product requires an internet connection and may have online services and features that collect and store data about you. Make sure to review the privacy policy for more information on how your data is used and protected.",
// },
// {
// warning_number: 2,
// category: "Data Collection",
// icon_tag: "data-collection",
// description:
// "Ubisoft may collect and store data about you in relation to your use of the Product, such as your connection information and compatible device data. Your privacy is important to Ubisoft, but be cautious and review their privacy policy to understand how your data is handled.",
// },
// {
// warning_number: 3,
// category: "Third-party Analytics",
// icon_tag: "data-usage-analytics",
// description:
// "Ubisoft uses third-party analytics tools to collect information about your gaming habits and use of the Product. This may include personal data such as your device identifiers and settings, game scores, and feature usage. Make sure you review their privacy policy for more details.",
// },
// {
// warning_number: 4,
// category: "Targeted Advertising",
// icon_tag: "behavioral-advertising",
// description:
// "The Product may display advertisements and collect information for targeted advertising purposes. This may include data such as your age, gender, and the ads you interact with. Read Ubisoft's privacy policy to understand how this information is used and how to opt-out.",
// },
// {
// warning_number: 5,
// category: "Unauthorized Program Detection",
// icon_tag: "access-control",
// description:
// "The Product may monitor your hardware for unauthorized third-party programs. If detected, information about the program and your account may be sent to Ubisoft. Your access to the Product may be terminated based on the detection results.",
// },
// ],
// };
// let jsonData = {
// eula_severity_rating: [
// {
// overall_severity_of_the_eula: "Low",
// severity_safety_rating: "80%",
// },
// ],
// warnings: [
// {
// warning_number: 1,
// category: "Third-party Sharing",
// icon_tag: "third-party-sharing",
// severity_indicator: "red",
// description:
// "This application shares user data with third-party entities. Understand the purposes of such sharing, the entities involved, and review the privacy policy to ensure your data is handled responsibly and securely.",
// },
// {
// warning_number: 2,
// category: "Data Usage Analytics",
// icon_tag: "data-usage-analytics",
// severity_indicator: "yellow",
// description:
// "The application collects and analyzes user data for the purpose of improving its products and services. Review the privacy policy to understand the types of data collected and how it is used.",
// },
// {
// warning_number: 3,
// category: "Personal Data Access",
// icon_tag: "personal-data-access",
// severity_indicator: "red",
// description:
// "This application has the capability to access a wide range of personal data, including images, SMS messages, and other sensitive information stored on the device. Exercise caution and review the privacy settings before granting access.",
// },
// {
// warning_number: 4,
// category: "Terms of Service",
// icon_tag: "terms-of-service",
// severity_indicator: "green",
// description:
// "By installing or using the Product, you agree to abide by the terms of service set forth by the developer. Review the terms of service to understand your rights and responsibilities while using the application.",
// },
// ],
// };
//#####---Function to Extract All Text Content from The Page---#####--------------------------------------------------------------------
function extractAllText() {
const allText = [];
// Function to check if an element is visible to the user
function isVisible(element) {
const style = getComputedStyle(element);
return style.display !== "none" && style.visibility !== "hidden";
}
// Traverse all text nodes in the DOM tree and collect their visible text content
function traverse(node) {
if (node.nodeType === Node.TEXT_NODE) {
// Check if the parent element is visible
if (node.parentElement && isVisible(node.parentElement)) {
allText.push(node.textContent);
}
} else if (node.nodeType === Node.ELEMENT_NODE && isVisible(node)) {
// If it's not a text node, recursively traverse its child nodes
for (const childNode of node.childNodes) {
traverse(childNode);
}
}
}
// Start traversal from the <body> element
traverse(document.body);
// Combine all collected visible text into a single string
return allText.join(" ");
}
//---------------------------------------------------Ending---of---Function---------------------------------------------------------------------------
//
//
//
//
//#####---Function to Fetch and Parse The Privacy Sensitive Words List File [Hard-Coded]---#####------------------------------------------------------
async function fetchWordList() {
try {
// Hardcoded wordlist
const privacySensitiveWordslist = [
"access",
"aggregate",
"connect",
"consolidate",
"disclose",
"display",
"maintain",
"mare",
"investigate",
"post",
"reserve",
"review",
"allow",
"contact",
"enforce",
"maximize",
"prevent",
"share",
"apply",
"contract",
"ensure",
"minimize",
"prohibit",
"specify",
"avoid",
"customize",
"exchange",
"monitor",
"protect",
"store",
"block",
"deny",
"help",
"notify",
"provide",
"update",
"change",
"destroy",
"honor",
"obligate",
"recommend",
"urge",
"choose",
"disallow",
"imply",
"opt-in",
"request",
"use",
"collect",
"comply",
"discipline",
"disclaim",
"inform",
"limit",
"opt-out",
"require",
"verify",
"personal",
"ip address",
"third-party",
"publish",
"consent",
"process",
"create",
"delete",
"retention",
"registration",
"mobile",
"phone",
"speech recognition",
"cloud",
"service",
"jurisdictions",
"password",
"protection",
"information",
"location",
"real-time",
"upload",
"download",
"shared",
"first-party",
"automatically",
"usage",
"trend",
"log",
"mapping",
"advertising",
"track",
"payment",
"chat",
"history",
"record",
"anonymous",
"biometric",
"cookie",
"gdpr",
"correction",
"child",
"age",
"legal",
"erasure",
"deletion",
"withdraw",
"retention period",
"security",
"sell",
"monetization",
"transfer",
"under-age",
"accountability",
"agree",
"disagree",
];
return privacySensitiveWordslist
.map((word) => word.trim())
.filter((word) => word !== "");
} catch (error) {
console.error("Failed to fetch or parse the wordlist:", error);
return [];
}
}
//---------------------------------------------------Ending---of---Function----------------------------------------------------------------------------
//
//
//
//#####---Function to send a message to the popup with jsonData---#####--------------------------------------------------------------------------------
function sendMessageToPopup(data) {
// console.log("Sending data to popup:", data);
chrome.runtime.sendMessage({ message: "show_data", data: data });
}
//---------------------------------------------------Ending---of---Function----------------------------------------------------------------------------
//
//
//
//#####---Calling The Cloud Function---#####-----------------------------------------------------------------------------------------------------------
function callCloudFunction(allPageText) {
console.log("Function Called...\n");
const cloudFunctionUrl =
"https://eula-analyzer-for-publication-761034970962.asia-southeast1.run.app";
return fetch(cloudFunctionUrl, {
method: "POST",
headers: {
"Content-Type": "text/plain",
},
body: allPageText, // Send the plaintext directly
})
.then((response) => {
// Check if the response status is OK (200)
if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
}
// Read the response text
return response.text();
})
.then((data) => {
// Handle the response from the Cloud Function
console.log("Cloud Function Response: ", data);
// Assuming the returned data is in JSON format, parse it
try {
jsonData = JSON.parse(data);
} catch (error) {
console.error("Error parsing Cloud Function response:", error);
}
})
.catch((error) => {
console.error("Error fetching data from Cloud Function:", error);
throw error; // rethrow the error for handling elsewhere if needed
});
}
//---------------------------------------------------Ending---of---Function----------------------------------------------------------------------------
//
//
//
// Define a callback function to be called when highlighting is complete
function highlightingCallback() {
// Send a message to the popup after highlighting is complete
// setTimeout(function () {
// sendMessageToPopup(jsonData);
// }, 5000);
sendMessageToPopup(jsonData);
}
//
//
//
//
//#####---Function for Highlighting The Privacy Sensitive Words---#####---------------------------------------------------------------
async function highlightWords() {
const predefinedWords = await fetchWordList();
const allPageText = extractAllText();
const elements = document.querySelectorAll("body *");
elements.forEach((element) => {
const node = element.firstChild;
if (node !== null && node.nodeType === Node.TEXT_NODE) {
const text = node.nodeValue;
const replacedText = predefinedWords.reduce((acc, word) => {
const regex = new RegExp(`\\b${word}\\b`, "gi");
return acc.replace(
regex,
`<span style="background-color: yellow">${word}</span>`
);
}, text);
if (replacedText !== text) {
const newNode = document.createElement("span");
newNode.innerHTML = replacedText;
element.replaceChild(newNode, node);
}
}
});
// Call the Cloud Function and wait for the response
try {
await callCloudFunction(allPageText);
} catch (error) {
// Handle errors
console.error("Error processing data:", error);
}
}
//---------------------------------------------------Ending---of---Function-----------------------------------------------------------
//
//
//
// Message listener to trigger highlighting and send jsonData when a message is received
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.message === "highlight_words") {
highlightWords().then(highlightingCallback);
return true;
}
});