Просмотр исходного кода

add variables tio get the vist date and dates in ms (see #608)

Gildas 5 лет назад
Родитель
Сommit
592a798ed5

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

@@ -110,6 +110,7 @@ singlefile.extension.core.bg.autosave = (() => {
 		options.imports = message.imports;
 		options.referrer = message.referrer;
 		options.updatedResources = message.updatedResources;
+		options.visitDate = new Date(message.visitDate);
 		options.backgroundTab = true;
 		options.autoSave = true;
 		options.incognito = tab.incognito;

+ 4 - 1
extension/core/content/content-bootstrap.js

@@ -31,6 +31,7 @@ this.singlefile.extension.core.content.bootstrap = this.singlefile.extension.cor
 
 	let unloadListenerAdded, options, autoSaveEnabled, autoSaveTimeout, autoSavingPage, pageAutoSaved, previousLocationHref;
 	singlefile.extension.core.content.updatedResources = {};
+	singlefile.extension.core.content.visitDate = new Date();
 	browser.runtime.sendMessage({ method: "autosave.init" }).then(message => {
 		options = message.options;
 		autoSaveEnabled = message.autoSaveEnabled;
@@ -179,6 +180,7 @@ this.singlefile.extension.core.content.bootstrap = this.singlefile.extension.cor
 	function savePage(docData, frames) {
 		const helper = singlefile.lib.helper;
 		const updatedResources = singlefile.extension.core.content.updatedResources;
+		const visitDate = singlefile.extension.core.content.visitDate.getTime();
 		Object.keys(updatedResources).forEach(url => updatedResources[url].retrieved = false);
 		browser.runtime.sendMessage({
 			method: "autosave.save",
@@ -195,7 +197,8 @@ this.singlefile.extension.core.content.bootstrap = this.singlefile.extension.cor
 			referrer: docData.referrer,
 			frames: frames,
 			url: location.href,
-			updatedResources
+			updatedResources,
+			visitDate
 		});
 	}
 

+ 1 - 0
extension/core/content/content-main.js

@@ -73,6 +73,7 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 		const options = message.options;
 		if (!singlefile.extension.core.processing) {
 			options.updatedResources = singlefile.extension.core.content.updatedResources || {};
+			options.visitDate = singlefile.extension.core.content.visitDate; 
 			Object.keys(options.updatedResources).forEach(url => options.updatedResources[url].retrieved = false);
 			let selectionFound;
 			if (options.selected || options.optionallySelected) {

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

@@ -592,6 +592,7 @@
 					<li><code>{date-locale}</code>: the localized value of the save date (e.g. "16_09_2018")</li>
 					<li><code>{time-iso}</code>: the save time in the ISO format (e.g. "22_38_26_317")</li>
 					<li><code>{time-locale}</code>: the localized value of the save time (e.g. "00_38_26")</li>
+					<li><code>{time-ms}</code>: the save time is ms since the Unix Epoch (e.g. 1563582018000)</li>
 					<li><code>{day-utc}</code>: the day of the save date in UTC format (e.g. "15")</li>
 					<li><code>{day-locale}</code>: the localized value of the day (e.g. "15")</li>
 					<li><code>{month-utc}</code>: the month of the save date in UTC format (e.g. "09")</li>
@@ -603,7 +604,30 @@
 					<li><code>{minutes-utc}</code>: the minutes of the save date in UTC format (e.g. "38")</li>
 					<li><code>{minutes-locale}</code>: the localized value of the minutes (e.g. "38")</li>
 					<li><code>{seconds-utc}</code>: the seconds of the save date in UTC format (e.g. "31")</li>
-					<li><code>{seconds-locale}</code>: the localized value of the seconds (e.g. "31")</li>
+					<li><code>{seconds-locale}</code>: the localized value of the seconds (e.g. "31")</li>					
+					<li><code>{visit-datetime-iso}</code>: the visit date and time in the ISO format (e.g.
+						"2018-09-15T22_38_26_317Z")</li>
+					<li><code>{visit-datetime-utc}</code>: the visit date and time in UTC format (e.g. "Sat, 15 Sep 2018
+						22_38_26 GMT")</li>
+					<li><code>{visit-datetime-locale}</code>: the localized value of the date and time (e.g. "9_16_2018,
+						12_54_31 AM")</li>
+					<li><code>{visit-date-iso}</code>: the visit date in the ISO format (e.g. "2018-09-15")</li>
+					<li><code>{visit-date-locale}</code>: the localized value of the visit date (e.g. "16_09_2018")</li>					
+					<li><code>{visit-time-iso}</code>: the visit time in the ISO format (e.g. "22_38_26_317")</li>
+					<li><code>{visit-time-locale}</code>: the localized value of the visit time (e.g. "00_38_26")</li>
+					<li><code>{visit-time-ms}</code>: the visit time is ms since the Unix Epoch (e.g. 1563582018000)</li>
+					<li><code>{visit-day-utc}</code>: the day of the visit date in UTC format (e.g. "15")</li>
+					<li><code>{visit-day-locale}</code>: the localized value of the day (e.g. "15")</li>
+					<li><code>{visit-month-utc}</code>: the month of the visit date in UTC format (e.g. "09")</li>
+					<li><code>{visit-month-locale}</code>: the localized value of the month (e.g. "09")</li>
+					<li><code>{visit-year-utc}</code>: the year of the visit date in UTC format (e.g. "2018")</li>
+					<li><code>{visit-year-locale}</code>: the localized value of the year (e.g. "2018")</li>
+					<li><code>{visit-hours-utc}</code>: the hour of the visit date in UTC format (e.g. "20")</li>
+					<li><code>{visit-hours-locale}</code>: the localized value of the hour (e.g. "22")</li>
+					<li><code>{visit-minutes-utc}</code>: the minutes of the visit date in UTC format (e.g. "38")</li>
+					<li><code>{visit-minutes-locale}</code>: the localized value of the minutes (e.g. "38")</li>
+					<li><code>{visit-seconds-utc}</code>: the seconds of the visit date in UTC format (e.g. "31")</li>
+					<li><code>{visit-seconds-locale}</code>: the localized value of the seconds (e.g. "31")</li>
 					<li><code>{url-href}</code>: the URL of the page (e.g. "http://example.com/category/index.html")
 					</li>
 					<li><code>{url-href-flat}</code>: the URL of the page with replaced slashes (e.g.

+ 27 - 20
lib/single-file/single-file-core.js

@@ -1457,7 +1457,6 @@ this.singlefile.lib.core = this.singlefile.lib.core || (globalThis => {
 
 	class ProcessorHelper {
 		static async evalTemplate(template = "", options, content, dontReplaceSlash) {
-			const date = options.saveDate;
 			const url = util.parseURL(options.saveUrl);
 			template = await evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await evalTemplateVariable(template, "page-heading", () => options.info.heading || "No heading", dontReplaceSlash, options.filenameReplacementCharacter);
@@ -1466,25 +1465,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (globalThis => {
 			template = await evalTemplateVariable(template, "page-author", () => options.info.author || "No author", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await evalTemplateVariable(template, "page-creator", () => options.info.creator || "No creator", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await evalTemplateVariable(template, "page-publisher", () => options.info.publisher || "No publisher", dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "datetime-iso", () => date.toISOString(), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "date-iso", () => date.toISOString().split("T")[0], dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "time-iso", () => date.toISOString().split("T")[1].split("Z")[0], dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "date-locale", () => date.toLocaleDateString(), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "time-locale", () => date.toLocaleTimeString(), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "day-locale", () => String(date.getDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "month-locale", () => String(date.getMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "year-locale", () => String(date.getFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "datetime-locale", () => date.toLocaleString(), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "datetime-utc", () => date.toUTCString(), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "day-utc", () => String(date.getUTCDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "month-utc", () => String(date.getUTCMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "year-utc", () => String(date.getUTCFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "hours-locale", () => String(date.getHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "minutes-locale", () => String(date.getMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "seconds-locale", () => String(date.getSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "hours-utc", () => String(date.getUTCHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "minutes-utc", () => String(date.getUTCMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
-			template = await evalTemplateVariable(template, "seconds-utc", () => String(date.getUTCSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+			await evalDate(options.saveDate);
+			await evalDate(options.visitDate, "visit-");
 			template = await evalTemplateVariable(template, "url-hash", () => url.hash.substring(1) || "No hash", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await evalTemplateVariable(template, "url-host", () => url.host.replace(/\/$/, "") || "No host", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await evalTemplateVariable(template, "url-hostname", () => url.hostname.replace(/\/$/, "") || "No hostname", dontReplaceSlash, options.filenameReplacementCharacter);
@@ -1525,6 +1507,31 @@ this.singlefile.lib.core = this.singlefile.lib.core || (globalThis => {
 					return value;
 				}
 			}
+
+			async function evalDate(date, prefix) {
+				if (date) {
+					template = await evalTemplateVariable(template, prefix + "datetime-iso", () => date.toISOString(), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "date-iso", () => date.toISOString().split("T")[0], dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "time-iso", () => date.toISOString().split("T")[1].split("Z")[0], dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "date-locale", () => date.toLocaleDateString(), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "time-locale", () => date.toLocaleTimeString(), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "day-locale", () => String(date.getDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "month-locale", () => String(date.getMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "year-locale", () => String(date.getFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "datetime-locale", () => date.toLocaleString(), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "datetime-utc", () => date.toUTCString(), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "day-utc", () => String(date.getUTCDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "month-utc", () => String(date.getUTCMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "year-utc", () => String(date.getUTCFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "hours-locale", () => String(date.getHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "minutes-locale", () => String(date.getMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "seconds-locale", () => String(date.getSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "hours-utc", () => String(date.getUTCHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "minutes-utc", () => String(date.getUTCMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "seconds-utc", () => String(date.getUTCSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
+					template = await evalTemplateVariable(template, prefix + "time-ms", () => String(date.getTime()), dontReplaceSlash, options.filenameReplacementCharacter);
+				}
+			}
 		}
 
 		static setBackgroundImage(element, url, style) {