-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
48 lines (40 loc) · 1.44 KB
/
options.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
function loadLogo(buddySrc) {
if(buddySrc === undefined) {
buddySrc = mozExt + "default_images/niolet.png"
}
document.getElementById("result").setAttribute("src", buddySrc)
}
function handlePhotoUpload(event) {
var reader = new FileReader();
reader.onload = function (e) {
browser.storage.local.set({buddy: e.target.result})
browser.storage.local.get().then((items) => document.getElementById("result").setAttribute("src", items.buddy))
}
reader.readAsDataURL(event.target.files[0]);
}
function handleSizeChange() {
browser.storage.local.set({size: document.getElementById("size").value})
}
function lightMode() {
document.body.setAttribute("class", "light")
browser.storage.local.set({theme: "light"})
}
function darkMode() {
document.body.setAttribute("class", "dark")
browser.storage.local.set({theme: "dark"})
}
function onThemeLoad(theme) {
document.body.setAttribute("class", theme)
if(theme === "dark") {
document.getElementById("dark").checked = true
}
else {
document.getElementById("light").checked = true
}
}
document.getElementById("upload_photo").addEventListener("change", handlePhotoUpload)
document.getElementById("size").onchange = handleSizeChange
document.getElementById("light").onchange = lightMode
document.getElementById("dark").onchange = darkMode
browser.storage.local.get().then((items) => loadLogo(items.buddy))
browser.storage.local.get().then((items) => onThemeLoad(items.theme))