-
Notifications
You must be signed in to change notification settings - Fork 5
/
check_for_link.js
69 lines (58 loc) · 2.12 KB
/
check_for_link.js
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
/**
* Content script to detect CCPA opt-out links. Searches the page for
* such a link, then displays a notification if found.
*/
// Add compatibility for Chromuim-based browsers
var browser = browser || chrome;
/**
* Function to display notification
*/
function displayPopup() {
// Create popup
var popup = document.createElement('div');
popup.setAttribute('id', 'CCPAPopup');
// Create popup body
var popupBody = document.createElement('div');
popupBody.setAttribute('id', 'CCPABody');
popupBody.innerHTML = '<b>This website sells your personal information. Opt out below.</b></br>';
popup.appendChild(popupBody);
// Create 'X' button
var close = document.createElement('span');
close.innerHTML = 'x';
close.setAttribute('id', 'CCPAClose');
popup.appendChild(close);
// Create more info link
var moreInfo = document.createElement('a');
moreInfo.setAttribute('id', 'CCPAMoreInfo');
moreInfo.setAttribute('href', browser.runtime.getManifest().homepage_url);
moreInfo.setAttribute('target', '_blank');
moreInfo.innerHTML = 'More Info';
popupBody.appendChild(moreInfo);
// Create button
var button = document.createElement('button');
button.setAttribute('id', 'CCPAButton');
button.innerHTML = "Don't Sell My Personal Information";
popup.appendChild(button);
// Add popup to document
document.getElementsByTagName('BODY')[0].appendChild(popup);
}
// Search page elements for CCPA opt-out link
var pageElements = document.getElementsByTagName('*');
var linkDetected = false;
var linkReference = null;
for (var i = 0; i < pageElements.length; i++) {
// If opt-out link is found, display notification
if (pageElements[i].innerHTML.toLowerCase().search('do not sell') != -1
|| pageElements[i].innerHTML.toLowerCase().search('don\'t sell') != -1) {
linkReference = pageElements[i];
linkDetected = true;
}
}
// Send search result to background script
if (linkDetected) {
displayPopup();
browser.runtime.sendMessage({linkDetected: "yes"});
}
else {
browser.runtime.sendMessage({linkDetected: "no"});
}