This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
72 lines (60 loc) · 1.79 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function updatePreferences() {
const rightSidebar = document.getElementById("right-sidebar");
const floatingActionBar = document.getElementById("floating-action-bar");
chrome.storage.sync.set(
{
hideRightSidebar: rightSidebar.checked,
hideFloatingActionBar: floatingActionBar.checked,
},
function () {
publish();
const info = document.getElementById("info");
info.textContent = "Successfully updated!";
setTimeout(function () {
info.textContent = "";
}, 1000);
}
);
}
function resetPreferences() {
document.getElementById("right-sidebar").checked = false;
document.getElementById("floating-action-bar").checked = false;
chrome.storage.sync.set(
{
hideRightSidebar: false,
hideFloatingActionBar: false,
},
function () {
publish();
const info = document.getElementById("info");
info.textContent = "Successfully reset!";
setTimeout(function () {
info.textContent = "";
}, 1000);
}
);
}
function loadPreferences() {
chrome.storage.sync.get(
{
hideRightSidebar: false,
hideFloatingActionBar: false,
},
function (preferences) {
document.getElementById("right-sidebar").checked =
preferences.hideRightSidebar;
document.getElementById("floating-action-bar").checked =
preferences.hideFloatingActionBar;
}
);
}
async function publish() {
const [activeTab] = await chrome.tabs.query({
active: true,
currentWindow: true,
});
chrome.tabs.sendMessage(activeTab.id, { message: "reload" });
}
document.addEventListener("DOMContentLoaded", loadPreferences);
document.getElementById("reset").addEventListener("click", resetPreferences);
document.getElementById("save").addEventListener("click", updatePreferences);