Browse Source

add hotkey (a N) to toggle night.css

Andrew Dolgov 1 year ago
parent
commit
1c8593c1fa
13 changed files with 60 additions and 21 deletions
  1. 5 5
      css/default.css
  2. 0 0
      css/default.css.map
  3. 9 0
      css/dijit_basic.less
  4. 0 8
      css/dijit_light.less
  5. 4 2
      include/controls.php
  6. 2 0
      include/functions.php
  7. 2 2
      index.php
  8. 26 2
      js/AppBase.js
  9. 2 0
      js/prefs.js
  10. 3 0
      js/tt-rss.js
  11. 2 2
      prefs.php
  12. 5 0
      themes/night.css
  13. 0 0
      themes/night.css.map

+ 5 - 5
css/default.css

@@ -1831,6 +1831,11 @@ body#sharepopup input {
 .flat label.dijitButton:hover {
   background-color: #f5f5f5;
 }
+.flat .dijitTree .dijitTreeNode .dijitTreeRow {
+  padding: 4px 0px 4px;
+  border-width: 1px;
+  color: #555555;
+}
 @font-face {
   font-family: 'Material Icons';
   font-style: normal;
@@ -1873,11 +1878,6 @@ body#sharepopup input {
 .flat .dijitCheckBox {
   background: #ccc;
 }
-.flat .dijitTree .dijitTreeNode .dijitTreeRow {
-  padding: 4px 0px 4px;
-  border-width: 1px;
-  color: #333;
-}
 body.ttrss_zoom {
   margin-left: auto;
   margin-right: auto;

File diff suppressed because it is too large
+ 0 - 0
css/default.css.map


+ 9 - 0
css/dijit_basic.less

@@ -132,4 +132,13 @@
 	label.dijitButton:hover {
 		background-color : @color-panel-bg;
 	}
+
+	.dijitTree {
+		.dijitTreeNode .dijitTreeRow {
+			padding : 4px 0px 4px;
+			border-width : 1px;
+			color : @default-text;
+		}
+	}
+
 }

+ 0 - 8
css/dijit_light.less

@@ -11,12 +11,4 @@
 	.dijitCheckBox {
 		background : #ccc;
 	}
-
-	.dijitTree {
-		.dijitTreeNode .dijitTreeRow {
-			padding : 4px 0px 4px;
-			border-width : 1px;
-			color : #333;
-		}
-	}
 }

+ 4 - 2
include/controls.php

@@ -233,10 +233,12 @@ function print_feed_cat_select($id, $default_id,
 	}
 }
 
-function stylesheet_tag($filename) {
+function stylesheet_tag($filename, $id = false) {
 	$timestamp = filemtime($filename);
 
-	return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
+	$id_part = $id ? "id=\"$id\"" : "";
+
+	return "<link rel=\"stylesheet\" $id_part type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
 }
 
 function javascript_tag($filename) {

+ 2 - 0
include/functions.php

@@ -1174,6 +1174,7 @@
 				"create_label" => __("Create label"),
 				"create_filter" => __("Create filter"),
 				"collapse_sidebar" => __("Un/collapse sidebar"),
+				"toggle_night_mode" => __("Toggle night mode"),
 				"help_dialog" => __("Show help dialog"))
 		);
 
@@ -1245,6 +1246,7 @@
 			"c l" => "create_label",
 			"c f" => "create_filter",
 			"c s" => "collapse_sidebar",
+			"a *n" => "toggle_night_mode",
 			"^(191)|Ctrl+/" => "help_dialog",
 		);
 

+ 2 - 2
index.php

@@ -64,9 +64,9 @@
 	<?php if ($_SESSION["uid"]) {
 		$theme = get_pref("USER_CSS_THEME", false, false);
 		if ($theme && theme_exists("$theme")) {
-			echo stylesheet_tag(get_theme_path($theme));
+			echo stylesheet_tag(get_theme_path($theme), 'theme_css');
 		} else {
-			echo stylesheet_tag("css/default.css");
+			echo stylesheet_tag("css/default.css", 'theme_css');
 		}
 	}
 	?>

+ 26 - 2
js/AppBase.js

@@ -51,8 +51,9 @@ define(["dojo/_base/declare"], function (declare) {
 			if (dijit.byId("loading_bar"))
 				dijit.byId("loading_bar").update({progress: loading_progress});
 
-			if (loading_progress >= 90)
-				Element.hide("overlay");
+			if (loading_progress >= 90) {
+				$("overlay").hide();
+			}
 
 		},
 		keyeventToAction: function(event) {
@@ -351,6 +352,29 @@ define(["dojo/_base/declare"], function (declare) {
 
 			this.initSecondStage();
 		},
+		toggleNightMode: function() {
+			const link = $("theme_css");
+
+			if (link) {
+
+				let user_theme = "";
+				let user_css = "";
+
+				if (link.getAttribute("href").indexOf("themes/night.css") == -1) {
+					user_css = "themes/night.css?" + Date.now();
+					user_theme = "night.css";
+				} else {
+					user_theme = "default.php";
+					user_css = "css/default.css?" + Date.now();
+				}
+
+				fetch(user_css).then(() => {
+					link.setAttribute("href", user_css);
+					xhrPost("backend.php", {op: "rpc", method: "setpref", key: "USER_CSS_THEME", value: user_theme});
+				});
+
+			}
+		},
 		explainError: function(code) {
 			return this.displayDlg(__("Error explained"), "explainError", code);
 		},

+ 2 - 0
js/prefs.js

@@ -132,6 +132,8 @@ require(["dojo/_base/kernel",
 							case "help_dialog":
 								App.helpDialog("main");
 								return false;
+							case "toggle_night_mode":
+								App.toggleNightMode();
 							default:
 								console.log("unhandled action: " + action_name + "; keycode: " + event.which);
 						}

+ 3 - 0
js/tt-rss.js

@@ -466,6 +466,9 @@ require(["dojo/_base/kernel",
 							Feeds.reloadCurrent();
 						});
 					};
+					this.hotkey_actions["toggle_night_mode"] = function () {
+						App.toggleNightMode();
+					};
 				},
 				onActionSelected: function(opid) {
 					switch (opid) {

+ 2 - 2
prefs.php

@@ -40,9 +40,9 @@
 	<?php if ($_SESSION["uid"]) {
 		$theme = get_pref("USER_CSS_THEME", false, false);
 		if ($theme && theme_exists("$theme")) {
-			echo stylesheet_tag(get_theme_path($theme));
+			echo stylesheet_tag(get_theme_path($theme), 'theme_css');
 		} else {
-			echo stylesheet_tag("css/default.css");
+			echo stylesheet_tag("css/default.css", 'theme_css');
 		}
 	}
 	?>

+ 5 - 0
themes/night.css

@@ -1831,6 +1831,11 @@ body#sharepopup input {
 .flat label.dijitButton:hover {
   background-color: #222222;
 }
+.flat .dijitTree .dijitTreeNode .dijitTreeRow {
+  padding: 4px 0px 4px;
+  border-width: 1px;
+  color: #cccccc;
+}
 @font-face {
   font-family: 'Material Icons';
   font-style: normal;

File diff suppressed because it is too large
+ 0 - 0
themes/night.css.map


Some files were not shown because too many files changed in this diff