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

added option to include the infobar in saved pages (fix #243)

Former-commit-id: 77d6ef6f4eb856a6bb5a7cee110e0ec8a32bbd39
Gildas 6 роки тому
батько
коміт
54e8cf5fa4

+ 5 - 1
_locales/de/messages.json

@@ -127,6 +127,10 @@
         "message": "Muster für Inhalt des Infoknopfs",
         "message": "Muster für Inhalt des Infoknopfs",
         "description": "Options page label: 'template of the infobar content'"
         "description": "Options page label: 'template of the infobar content'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "Einfügen Inhalt des Infoknopfs in die gespeicherte Seite",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "Inhalt des Infoknopfs im Dialogfenster eingeben",
         "message": "Inhalt des Infoknopfs im Dialogfenster eingeben",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
@@ -443,4 +447,4 @@
         "message": "Neuen Namen für das ausgewählte Profil eingeben",
         "message": "Neuen Namen für das ausgewählte Profil eingeben",
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
     }
     }
-}
+}

+ 5 - 1
_locales/en/messages.json

@@ -127,6 +127,10 @@
         "message": "template of the infobar content",
         "message": "template of the infobar content",
         "description": "Options page label: 'template of the infobar content'"
         "description": "Options page label: 'template of the infobar content'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "include the infobar in the saved page",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "open a prompt dialog to edit the infobar content",
         "message": "open a prompt dialog to edit the infobar content",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
@@ -443,4 +447,4 @@
         "message": "Enter a new name for the selected profile",
         "message": "Enter a new name for the selected profile",
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
     }
     }
-}
+}

+ 4 - 0
_locales/es/messages.json

@@ -127,6 +127,10 @@
         "message": "plantilla del contenido de la barra informativa",
         "message": "plantilla del contenido de la barra informativa",
         "description": "Options page label: 'template of the infobar content'"
         "description": "Options page label: 'template of the infobar content'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "incluir la barra informativa en la página guardada",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "abrir un cuadro de diálogo para editar el contenido de la barra informativa",
         "message": "abrir un cuadro de diálogo para editar el contenido de la barra informativa",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"

+ 5 - 1
_locales/fr/messages.json

@@ -127,6 +127,10 @@
         "message": "modèle du contenu de la barre d'information",
         "message": "modèle du contenu de la barre d'information",
         "description": "Options page label: 'template of the infobar content'"
         "description": "Options page label: 'template of the infobar content'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "inclure la barre d'information dans la page sauvegardée",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "ouvrir une boite de dialogue pour éditer le contenu de la barre d'information",
         "message": "ouvrir une boite de dialogue pour éditer le contenu de la barre d'information",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
@@ -443,4 +447,4 @@
         "message": "Saisissez un nouveau nom pour le profil sélectionné",
         "message": "Saisissez un nouveau nom pour le profil sélectionné",
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
     }
     }
-}
+}

+ 5 - 1
_locales/ja/messages.json

@@ -127,6 +127,10 @@
         "message": "infobar コンテンツのテンプレート",
         "message": "infobar コンテンツのテンプレート",
         "description": "オプションのページラベル: 'infobar コンテンツのテンプレート'"
         "description": "オプションのページラベル: 'infobar コンテンツのテンプレート'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "include the infobar in the saved page",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "infobar のコンテンツを編集するためのプロンプトダイアログを開く",
         "message": "infobar のコンテンツを編集するためのプロンプトダイアログを開く",
         "description": "オプションのページラベル: 'infobar のコンテンツを編集するためのプロンプトダイアログを開く'"
         "description": "オプションのページラベル: 'infobar のコンテンツを編集するためのプロンプトダイアログを開く'"
@@ -443,4 +447,4 @@
         "message": "選択したプロファイルの新しい名前を入力します。",
         "message": "選択したプロファイルの新しい名前を入力します。",
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
     }
     }
-}
+}

+ 5 - 1
_locales/pl/messages.json

@@ -127,6 +127,10 @@
         "message": "szablon zawartości paska informacyjnego",
         "message": "szablon zawartości paska informacyjnego",
         "description": "Options page label: 'template of the infobar content'"
         "description": "Options page label: 'template of the infobar content'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "włączyć paska informacyjnego do zapisanej strony",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "otwieraj okno dialogowe z monitem, aby edytować zawartość paska informacyjnego",
         "message": "otwieraj okno dialogowe z monitem, aby edytować zawartość paska informacyjnego",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
@@ -443,4 +447,4 @@
         "message": "Wpisz nową nazwę wybranego profilu",
         "message": "Wpisz nową nazwę wybranego profilu",
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
     }
     }
-}
+}

+ 5 - 1
_locales/ru/messages.json

@@ -127,6 +127,10 @@
         "message": "шаблон содержимого информационной панели",
         "message": "шаблон содержимого информационной панели",
         "description": "Options page label: 'template of the infobar content'"
         "description": "Options page label: 'template of the infobar content'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "включить информационной панели в сохраненную страницу",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "открывать диалоговое окно для редактирования содержимого информационной панели",
         "message": "открывать диалоговое окно для редактирования содержимого информационной панели",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
@@ -443,4 +447,4 @@
         "message": "Введите новое имя для выбранного профиля",
         "message": "Введите новое имя для выбранного профиля",
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
         "description": "Popup text 'Enter a new name for the selected profile' in the options page"
     }
     }
-}
+}

+ 5 - 1
_locales/zh_CN/messages.json

@@ -127,6 +127,10 @@
         "message": "信息栏内容模板",
         "message": "信息栏内容模板",
         "description": "选项页标签: '信息栏内容模板'"
         "description": "选项页标签: '信息栏内容模板'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "include the infobar in the saved page",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "打开一个提示窗口以编辑信息栏内容",
         "message": "打开一个提示窗口以编辑信息栏内容",
         "description": "选项页标签: '打开一个提示窗口以编辑信息栏内容'"
         "description": "选项页标签: '打开一个提示窗口以编辑信息栏内容'"
@@ -446,4 +450,4 @@
     "__WET_LOCALE__": {
     "__WET_LOCALE__": {
         "message": "zh-cn"
         "message": "zh-cn"
     }
     }
-}
+}

+ 5 - 1
_locales/zh_TW/messages.json

@@ -127,6 +127,10 @@
         "message": "信息欄內容模板",
         "message": "信息欄內容模板",
         "description": "選項頁標籤: '信息欄內容模板'"
         "description": "選項頁標籤: '信息欄內容模板'"
     },
     },
+    "optionIncludeInfobar": {
+        "message": "include the infobar in the saved page",
+        "description": "Options page label: 'include the infobar in the saved page'"
+    },
     "optionConfirmInfobar": {
     "optionConfirmInfobar": {
         "message": "打開一個提示窗口以編輯信息欄內容",
         "message": "打開一個提示窗口以編輯信息欄內容",
         "description": "選項頁標籤: '打開一個提示窗口以編輯信息欄內容'"
         "description": "選項頁標籤: '打開一個提示窗口以編輯信息欄內容'"
@@ -446,4 +450,4 @@
     "__WET_LOCALE__": {
     "__WET_LOCALE__": {
         "message": "zh_TW"
         "message": "zh_TW"
     }
     }
-}
+}

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

@@ -117,6 +117,9 @@ singlefile.extension.core.bg.autosave = (() => {
 		const processor = new (singlefile.lib.SingleFile.getClass())(options);
 		const processor = new (singlefile.lib.SingleFile.getClass())(options);
 		await processor.run();
 		await processor.run();
 		const page = await processor.getPageData();
 		const page = await processor.getPageData();
+		if (options.includeInfobar) {
+			await singlefile.extension.core.common.infobar.includeScript(page);
+		}
 		page.url = URL.createObjectURL(new Blob([page.content], { type: "text/html" }));
 		page.url = URL.createObjectURL(new Blob([page.content], { type: "text/html" }));
 		try {
 		try {
 			await singlefile.extension.core.bg.downloads.downloadPage(page, options);
 			await singlefile.extension.core.bg.downloads.downloadPage(page, options);

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

@@ -39,6 +39,7 @@ singlefile.extension.core.bg.business = (() => {
 		"/lib/single-file/single-file-core.js",
 		"/lib/single-file/single-file-core.js",
 		"/lib/single-file/single-file.js",
 		"/lib/single-file/single-file.js",
 		"/extension/ui/content/content-ui-main.js",
 		"/extension/ui/content/content-ui-main.js",
+		"/extension/core/common/infobar.js",
 		"/extension/core/content/content-main.js"
 		"/extension/core/content/content-main.js"
 	];
 	];
 
 

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

@@ -45,6 +45,7 @@ singlefile.extension.core.bg.config = (() => {
 		loadDeferredImagesBlockStorage: false,
 		loadDeferredImagesBlockStorage: false,
 		filenameTemplate: "{page-title} ({date-iso} {time-locale}).html",
 		filenameTemplate: "{page-title} ({date-iso} {time-locale}).html",
 		infobarTemplate: "",
 		infobarTemplate: "",
+		includeInfobar: false,
 		confirmInfobarContent: false,
 		confirmInfobarContent: false,
 		confirmFilename: false,
 		confirmFilename: false,
 		filenameConflictAction: "uniquify",
 		filenameConflictAction: "uniquify",

+ 43 - 0
extension/core/common/infobar.js

@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010-2019 Gildas Lormeau
+ * contact : gildas.lormeau <at> gmail.com
+ * 
+ * This file is part of SingleFile.
+ *
+ *   The code in this file is free software: you can redistribute it and/or 
+ *   modify it under the terms of the GNU Affero General Public License 
+ *   (GNU AGPL) as published by the Free Software Foundation, either version 3
+ *   of the License, or (at your option) any later version.
+ * 
+ *   The code in this file is distributed in the hope that it will be useful, 
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero 
+ *   General Public License for more details.
+ *
+ *   As additional permission under GNU AGPL version 3 section 7, you may 
+ *   distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU 
+ *   AGPL normally required by section 4, provided you include this license 
+ *   notice and a URL through which recipients can access the Corresponding 
+ *   Source.
+ */
+
+/* global browser, singlefile, fetch */
+
+singlefile.extension.core.common.infobar = (() => {
+
+	return {
+		includeScript
+	};
+
+	async function includeScript(pageData) {
+		let infobarContent = await (await fetch(browser.runtime.getURL("/extension/ui/content/content-ui-infobar.js"))).text();
+		let lastInfobarContent;
+		while (lastInfobarContent != infobarContent) {
+			lastInfobarContent = infobarContent;
+			infobarContent = infobarContent.replace(/\/\*(.|\n)*?\*\//, "");
+		}
+		infobarContent = infobarContent.replace(/\t+/g, " ").replace(/\nthis\.[^(]*/gi, "\n").replace(/\n+/g, "");
+		pageData.content += "<script>" + infobarContent + "</script>";
+	}
+
+})();

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

@@ -198,6 +198,9 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 	}
 	}
 
 
 	async function downloadPage(page, options) {
 	async function downloadPage(page, options) {
+		if (options.includeInfobar) {
+			await singlefile.extension.core.common.infobar.includeScript(page);
+		}
 		if (options.backgroundSave) {
 		if (options.backgroundSave) {
 			for (let blockIndex = 0; blockIndex * MAX_CONTENT_SIZE < page.content.length; blockIndex++) {
 			for (let blockIndex = 0; blockIndex * MAX_CONTENT_SIZE < page.content.length; blockIndex++) {
 				const message = {
 				const message = {

+ 5 - 0
extension/ui/bg/ui-options.js

@@ -82,6 +82,7 @@
 	const groupDuplicateImagesLabel = document.getElementById("groupDuplicateImagesLabel");
 	const groupDuplicateImagesLabel = document.getElementById("groupDuplicateImagesLabel");
 	const confirmInfobarLabel = document.getElementById("confirmInfobarLabel");
 	const confirmInfobarLabel = document.getElementById("confirmInfobarLabel");
 	const infobarTemplateLabel = document.getElementById("infobarTemplateLabel");
 	const infobarTemplateLabel = document.getElementById("infobarTemplateLabel");
+	const includeInfobarLabel = document.getElementById("includeInfobarLabel");
 	const miscLabel = document.getElementById("miscLabel");
 	const miscLabel = document.getElementById("miscLabel");
 	const helpLabel = document.getElementById("helpLabel");
 	const helpLabel = document.getElementById("helpLabel");
 	const addProfileButton = document.getElementById("addProfileButton");
 	const addProfileButton = document.getElementById("addProfileButton");
@@ -127,6 +128,7 @@
 	const removeAlternativeMediasInput = document.getElementById("removeAlternativeMediasInput");
 	const removeAlternativeMediasInput = document.getElementById("removeAlternativeMediasInput");
 	const groupDuplicateImagesInput = document.getElementById("groupDuplicateImagesInput");
 	const groupDuplicateImagesInput = document.getElementById("groupDuplicateImagesInput");
 	const infobarTemplateInput = document.getElementById("infobarTemplateInput");
 	const infobarTemplateInput = document.getElementById("infobarTemplateInput");
+	const includeInfobarInput = document.getElementById("includeInfobarInput");
 	const confirmInfobarInput = document.getElementById("confirmInfobarInput");
 	const confirmInfobarInput = document.getElementById("confirmInfobarInput");
 	const expandAllButton = document.getElementById("expandAllButton");
 	const expandAllButton = document.getElementById("expandAllButton");
 	const rulesDeleteAllButton = document.getElementById("rulesDeleteAllButton");
 	const rulesDeleteAllButton = document.getElementById("rulesDeleteAllButton");
@@ -410,6 +412,7 @@
 	miscLabel.textContent = browser.i18n.getMessage("optionsMiscSubTitle");
 	miscLabel.textContent = browser.i18n.getMessage("optionsMiscSubTitle");
 	helpLabel.textContent = browser.i18n.getMessage("optionsHelpLink");
 	helpLabel.textContent = browser.i18n.getMessage("optionsHelpLink");
 	infobarTemplateLabel.textContent = browser.i18n.getMessage("optionInfobarTemplate");
 	infobarTemplateLabel.textContent = browser.i18n.getMessage("optionInfobarTemplate");
+	includeInfobarLabel.textContent = browser.i18n.getMessage("optionIncludeInfobar");
 	confirmInfobarLabel.textContent = browser.i18n.getMessage("optionConfirmInfobar");
 	confirmInfobarLabel.textContent = browser.i18n.getMessage("optionConfirmInfobar");
 	resetButton.textContent = browser.i18n.getMessage("optionsResetButton");
 	resetButton.textContent = browser.i18n.getMessage("optionsResetButton");
 	exportButton.textContent = browser.i18n.getMessage("optionsExportButton");
 	exportButton.textContent = browser.i18n.getMessage("optionsExportButton");
@@ -581,6 +584,7 @@
 		groupDuplicateImagesInput.checked = profileOptions.groupDuplicateImages;
 		groupDuplicateImagesInput.checked = profileOptions.groupDuplicateImages;
 		removeAlternativeMediasInput.checked = profileOptions.removeAlternativeMedias;
 		removeAlternativeMediasInput.checked = profileOptions.removeAlternativeMedias;
 		infobarTemplateInput.value = profileOptions.infobarTemplate;
 		infobarTemplateInput.value = profileOptions.infobarTemplate;
+		includeInfobarInput.checked = profileOptions.includeInfobar;
 		confirmInfobarInput.checked = profileOptions.confirmInfobarContent;
 		confirmInfobarInput.checked = profileOptions.confirmInfobarContent;
 		removeFramesInput.disabled = saveRawPageInput.checked;
 		removeFramesInput.disabled = saveRawPageInput.checked;
 		removeFramesInput.checked = removeFramesInput.checked || saveRawPageInput.checked;
 		removeFramesInput.checked = removeFramesInput.checked || saveRawPageInput.checked;
@@ -635,6 +639,7 @@
 				removeAlternativeMedias: removeAlternativeMediasInput.checked,
 				removeAlternativeMedias: removeAlternativeMediasInput.checked,
 				groupDuplicateImages: groupDuplicateImagesInput.checked,
 				groupDuplicateImages: groupDuplicateImagesInput.checked,
 				infobarTemplate: infobarTemplateInput.value,
 				infobarTemplate: infobarTemplateInput.value,
+				includeInfobar: includeInfobarInput.checked,
 				confirmInfobarContent: confirmInfobarInput.checked
 				confirmInfobarContent: confirmInfobarInput.checked
 			}
 			}
 		});
 		});

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

@@ -193,6 +193,10 @@
 							considerably reduce the size of the file without altering the document most of the time. It
 							considerably reduce the size of the file without altering the document most of the time. It
 							may also decrease the time needed to save a page.</p>
 							may also decrease the time needed to save a page.</p>
 					</li>
 					</li>
+					<li data-options-label="includeInfobarLabel">Option: include infobar in the saved page
+						<p>Check this option to display the ℹ button at the top right of the page when viewing a saved
+							page in a browser where SingleFileZ is not installed.</p>
+					</li>
 				</ul>
 				</ul>
 				<p>Stylesheets</p>
 				<p>Stylesheets</p>
 				<ul>
 				<ul>

+ 4 - 0
extension/ui/pages/options.html

@@ -84,6 +84,10 @@
 				<label for="removeFramesInput" id="removeFramesLabel"></label>
 				<label for="removeFramesInput" id="removeFramesLabel"></label>
 				<input type="checkbox" id="removeFramesInput">
 				<input type="checkbox" id="removeFramesInput">
 			</div>
 			</div>
+			<div class="option">
+				<label for="includeInfobarInput" id="includeInfobarLabel"></label>
+				<input type="checkbox" id="includeInfobarInput">
+			</div>
 		</details>
 		</details>
 		<details>
 		<details>
 			<summary id="stylesheetsLabel"></summary>
 			<summary id="stylesheetsLabel"></summary>

+ 1 - 0
index.js

@@ -24,6 +24,7 @@
 this.singlefile = this.singlefile || {
 this.singlefile = this.singlefile || {
 	extension: {
 	extension: {
 		core: {
 		core: {
+			common: {},
 			bg: {},
 			bg: {},
 			content: {}
 			content: {}
 		},
 		},

+ 1 - 0
manifest.json

@@ -61,6 +61,7 @@
 			"extension/core/bg/tabs.js",
 			"extension/core/bg/tabs.js",
 			"extension/core/bg/downloads.js",
 			"extension/core/bg/downloads.js",
 			"extension/core/bg/autosave.js",
 			"extension/core/bg/autosave.js",
+			"extension/core/common/infobar.js",
 			"extension/ui/bg/ui-main.js",
 			"extension/ui/bg/ui-main.js",
 			"extension/ui/bg/ui-menus.js",
 			"extension/ui/bg/ui-menus.js",
 			"extension/ui/bg/ui-commands.js",
 			"extension/ui/bg/ui-commands.js",