-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotification_popup.js
98 lines (92 loc) · 3.13 KB
/
notification_popup.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
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
var text = document.getElementById('react-root');
var popupPart1 = `
<div id='myModal' class='modal'>
<div class='modal-content'>
<span class="close">×</span>
<h2 id="popTitle">Before you Sign Up</h2>
<div id="message">
<p>`
var popupPart2 = `</p>
</div>
<div id="footer">
<span>Nevermind</span>
<span id="middle" class="align-right">Sign up</span>
<span class="align-right">Sign up and remind me next time</span>
</div>
</div>
</div>`
text.insertAdjacentHTML('beforeend', popupPart1 + "Filler" + popupPart2);
function getElementByContents(type, contents){
var tags = document.getElementsByTagName(type);
var searchText = contents;
var found;
for (var i = 0; i < aTags.length; i++) {
if (tags[i].textContent == searchText) {
found = tags[i];
break;
}
}
}
function updateModal(innerText){
var elem = document.getElementById('myModal');
elem.parentNode.removeChild(elem);
var text = document.getElementById('react-root');
text.insertAdjacentHTML('beforeend', popupPart1 + innerText + popupPart2);
}
window.onload = function(){
signUpElement.onclick = function(event) {
console.log("Clicked!")
//Check state of plugin to decide whether to display the pop-up or not.
chrome.storage.sync.get('state', function(data) {
if (data.state === 'on') {
modal.style.display= "block";
event.stopPropagation();
}
});
}
var modal = document.getElementById('myModal');
var span = document.getElementsByClassName("close")[0];
span.onclick = function() {
//Check state of plugin to decide whether to display the pop-up or not.
chrome.storage.sync.get('state', function(data) {
if (data.state === 'on') {
modal.style.display = "none";
}
});
}
window.onclick = function(event) {
if (event.target == modal) {
//Check state of plugin to decide whether to display the pop-up or not.
chrome.storage.sync.get('state', function(data) {
if (data.state === 'on') {
modal.style.display = "none";
}
});
}
}
}
document.addEventListener('click', function(e) {
event = e || window.event;
var target = e.target || e.srcElement;
var tag = target.textContent;
console.log("Got click on tag " + tag);
var domain = window.location.host;
console.log("Got host " + domain)
//Check state of plugin to decide whether to display the pop-up or not.
chrome.storage.sync.get('state', function(data) {
if (data.state === 'on') {
getEulaSectionForTag(domain, tag, function(eulaText){
if(eulaText != null){
//there is a eula text section! Good.
console.log("Got EULA for tag " + tag + " on domain " + domain);
event.stopPropagation();
updateModal(eulaText);
var modal = document.getElementById('myModal');
modal.style.display="block"
} else {
console.log("Unable to find EULA for tag " + tag + " on domain " + domain);
}
});
}
});
}, false);