diff options
Diffstat (limited to 'reference/js')
-rw-r--r-- | reference/js/iife.js | 10 | ||||
-rw-r--r-- | reference/js/setTheme.js | 29 | ||||
-rw-r--r-- | reference/js/toggleTheme.js | 7 |
3 files changed, 46 insertions, 0 deletions
diff --git a/reference/js/iife.js b/reference/js/iife.js new file mode 100644 index 0000000..43018d5 --- /dev/null +++ b/reference/js/iife.js @@ -0,0 +1,10 @@ +(function () { + /* + We set cookies by default, but we do NOT need consent for these as they + are necessary and as per <https://gdpr.eu/cookies>: "To comply with the + regulations governing cookies under the GDPR and the ePrivacy Directive + you must: ... Receive users’ consent before you use any cookies + __except__ strictly necessary cookies..." + */ + setTheme(localStorage.getItem("theme")); +})(); diff --git a/reference/js/setTheme.js b/reference/js/setTheme.js new file mode 100644 index 0000000..b90f629 --- /dev/null +++ b/reference/js/setTheme.js @@ -0,0 +1,29 @@ +function setTheme(theme) { + localStorage.setItem("theme",theme); + var root = document.querySelector(":root"); + var rootstyle = getComputedStyle(root); + const black = rootstyle.getPropertyValue("--black"); + const darkgrey = rootstyle.getPropertyValue("--darkgrey"); + const lightgrey = rootstyle.getPropertyValue("--lightgrey"); + const white = rootstyle.getPropertyValue("--white"); + var backgroundColour0; + var backgroundColour1; + var foregroundColour; + if (theme === "dark") { + backgroundColour0 = black; + backgroundColour1 = darkgrey; + foregroundColour = white; + } + else if (theme === "light") { + backgroundColour0 = lightgrey; + backgroundColour1 = white; + foregroundColour = black; + } + else { + setTheme("dark"); + return; + } + root.style.setProperty("--backgroundColour0",backgroundColour0); + root.style.setProperty("--backgroundColour1",backgroundColour1); + root.style.setProperty("--foregroundColour",foregroundColour); +} diff --git a/reference/js/toggleTheme.js b/reference/js/toggleTheme.js new file mode 100644 index 0000000..cfc1394 --- /dev/null +++ b/reference/js/toggleTheme.js @@ -0,0 +1,7 @@ +function toggleTheme() { + if (localStorage.getItem("theme") === "light") { + setTheme("dark"); + return; + } + setTheme("light"); +} |