diff --git a/assets/css/darktheme.css b/assets/css/darktheme.css new file mode 100644 index 00000000..19cdfd45 --- /dev/null +++ b/assets/css/darktheme.css @@ -0,0 +1,26 @@ +a:hover, +a:active { + color: #46aaf6; +} + +a { + color: #f0f0f0; + text-decoration: none; +} + +body { + background-color: #101010; + color: #f0f0f0; +} + +.pure-form legend { + color: #f0f0f0; +} + +.pure-menu-heading { + color: #f0f0f0; +} + +.pure-form > fieldset > input { + color: #101010; +} diff --git a/assets/css/custom.css b/assets/css/default.css similarity index 55% rename from assets/css/custom.css rename to assets/css/default.css index abd4e66e..850ebd47 100644 --- a/assets/css/custom.css +++ b/assets/css/default.css @@ -1,13 +1,3 @@ -a { - color: #333; - text-decoration: none; -} - -a:hover, -a:active { - color: #167ac6; -} - .h-box { padding-left: 1em; padding-right: 1em; @@ -16,4 +6,4 @@ a:active { .v-box { padding-top: 1em; padding-bottom: 1em; -} \ No newline at end of file +} diff --git a/assets/css/lighttheme.css b/assets/css/lighttheme.css new file mode 100644 index 00000000..34bb9fc1 --- /dev/null +++ b/assets/css/lighttheme.css @@ -0,0 +1,9 @@ +a:hover, +a:active { + color: #167ac6; +} + +a { + color: #303030; + text-decoration: none; +} diff --git a/src/invidious.cr b/src/invidious.cr index 78b13b1c..85645611 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -208,6 +208,10 @@ before_all do |env| notifications ||= 0 env.set "notifications", notifications end + + if env.request.cookies.has_key?("darktheme") && env.request.cookies["darktheme"].value == "true" + env.set "darktheme", true + end end get "/" do |env| @@ -514,7 +518,9 @@ get "/signout" do |env| referer ||= "/" env.request.cookies.each do |cookie| - cookie.expires = Time.new(1990, 1, 1) + if cookie.name != "darktheme" + cookie.expires = Time.new(1990, 1, 1) + end end env.request.cookies.add_response_headers(env.response.headers) @@ -770,6 +776,20 @@ get "/subscription_ajax" do |env| env.redirect referer end +get "/modify_theme" do |env| + referer = env.request.headers["referer"]? + referer ||= "/" + + if env.params.query["dark"]? + env.response.cookies["darktheme"] = "true" + elsif env.params.query["light"]? + env.request.cookies["darktheme"].expires = Time.new(1990, 1, 1) + env.request.cookies.add_response_headers(env.response.headers) + end + + env.redirect referer +end + error 404 do |env| error_message = "404 Page not found" templated "error" diff --git a/src/views/layout.ecr b/src/views/layout.ecr index cf26da3f..22abd4c5 100644 --- a/src/views/layout.ecr +++ b/src/views/layout.ecr @@ -7,7 +7,12 @@ - + + <% if env.get? "darktheme" %> + + <% else %> + + <% end %> <%= yield_content "header" %> @@ -21,7 +26,9 @@
- "> +
+ "> +
@@ -47,6 +54,13 @@
<%= content %> +
+ <% if env.get? "darktheme" %> + Light theme + <% else %> + Dark theme + <% end %> +
Released under AGPLv3 by Omar Roth - source available here