-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
107 lines (84 loc) · 2.72 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
if (!navigator.serviceWorker.controller) {
navigator.serviceWorker.register("/sw.js").then(function(reg) {
console.log("Service worker has been registered for scope: " + reg.scope);
});
}
// Checking local storage
const theme = localStorage.getItem("theme");
const font_size = localStorage.getItem("font-size");
const font_family = localStorage.getItem("font-family");
///////////////////////
const textarea = document.getElementById("notes");
const body = document.getElementById("body");
const theme_select = document.getElementById("theme-select");
const font_style_select = document.getElementById("font-style-select");
const font_size_select = document.getElementById("font-size-select");
let notes = localStorage.getItem("notes");
textarea.value = notes;
const menu = document.getElementById("menu");
let rotated = false;
function toggle() {
if (rotated == false) {
document.getElementById("menu-icon").style.animationName =
"rotate-open";
rotated = true;
} else {
document.getElementById("menu-icon").style.animationName =
"rotate-close";
rotated = false;
}
if (menu.style.display == "none" || menu.style.display == "") {
menu.style.display = "inline-block";
} else {
menu.style.display = "none";
}
}
function syncNotes() {
notes = document.getElementById("notes").value;
localStorage.setItem("notes", notes);
}
//////////////////////////////////////
// Handling themes
//////////////////////////////////////
function themeChange() {
if (theme_select.value == "dark") {
body.className = "body-dark";
textarea.className = "textarea-dark";
localStorage.setItem("theme", "dark");
} else if (theme_select.value == "light") {
body.className = "body-light";
textarea.className = "textarea-light";
localStorage.setItem("theme", "light");
}
}
// Setting theme according to local storage
if (theme) {
body.className = "body-" + theme;
textarea.className = "textarea-" + theme;
theme_select.value = theme;
}
//////////////////////////////////////////
// Handling font families
function fontFamilyChange() {
body.style.fontFamily = font_style_select.value;
textarea.style.fontFamily = font_style_select.value;
localStorage.setItem("font-family", font_style_select.value);
}
if (font_family) {
body.style.fontFamily = font_family;
textarea.style.fontFamily = font_family;
font_style_select.value = font_family;
}
////////////////////////////
// Handling font sizes
function fontSizeChange() {
body.style.fontSize = font_size_select.value;
textarea.style.fontSize = font_size_select.value;
localStorage.setItem("font-size", font_size_select.value);
}
if (font_size) {
body.style.fontSize = font_size;
textarea.style.fontSize = font_size;
font_size_select.value = font_size;
}
///////////////////////////