summaryrefslogtreecommitdiff
path: root/static/scripts
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2021-02-27 01:14:41 -0700
committerDavid Luevano Alvarado <david@luevano.xyz>2021-02-27 01:14:41 -0700
commit54180a1a177b9a11d8348c14a3446529b08daea7 (patch)
tree139b56c97c32bacbf7dd2765eb08dacd7322c544 /static/scripts
parent89724572c5250e2eb531754e33ac112896fa0226 (diff)
Tweak css and add switch for dark and light mode
Diffstat (limited to 'static/scripts')
-rw-r--r--static/scripts/gb.js2
-rw-r--r--static/scripts/theme.js53
2 files changed, 54 insertions, 1 deletions
diff --git a/static/scripts/gb.js b/static/scripts/gb.js
index 4051d7f..67afe20 100644
--- a/static/scripts/gb.js
+++ b/static/scripts/gb.js
@@ -41,7 +41,7 @@ $(document).ready(function (){
$('#btn_down').click(function (){
input(3);
});
-
+
$('#btn_a').click(function (){
input(4);
});
diff --git a/static/scripts/theme.js b/static/scripts/theme.js
new file mode 100644
index 0000000..2ffe621
--- /dev/null
+++ b/static/scripts/theme.js
@@ -0,0 +1,53 @@
+var local_storage = window.localStorage;
+
+window.onload = () => {
+ let theme = local_storage.getItem('theme');
+ let switch_theme = document.getElementById('theme-switch');
+
+ if(theme == null){
+ local_storage.setItem('theme', 'dark');
+ }
+
+ if(theme == 'dark'){
+ switch_theme.checked = true;
+ }
+ else{
+ switch_theme.checked = false;
+
+ let theme = document.getElementById('theme-css');
+ let href = theme.getAttribute('href');
+
+ href = href.replace('dark.css', 'light.css');
+ theme.setAttribute('href', href);
+ }
+}
+
+function setTheme(){
+ let switch_theme = document.getElementById('theme-switch');
+
+ if(switch_theme.checked == true){
+ local_storage.setItem('theme', 'dark');
+ }
+ else{
+ local_storage.setItem('theme', 'light');
+ }
+}
+
+// toggles between both themes, and then calls set theme to actually set it persistently.
+function toggleTheme(){
+ let theme = document.getElementById('theme-css');
+ let href = theme.getAttribute('href');
+
+ if(href.endsWith('dark.css')){
+ href = href.replace('dark.css', 'light.css');
+ }
+ else if (href.endsWith('light.css')){
+ href = href.replace('light.css', 'dark.css');
+ }
+ else{
+ console.log('Wrong replacement.');
+ }
+
+ theme.setAttribute('href', href);
+ setTheme();
+}