From 627fa59d384317e916c19d56af4e8f9d5d8a5dda Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Tue, 22 Feb 2022 00:15:53 -0300 Subject: [PATCH] Add loadParticles() and setParticles() --- assets/js/theme.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index 8bdcb44..d2ae081 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1,12 +1,13 @@ let toggleTheme = (theme) => { if (theme == "dark") { setTheme("light"); + loadParticles("light") } else { setTheme("dark"); + loadParticles("dark") } } - let setTheme = (theme) => { transTheme(); if (theme) { @@ -46,3 +47,32 @@ let initTheme = (theme) => { initTheme(localStorage.getItem("theme")); + +let loadParticles = (theme) => { + var matches = document.baseURI.match(/\//g); + var count = matches ? matches.length : 0; + if (count != 3) + return; + + if (!theme) + setParticles(localStorage.getItem("theme")) + else + setParticles(theme) +} + +let setParticles = (theme) => { + if (theme == "dark") { + try { + particlesJS.load('particles-js', 'assets/json/particles-dark.json'); + } catch(e) { + console.log('ERROR: particles-js is not loaded.') + } + } + else { + try { + particlesJS.load('particles-js', 'assets/json/particles-light.json'); + } catch(e) { + console.log('ERROR: particles-js is not loaded.') + } + } +} \ No newline at end of file