Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ryan778
GitHub Repository: Ryan778/Ryan778.github.io
Path: blob/master/final-grade-calculator/secondary.js
574 views
1
/* secondary.js
2
* Handles what dialogs (the messages up top, not the alert boxes) to show and whether to show them or not
3
* Also handles the theme toggle button
4
* (C) 2019 Ryan Zhang. All Rights Reserved.
5
* Interested in anything on here? Contact me at https://ryan778.github.io/about-me/ and we can discuss.
6
*/
7
8
let s_dismissed = [];
9
let s_curTheme = 1; // 1 = light, 0 = dark
10
if(localStorage.fgc_dismissedDialogs){
11
$('#sp-resetDialogs').show();
12
s_dismissed = localStorage.fgc_dismissedDialogs.split('|')}
13
14
function d_show(ele, key){
15
if(s_dismissed.indexOf(key) === -1){
16
$(ele).show();
17
}
18
}
19
20
$('.btn-close').on('click', (e) => {
21
$('#sp-resetDialogs').show();
22
s_dismissed.push(e.currentTarget.dataset.key);
23
localStorage.fgc_dismissedDialogs = s_dismissed.join('|');
24
$(e.currentTarget.parentElement.parentElement).hide();
25
})
26
27
$('#a-resetDialogs').on('click', (e) => {
28
if(e.currentTarget.dataset.hasReset){location.reload()}
29
localStorage.removeItem('fgc_dismissedDialogs');
30
e.currentTarget.innerText = 'Success! (Reload to show)';
31
e.currentTarget.dataset.hasReset = '1';
32
})
33
34
$('#i-toggleTheme').on('click', (e) => {
35
s_curTheme = !s_curTheme;
36
e.currentTarget.innerHTML = s_curTheme?'nights_stay':'wb_sunny';
37
document.getElementById('theme').href = `themes/${s_curTheme?'default':'dark'}.css`;
38
})
39
40
d_show('#al_rel', 'r1.0.0')
41
if(!window.matchMedia("(prefers-color-scheme: light)").matches || new Date().getHours() > 22 || new Date().getHours() < 6){
42
s_curTheme = 0;
43
d_show('#al_dark', 'autodark')}
44