diff options
-rw-r--r-- | client.go | 29 | ||||
-rw-r--r-- | main.go | 15 | ||||
-rw-r--r-- | static/js/themes.js | 2 | ||||
-rw-r--r-- | static/main.html | 9 |
4 files changed, 43 insertions, 12 deletions
@@ -54,7 +54,9 @@ type PageData struct { ReturnTo string NewsItems []NewsItem BoardRemainer []int - Themes *[]string + + Themes *[]string + ThemeCookie string } type AdminPage struct { @@ -70,7 +72,9 @@ type AdminPage struct { IsLocal bool PostBlacklist []PostBlacklist AutoSubscribe bool - Themes *[]string + + Themes *[]string + ThemeCookie string } type Report struct { @@ -146,6 +150,9 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.NewsItems = getNewsFromDB(db, 3) data.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + data.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err := t.ExecuteTemplate(w, "layout", data) if err != nil { @@ -185,6 +192,9 @@ func NewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB, timestamp int) data.Title = actor.PreferredUsername + ": " + data.NewsItems[0].Title data.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + data.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err = t.ExecuteTemplate(w, "layout", data) if err != nil { @@ -215,6 +225,9 @@ func AllNewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.NewsItems = getNewsFromDB(db, 0) data.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + data.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err := t.ExecuteTemplate(w, "layout", data) if err != nil { @@ -315,6 +328,9 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co returnData.TotalPage = len(returnData.Pages) - 1 returnData.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + returnData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err := t.ExecuteTemplate(w, "layout", returnData) if err != nil { @@ -376,6 +392,9 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C returnData.Posts = collection.OrderedItems returnData.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + returnData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err := t.ExecuteTemplate(w, "layout", returnData) if err != nil { @@ -430,6 +449,9 @@ func ArchiveGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C returnData.Posts = collection.OrderedItems returnData.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + returnData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err := t.ExecuteTemplate(w, "layout", returnData) if err != nil { @@ -531,6 +553,9 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { } returnData.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + returnData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } err := t.ExecuteTemplate(w, "layout", returnData) if err != nil { @@ -96,10 +96,6 @@ func main() { } for _, f := range themes { - if f.Name() == "default.css" { - continue - } - if e := path.Ext(f.Name()); e == ".css" { Themes = append(Themes, strings.TrimSuffix(f.Name(), e)) } @@ -633,7 +629,11 @@ func main() { adminData.Themes = &Themes - err := t.ExecuteTemplate(w, "layout", adminData) + if cookie, err := r.Cookie("theme"); err == nil { + adminData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } + + err = t.ExecuteTemplate(w, "layout", adminData) if err != nil { // TODO: actual error handling log.Printf("mod page: %s\n", err) @@ -673,8 +673,11 @@ func main() { adminData.PostBlacklist = GetRegexBlacklistDB(db) adminData.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + adminData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } - err := t.ExecuteTemplate(w, "layout", adminData) + err = t.ExecuteTemplate(w, "layout", adminData) if err != nil { // TODO: actual error handling log.Printf("mod page: %s\n", err) diff --git a/static/js/themes.js b/static/js/themes.js index 3f1b906..1d89e60 100644 --- a/static/js/themes.js +++ b/static/js/themes.js @@ -1,5 +1,5 @@ function setCookie(key, value, age) { - document.cookie = key + "=" + encodeURIComponent(value) + ";sameSite=strict;max-age=" + 60 * 60 * 24 * age + ";path=/"; + document.cookie = key + "=" + encodeURIComponent(value) + ";sameSite=none;max-age=" + (60 * 60 * 24 * age) + ";path=/"; } function getCookie(key) { diff --git a/static/main.html b/static/main.html index 3e29053..ba871c0 100644 --- a/static/main.html +++ b/static/main.html @@ -8,9 +8,13 @@ <meta property="og:locale" content="en_US" /> <meta property="og:type" content="website" /> <link rel="icon" type="image/png" href="/static/favicon.png"> - <link rel="stylesheet" type="text/css" href="/static/css/themes/default.css" title="default"> + {{ if gt (len .ThemeCookie) 0 }} + <link rel="stylesheet" type="text/css" href="/static/css/themes/{{.ThemeCookie}}.css" title="selected theme"> + {{ else }} + <link rel="stylesheet" type="text/css" href="/static/css/themes/default.css" title="default"> + {{ end }} {{ range .Themes }} - <link rel="alternate stylesheet" type="text/css" href="/static/css/themes/{{.}}.css" title="{{.}}" disabled> + <link rel="alternate stylesheet" type="text/css" href="/static/css/themes/{{.}}.css" title="{{.}}" disabled> {{ end }} {{ template "header" . }} </head> @@ -49,7 +53,6 @@ <div style="float: right;"> Theme: <select id="themeSwitcher" onchange="setTheme(this.options[this.selectedIndex].value)"> - <option value="default">default</option> {{ range .Themes }} <option value="{{.}}">{{.}}</option> {{ end }} |