mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
create new css link to smoothly transition between themes
Previously, directly editing the <link> tag with the new file would cause the page to have no stylesheet for a moment while the new file is downloaded. A new element is now appended below the original instead, which smoothens out the transition.
This commit is contained in:
parent
ec7609ed8c
commit
56478e96c9
@ -19,14 +19,25 @@ var transitionEndEvent = whichTransitionEvent();
|
|||||||
|
|
||||||
// Toggles between light and dark themes
|
// Toggles between light and dark themes
|
||||||
function toggleCSS() {
|
function toggleCSS() {
|
||||||
let cssEl = document.querySelectorAll('link[rel="stylesheet"][type="text/css"]')[0];
|
let Els = document.querySelectorAll('link[rel="stylesheet"][type="text/css"]');
|
||||||
|
let cssEl = Els[0]
|
||||||
|
let remove = false;
|
||||||
|
if (Els.length != 1) {
|
||||||
|
cssEl = Els[1]
|
||||||
|
remove = true
|
||||||
|
}
|
||||||
let href = "bs" + bsVersion;
|
let href = "bs" + bsVersion;
|
||||||
if (cssEl.href.includes(href + "-jf")) {
|
if (cssEl.href.includes(href + "-jf")) {
|
||||||
href += ".css";
|
href += ".css";
|
||||||
} else {
|
} else {
|
||||||
href += "-jf.css";
|
href += "-jf.css";
|
||||||
}
|
}
|
||||||
cssEl.href = href
|
let newEl = cssEl.cloneNode(true);
|
||||||
|
newEl.href = href
|
||||||
|
cssEl.parentNode.insertBefore(newEl, cssEl.nextSibling);
|
||||||
|
if (remove) {
|
||||||
|
Els[0].remove()
|
||||||
|
}
|
||||||
document.cookie = "css=" + href;
|
document.cookie = "css=" + href;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
main.go
15
main.go
@ -94,7 +94,14 @@ func setGinLogger(router *gin.Engine, debugMode bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// app encompasses essentially all useful functions.
|
||||||
app := new(appContext)
|
app := new(appContext)
|
||||||
|
|
||||||
|
/*
|
||||||
|
set default config, data and local paths
|
||||||
|
also, confusing naming here. data_path is not the internal 'data' directory, rather the users .config/jfa-go folder.
|
||||||
|
local_path is the internal 'data' directory.
|
||||||
|
*/
|
||||||
userConfigDir, _ := os.UserConfigDir()
|
userConfigDir, _ := os.UserConfigDir()
|
||||||
app.data_path = filepath.Join(userConfigDir, "jfa-go")
|
app.data_path = filepath.Join(userConfigDir, "jfa-go")
|
||||||
app.config_path = filepath.Join(app.data_path, "config.ini")
|
app.config_path = filepath.Join(app.data_path, "config.ini")
|
||||||
@ -111,6 +118,8 @@ func main() {
|
|||||||
debug := flag.Bool("debug", false, "Enables debug logging and exposes pprof.")
|
debug := flag.Bool("debug", false, "Enables debug logging and exposes pprof.")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// attempt to apply command line flags correctly
|
||||||
if app.config_path == *configPath && app.data_path != *dataPath {
|
if app.config_path == *configPath && app.data_path != *dataPath {
|
||||||
app.data_path = *dataPath
|
app.data_path = *dataPath
|
||||||
app.config_path = filepath.Join(app.data_path, "config.ini")
|
app.config_path = filepath.Join(app.data_path, "config.ini")
|
||||||
@ -121,7 +130,7 @@ func main() {
|
|||||||
app.data_path = *dataPath
|
app.data_path = *dataPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// Env variables are necessary because syscall.Exec for self-restarts doesn't doesn't work with arguments for some reason.
|
// env variables are necessary because syscall.Exec for self-restarts doesn't doesn't work with arguments for some reason.
|
||||||
|
|
||||||
if v := os.Getenv("JFA_CONFIGPATH"); v != "" {
|
if v := os.Getenv("JFA_CONFIGPATH"); v != "" {
|
||||||
app.config_path = v
|
app.config_path = v
|
||||||
@ -158,14 +167,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
app.info.Printf("Copied default configuration to \"%s\"", app.config_path)
|
app.info.Printf("Copied default configuration to \"%s\"", app.config_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugMode bool
|
var debugMode bool
|
||||||
var address string
|
var address string
|
||||||
if app.loadConfig() != nil {
|
if app.loadConfig() != nil {
|
||||||
app.err.Fatalf("Failed to load config file \"%s\"", app.config_path)
|
app.err.Fatalf("Failed to load config file \"%s\"", app.config_path)
|
||||||
}
|
}
|
||||||
app.version = app.config.Section("jellyfin").Key("version").String()
|
app.version = app.config.Section("jellyfin").Key("version").String()
|
||||||
|
// read from config...
|
||||||
debugMode = app.config.Section("ui").Key("debug").MustBool(false)
|
debugMode = app.config.Section("ui").Key("debug").MustBool(false)
|
||||||
|
// then from flag
|
||||||
if *debug {
|
if *debug {
|
||||||
debugMode = true
|
debugMode = true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user