-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
53 lines (45 loc) · 1.44 KB
/
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
// Get the current tab URL
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab = tabs[0];
var url = tab.url;
// Get the notes from storage
chrome.storage.sync.get(url, function(data) {
var notes = data[url];
var notesDiv = document.getElementById("notes");
// Display the notes in the popup
if (notes && notes != "") {
notesDiv.innerHTML = notes;
} else {
notesDiv.placeholder = "";
}
});
});
// Save the notes to storage when the save button is clicked
var saveButton = document.getElementById("save");
var infoDiv = document.getElementById("info");
saveButton.addEventListener("click", function() {
// Get the current tab URL
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab = tabs[0];
var url = tab.url;
// Check if the URL starts with https://www.twitch.tv/
var prefix = "https://www.twitch.tv/";
var isTwitch = url.startsWith(prefix);
if(isTwitch) {
// Get the notes from the popup
var notesDiv = document.getElementById("notes");
var notes = notesDiv.innerHTML;
// Save the notes to storage
chrome.storage.sync.set({[url]: notes}, function() {
//Info sucess
infoDiv.innerHTML = "Note saved!";
infoDiv.style.color = "green";
});
}
else {
//Info fail
infoDiv.innerHTML = "You are not on twitch! Note is NOT saved";
infoDiv.style.color = "red";
}
});
});