forked from Stirling-Tools/Stirling-PDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Frooodle:main' into main
- Loading branch information
Showing
3 changed files
with
125 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,98 @@ | ||
var toggleCount = 0; | ||
var lastToggleTime = Date.now(); | ||
var toggleCount = 0 | ||
var lastToggleTime = Date.now() | ||
|
||
var elements = { | ||
lightModeStyles: null, | ||
darkModeStyles: null, | ||
rainbowModeStyles: null, | ||
darkModeIcon: null | ||
}; | ||
lightModeStyles: null, | ||
darkModeStyles: null, | ||
rainbowModeStyles: null, | ||
darkModeIcon: null, | ||
} | ||
|
||
function getElements() { | ||
elements.lightModeStyles = document.getElementById("light-mode-styles"); | ||
elements.darkModeStyles = document.getElementById("dark-mode-styles"); | ||
elements.rainbowModeStyles = document.getElementById("rainbow-mode-styles"); | ||
elements.darkModeIcon = document.getElementById("dark-mode-icon"); | ||
elements.lightModeStyles = document.getElementById("light-mode-styles") | ||
elements.darkModeStyles = document.getElementById("dark-mode-styles") | ||
elements.rainbowModeStyles = document.getElementById("rainbow-mode-styles") | ||
elements.darkModeIcon = document.getElementById("dark-mode-icon") | ||
elements.searchBar = document.getElementById("searchBar") | ||
elements.formControls = document.querySelectorAll(".form-control") | ||
} | ||
|
||
function setMode(mode) { | ||
var event = new CustomEvent('modeChanged', { detail: mode }); | ||
document.dispatchEvent(event); | ||
elements.lightModeStyles.disabled = mode !== "off"; | ||
elements.darkModeStyles.disabled = mode !== "on"; | ||
elements.rainbowModeStyles.disabled = mode !== "rainbow"; | ||
var jumbotron = document.getElementById('jumbotron'); | ||
if (mode === "on") { | ||
elements.darkModeIcon.src = "moon.svg"; | ||
// Add the table-dark class to tables for dark mode | ||
var tables = document.querySelectorAll('.table'); | ||
tables.forEach(table => { | ||
table.classList.add('table-dark'); | ||
}); | ||
if(jumbotron) { | ||
jumbotron.classList.add('bg-dark'); | ||
jumbotron.classList.remove('bg-light'); | ||
} | ||
} else if (mode === "off") { | ||
elements.darkModeIcon.src = "sun.svg"; | ||
// Remove the table-dark class for light mode | ||
var tables = document.querySelectorAll('.table-dark'); | ||
tables.forEach(table => { | ||
table.classList.remove('table-dark'); | ||
}); | ||
if(jumbotron){ | ||
console.log(mode) | ||
jumbotron.classList.remove('bg-dark'); | ||
jumbotron.classList.add('bg-light'); | ||
} | ||
} else if (mode === "rainbow") { | ||
elements.darkModeIcon.src = "rainbow.svg"; | ||
} | ||
var event = new CustomEvent("modeChanged", { detail: mode }) | ||
document.dispatchEvent(event) | ||
elements.lightModeStyles.disabled = mode !== "off" | ||
elements.darkModeStyles.disabled = mode !== "on" | ||
elements.rainbowModeStyles.disabled = mode !== "rainbow" | ||
var jumbotron = document.getElementById("jumbotron") | ||
if (mode === "on") { | ||
elements.darkModeIcon.src = "moon.svg" | ||
// Dark mode improvement | ||
elements.searchBar.classList.add("dark-mode-search") | ||
elements.formControls.forEach(input => input.classList.add("bg-dark", "text-white")) | ||
// Add the table-dark class to tables for dark mode | ||
var tables = document.querySelectorAll(".table") | ||
tables.forEach(table => { | ||
table.classList.add("table-dark") | ||
}) | ||
if (jumbotron) { | ||
jumbotron.classList.add("bg-dark") | ||
jumbotron.classList.remove("bg-light") | ||
} | ||
} else if (mode === "off") { | ||
elements.darkModeIcon.src = "sun.svg" | ||
// Dark Mode Improvement | ||
elements.searchBar.classList.remove("dark-mode-search") | ||
elements.formControls.forEach(input => input.classList.remove("bg-dark", "text-white")) | ||
// Remove the table-dark class for light mode | ||
var tables = document.querySelectorAll(".table-dark") | ||
tables.forEach(table => { | ||
table.classList.remove("table-dark") | ||
}) | ||
if (jumbotron) { | ||
console.log(mode) | ||
jumbotron.classList.remove("bg-dark") | ||
jumbotron.classList.add("bg-light") | ||
} | ||
} else if (mode === "rainbow") { | ||
elements.darkModeIcon.src = "rainbow.svg" | ||
} | ||
} | ||
|
||
function toggleDarkMode() { | ||
var currentTime = Date.now(); | ||
if (currentTime - lastToggleTime < 1000) { | ||
toggleCount++; | ||
} else { | ||
toggleCount = 1; | ||
} | ||
lastToggleTime = currentTime; | ||
var currentTime = Date.now() | ||
if (currentTime - lastToggleTime < 1000) { | ||
toggleCount++ | ||
} else { | ||
toggleCount = 1 | ||
} | ||
lastToggleTime = currentTime | ||
|
||
if (toggleCount >= 18) { | ||
localStorage.setItem("dark-mode", "rainbow"); | ||
setMode("rainbow"); | ||
} else if (localStorage.getItem("dark-mode") == "on") { | ||
localStorage.setItem("dark-mode", "off"); | ||
setMode("off"); | ||
} else { | ||
localStorage.setItem("dark-mode", "on"); | ||
setMode("on"); | ||
} | ||
if (toggleCount >= 18) { | ||
localStorage.setItem("dark-mode", "rainbow") | ||
setMode("rainbow") | ||
} else if (localStorage.getItem("dark-mode") == "on") { | ||
localStorage.setItem("dark-mode", "off") | ||
setMode("off") | ||
} else { | ||
localStorage.setItem("dark-mode", "on") | ||
setMode("on") | ||
} | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
getElements(); | ||
document.addEventListener("DOMContentLoaded", function () { | ||
getElements() | ||
|
||
var currentMode = localStorage.getItem("dark-mode") | ||
if (currentMode === "on" || currentMode === "off" || currentMode === "rainbow") { | ||
setMode(currentMode) | ||
} else if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
setMode("on") | ||
} else { | ||
setMode("off") | ||
} | ||
|
||
var currentMode = localStorage.getItem("dark-mode"); | ||
if (currentMode === "on" || currentMode === "off" || currentMode === "rainbow") { | ||
setMode(currentMode); | ||
} else if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
setMode("on"); | ||
} else { | ||
setMode("off"); | ||
} | ||
|
||
document.getElementById("dark-mode-toggle").addEventListener("click", function(event) { | ||
event.preventDefault(); | ||
toggleDarkMode(); | ||
}); | ||
}); | ||
document.getElementById("dark-mode-toggle").addEventListener("click", function (event) { | ||
event.preventDefault() | ||
toggleDarkMode() | ||
}) | ||
}) |