-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (41 loc) · 1.45 KB
/
main.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
const $ = document.querySelector.bind(document);
document.addEventListener('DOMContentLoaded', (event) => {
//const usageField = $('#current_measure');
const toggleSwitch = $('.theme-switch input[type="checkbox"]');
const currentTheme = localStorage.getItem('theme');
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') {
toggleSwitch.checked = true;
}
}
function switchTheme(e) {
if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
}
else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
}
}
//usageField.addEventListener('keyup', checkInput, false);
toggleSwitch.addEventListener('change', switchTheme, false);
}
);
usageField.addEventListener('keyup', checkInput, false);
function checkInput(e) {
//only alpha-numeric characters
var ok = /[0-9]/.test(String.fromCharCode(e.charCode));
if (!ok)
e.preventDefault();
var difference = e.target.value - 20000;
$('.usage').innerHTML = "הפרש מקריאה קודמת: " + difference;
if ( difference > 100 ) {
$('.high_usage').innerHTML = "ההפרש מהקריאה הנוכחית גדול מדי.";
$('.high_usage').style.display = "block";
}
else {
$('.high_usage').style.display = "none";
}
};