Переглянути джерело

added new template variable {url-referrer} (fixes #141)

Gildas 7 роки тому
батько
коміт
deeb71a39f

+ 1 - 0
extension/core/bg/autosave.js

@@ -91,6 +91,7 @@ singlefile.autosave = (() => {
 		options.postersData = message.postersData;
 		options.usedFonts = message.usedFonts;
 		options.shadowRootContents = message.shadowRootContents;
+		options.referrer = message.referrer;
 		options.insertSingleFileComment = true;
 		options.insertFaviconLink = true;
 		options.backgroundTab = true;

+ 2 - 0
extension/core/content/content-bootstrap.js

@@ -68,6 +68,7 @@ this.singlefile.bootstrap = this.singlefile.bootstrap || (async () => {
 					postersData: docData.postersData,
 					usedFonts: docData.usedFonts,
 					shadowRootContents: docData.shadowRootContents,
+					referrer: docData.referrer,
 					framesData,
 					url: location.href
 				});
@@ -106,6 +107,7 @@ this.singlefile.bootstrap = this.singlefile.bootstrap || (async () => {
 					postersData: docData.postersData,
 					usedFonts: docData.usedFonts,
 					shadowRootContents: docData.shadowRootContents,
+					referrer: docData.referrer,
 					framesData: frameTree.getSync(options),
 					url: location.href
 				});

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

@@ -438,6 +438,7 @@
 					<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-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 this page (e.g. "http_example.com")</li>
 					<li><code>{tab-id}</code>: the unique identifier of the tab (e.g. "326")</li>
 					<li><code>{digest-sha-256}</code>: the SHA-256 hash value of the entire page content (e.g.
 						e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855)</li>

+ 2 - 0
lib/single-file/single-file-core.js

@@ -156,6 +156,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				this.options.postersData = docData.postersData;
 				this.options.usedFonts = docData.usedFonts;
 				this.options.shadowRootContents = docData.shadowRootContents;
+				this.options.referrer = docData.referrer;
 			}
 			if (this.options.saveRawPage) {
 				this.options.removeFrames = true;
@@ -1077,6 +1078,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			template = await Util.evalTemplateVariable(template, "url-host", () => url.host.replace(/\/$/, "") || "No host", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-hostname", () => url.hostname.replace(/\/$/, "") || "No hostname", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-href", () => decodeURI(url.href) || "No href", dontReplaceSlash);
+			template = await Util.evalTemplateVariable(template, "url-referrer", () => decodeURI(options.referrer) || "No referrer", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-password", () => url.password || "No password", dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-pathname", () => decodeURI(url.pathname).replace(/^\//, "").replace(/\/$/, "") || "No pathname", dontReplaceSlash === undefined ? true : dontReplaceSlash);
 			template = await Util.evalTemplateVariable(template, "url-port", () => url.port || "No port", dontReplaceSlash);

+ 2 - 1
lib/single-file/util/doc-helper.js

@@ -120,7 +120,8 @@ this.docHelper = this.docHelper || (() => {
 			imageData,
 			postersData: getPostersData(doc),
 			usedFonts,
-			shadowRootContents
+			shadowRootContents,
+			referrer: doc.referrer
 		};
 	}