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