Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/st-wong/hugo-spectre-pixel-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/main.js')
-rw-r--r--static/js/main.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/static/js/main.js b/static/js/main.js
new file mode 100644
index 0000000..49e26bb
--- /dev/null
+++ b/static/js/main.js
@@ -0,0 +1,38 @@
+function togglePixelFont() {
+ const htmlTag = document.getElementsByTagName("html")[0];
+ pixelFontToggle = document.getElementById("pixelfont-toggle");
+ if (htmlTag.hasAttribute("data-theme")) {
+ if (typeof(Storage) !== "undefined") {
+ sessionStorage.pixelFontToggle = 0;
+ }
+ htmlTag.removeAttribute("data-theme");
+ pixelFontToggle.classList.add("text-gray");
+ pixelFontToggle.classList.remove("text-light");
+ return
+ }
+ htmlTag.setAttribute("data-theme", "pixel")
+ pixelFontToggle.classList.add("text-light");
+ pixelFontToggle.classList.remove("text-gray");
+ if (typeof(Storage) !== "undefined") {
+ sessionStorage.pixelFontToggle = 1;
+ }
+}
+
+function setPixelFont(){
+ if (typeof(Storage) !== "undefined" && sessionStorage.pixelFontToggle) {
+ const htmlTag = document.getElementsByTagName("html")[0];
+ pixelFontToggle = document.getElementById("pixelfont-toggle");
+ if (Number(sessionStorage.getItem("pixelFontToggle")) === 1) {
+ pixelFontToggle.classList.add("text-light");
+ pixelFontToggle.classList.remove("text-gray");
+ htmlTag.setAttribute("data-theme", "pixel");
+ }
+ else {
+ htmlTag.removeAttribute("data-theme");
+ pixelFontToggle.classList.add("text-gray");
+ pixelFontToggle.classList.remove("text-light");
+ }
+ }
+}
+
+document.getElementById("pixelfont-toggle").addEventListener("click", togglePixelFont);