-
Notifications
You must be signed in to change notification settings - Fork 4
/
content.js
73 lines (64 loc) · 2.07 KB
/
content.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
let popup;
function createDiv(text) {
if (text) {
popup = document.createElement('div');
popup.style.width = 'auto';
popup.style.height = 'auto';
popup.style.background = 'rgba(0, 0, 0, 0.7)';
popup.style.color = 'white';
popup.style.padding = '25px';
popup.style.borderRadius = '5px';
popup.style.position = 'fixed';
popup.style.top = '50%';
popup.style.left = '50%';
popup.style.transform = 'translate(-50%, -50%)';
popup.style.zIndex = '9999';
const closeButton = document.createElement("button");
closeButton.innerText = "X";
closeButton.style.position = "absolute";
closeButton.style.top = "0";
closeButton.style.color = 'white';
closeButton.style.right = "0";
closeButton.style.border = "none";
closeButton.style.background = "none";
closeButton.style.padding = "10";
closeButton.style.margin = "10";
closeButton.style.fontSize = "18px";
closeButton.style.cursor = "pointer";
closeButton.onclick = removePopup;
const content = document.createElement("div");
content.id = "sayitbetter_popup";
content.style.whiteSpace = "pre";
content.innerText = text;
// popup.appendChild(closeButton);
popup.appendChild(content);
document.body.appendChild(popup);
// Remove the div when clicked
popup.addEventListener('click', () => {
removePopup();
});
}
}
function removePopup() {
if (popup) {
popup.remove();
popup = null;
}
}
function updateDiv(text) {
if (text) {
const newDiv = document.getElementById('sayitbetter_popup');
newDiv.textContent = text;
setTimeout(() => {
removePopup();
}, "1000");
}
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'createDiv') {
createDiv(message.text);
}
if (message.action === 'updateDiv') {
updateDiv(message.text);
}
});