-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
56 lines (46 loc) · 1.89 KB
/
popup.js
File metadata and controls
56 lines (46 loc) · 1.89 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
// Add an event listener for when the DOM content is loaded
document.addEventListener('DOMContentLoaded', function() {
updateUI();
// Add an event listener to the element with the id 'reset' for when it is clicked
document.getElementById('reset').addEventListener('click', function() {
// Send a message to the chrome runtime to reset the count
chrome.runtime.sendMessage({reset: "yes"});
updateUI();
});
// Add an event listener to the save changes button
document.getElementById('saveChanges').addEventListener('click', function() {
var target = document.getElementById('targetSelect').value;
chrome.storage.local.set({ target: target }, function() {
// Close the modal
$('#settingsModal').modal('hide');
// Update the UI elements
updateUI();
});
});
document.getElementById('cogwheel').addEventListener('click', function() {
// show the settings modal
document.getElementById('settingsModal').style.display = "block";
});
// Add an event listener to the close button
document.getElementById('close').addEventListener('click', function() {
// hide the settings modal
document.getElementById('settingsModal').style.display = "none";
});
});
// Add a listener for messages from the chrome runtime
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
// If the request is to increment the count
if (request.increment == "yes") {
updateUI();
}
});
function updateUI() {
chrome.storage.local.get(['count', 'target'], function(data) {
var count = data.count || 0;
var target = data.target || 10000;
var progressBar = document.getElementById('progressBar').firstElementChild;
var countDiv = document.getElementById('count').firstElementChild;
progressBar.style.width = (count / target) * 100 + "%";
countDiv.innerText = "Tweets left: " + (target-count) + "/" + target;
});
}