-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindexDev.js
89 lines (74 loc) · 2.53 KB
/
indexDev.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
document.addEventListener('DOMContentLoaded', () => {
const textArea = document.querySelector("#note");
const settings = document.querySelector("#settings")
const saveBtn = document.querySelector("#saveBtn");
const clearBtn = document.querySelector("#clearBtn")
const settingsBtn = document.querySelector("#settingsBtn");
const statusMsg = document.querySelector("status");
// Get the current tab's URL
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
const url = tabs[0].url;
// Check if there's a note saved for this URL
const note = localStorage.getItem(url);
// If a note was found, display it in the text area
if (note) {
// const textArea = document.querySelector("#note");
textArea.value = note;
}
});
saveBtn.addEventListener('click', () => {
const text = textArea.value;
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
console.log('Saving note...');
// Get the URL of the current tab
const url = tabs[0].url;
localStorage.setItem(url, text);
console.log('Note saved');
});
})
clearBtn.onclick = () => {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const url = tabs[0].url;
localStorage.removeItem(url);
textArea.value = ''
console.log('Note cleared')
})
}
settingsBtn.addEventListener('click', () => {
switch (settings.style.display) {
// Settings menu is toggled "OFF"
case "none":
settings.style.display = "block"
note.style.display = "none"
break;
// Settings menu is toggled "ON"
case "block":
settings.style.display = "none"
note.style.display = "initial"
break;
default:
settings.style.display = "none"
note.style.display = "initial"
break;
}
})
// Add event listeners to the buttons
saveBtn.addEventListener("click", showSavedMsg);
clearBtn.addEventListener("click", showClearedMsg);
function showSavedMsg() {
statusMsg.style.display = "block";
statusMsg.innerText = 'Saved'
setTimeout(() => {
statusMsg.style.display = "none";
statusMsg.innerText = ''
}, 2000);
}
function showClearedMsg() {
statusMsg.style.display = "block";
statusMsg.innerText = 'Cleared'
setTimeout(() => {
statusMsg.style.display = "none";
statusMsg.innerText = ''
}, 2000);
}
})