-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
37 lines (31 loc) · 1.13 KB
/
popup.js
File metadata and controls
37 lines (31 loc) · 1.13 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
window.onload = function() {
const modifyButton = document.getElementById("modifyButton");
if (modifyButton) {
modifyButton.addEventListener("click", modifyOrReload);
}
displayCounts();
}
chrome.storage.onChanged.addListener(function(changes, namespace) {
for (let key in changes) {
let storageChange = changes[key];
if (key === 'wordCount' || key === 'charCount') {
displayCounts();
}
}
});
function displayCounts() {
chrome.storage.local.get(['wordCount', 'charCount'], function(data) {
document.getElementById('wordCount').textContent = "Word Count: " + (data.wordCount || 0);
document.getElementById('charCount').textContent = "Char Count: " + (data.charCount || 0);
});
}
function modifyOrReload() {
const modifyButton = document.getElementById("modifyButton");
if (modifyButton.textContent === "Modify Text") {
modifyButton.textContent = "Refresh Page";
chrome.runtime.sendMessage({action: "modify"});
} else {
modifyButton.textContent = "Modify Text";
chrome.runtime.sendMessage({action: "reload"});
}
}