Ver código fonte

added support of {url-search-*} template variables (see #135)

Gildas 7 anos atrás
pai
commit
8f38693aa1

+ 2 - 1
extension/ui/pages/help.html

@@ -436,7 +436,8 @@
 					<li><code>{url-port}</code>: the port of the URL (e.g. "8080")</li>
 					<li><code>{url-username}</code>: the user name of the URL (e.g. "john_doe")</li>
 					<li><code>{url-password}</code>: the password of the URL (e.g. "qwerty123")</li>
-					<li><code>{url-search}</code>: the search string of the URL (e.g. "filter-date=today")</li>
+					<li><code>{url-search}</code>: the search string of the URL (e.g. "order=ascending")</li>
+					<li><code>{url-search-&lt;name&gt;}</code>: the query parameter "&lt;name&gt;" in the the search string of the URL (e.g. "url-search-order" will return "ascending" in the previous example)</li>
 					<li><code>{url-hash}</code>: the hash of the URL (e.g. "chapter-2")</li>
 					<li><code>{url-referrer}</code>: the URI of the page that "linked" to the page (e.g. "http_example.com")</li>
 					<li><code>{tab-id}</code>: the unique identifier of the tab (e.g. "326")</li>

+ 6 - 1
lib/single-file/single-file-core.js

@@ -1087,6 +1087,11 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			template = await Util.evalTemplateVariable(template, "url-port", () => url.port || "No port", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-protocol", () => url.protocol || "No protocol", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-search", () => url.search.substring(1) || "No search", dontReplaceSlash);
+			const params = url.search.substring(1).split("&").map(parameter => parameter.split("="));
+			for (const [name, value] of params) {
+				template = await Util.evalTemplateVariable(template, "url-search-" + name, () => value || "", dontReplaceSlash);
+			}
+			template = template.replace(/{\s*url-search-[^}\s]*\s*}/gi, "");
 			template = await Util.evalTemplateVariable(template, "url-username", () => url.username || "No username", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "tab-id", () => String(options.tabId || "No tab id"), dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-last-segment", () => decodeURI(Util.getLastSegment(url)) || "No last segment", dontReplaceSlash);
@@ -1095,7 +1100,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				template = await Util.evalTemplateVariable(template, "digest-sha-384", async () => docUtil.digest("SHA-384", content), dontReplaceSlash);
 				template = await Util.evalTemplateVariable(template, "digest-sha-512", async () => docUtil.digest("SHA-512", content), dontReplaceSlash);
 			}
-			return template;
+			return template.trim();
 		}
 
 		static setBackgroundImage(element, url, style) {