/*Canopy - The next generation of stoner streaming software Copyright (C) 2024-2026 Rainbownapkin and the TTN Community This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ /** * Class to manage */ class themeManager{ /** * Instantiates new Theme Manager */ constructor(){ /** * Map of all available themes */ this.themes = new Map([ ["Movie Night", "/css/theme/movie-night.css"], ["The Network (Classic)", "/css/theme/the-network-classic.css"] ]); /** * Sets default theme for new users */ this.defaultTheme = "The Network (Classic)"; /** * Define property to hold theme link DOM node */ this.themeLink = null; //Set theme from preference this.setTheme(localStorage.getItem("theme")); } /** * Sets theme by name * @param {String} theme - name of theme to set, keep blank for default theme */ setTheme(theme = localStorage.getItem("theme")){ //If we didnt get a theme to set if(theme == null || theme == ""){ //Use the first theme in the list theme = this.defaultTheme; } //If we have a link already setup if(this.themeLink != null){ //Get Ridda it! this.themeLink.remove(); } //Create new link element and use it to set themeLink this.themeLink = this.genThemeLink(theme); //If we got a bad link if(this.themeLink == null){ //Reset the theme to the default theme this.setTheme(this.defaultTheme); //Do not pass go, do not collect $200 return; } //Append themeLink to header document.querySelector('head').appendChild(this.themeLink); //Save theme choice to local storage localStorage.setItem("theme", theme); } genThemeLink(theme = localStorage.getItem("theme")){ //Grab themePath by name let themePath = this.themes.get(theme) //If we got dookie-dick for a theme if(themePath == null || themePath == ""){ //GIMME A THEME WITH NUTHIN'! NUTHIN'?!?! NUTHIN'!! https://i.ytimg.com/vi/CccHBlGrOu8/hqdefault.jpg return; } //Create new link element and use it to set themeLink const themeLink = document.createElement('link'); //Set themeLink attributes themeLink.type = "text/css"; themeLink.rel = "stylesheet"; //Set theme href to theme location themeLink.href = themePath; return themeLink; } } ThemeManager = new themeManager();