Browse Source

add option "open saved pages in a new tab" (cf. #703)

Gildas 4 years ago
parent
commit
1d5265ef1f

+ 4 - 0
_locales/de/messages.json

@@ -399,6 +399,10 @@
 		"message": "annotate the page before saving",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "open pages saved with SingleFile in the annotation editor",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/en/messages.json

@@ -399,6 +399,10 @@
 		"message": "annotate the page before saving",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "open pages saved with SingleFile in the annotation editor",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/es/messages.json

@@ -399,6 +399,10 @@
 		"message": "annotate the page before saving",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "abrir las páginas guardadas en una nueva pestaña",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "open pages saved with SingleFile in the annotation editor",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/fr/messages.json

@@ -399,6 +399,10 @@
 		"message": "annoter la page avant de la sauvegarder",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "ouvrir les pages sauvées dans un nouvel onglet",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "ouvrir les pages sauvées avec SingleFile dans l'éditeur d'annotations",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/ja/messages.json

@@ -399,6 +399,10 @@
 		"message": "保存する前にページに注釈を付けます",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "annotation editor で、SingleFile で保存されたページを開く",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/pl/messages.json

@@ -399,6 +399,10 @@
 		"message": "adnotuj stronę przed zapisaniem",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "otwieraj strony zapisane z SingleFile w edytorze adnotacji",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/ru/messages.json

@@ -399,6 +399,10 @@
 		"message": "аннотировать страницу перед сохранением",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "сохранять открытые страницы из редактора аннотаций SingleFile",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/uk/messages.json

@@ -399,6 +399,10 @@
 		"message": "анотувати сторінки перед збереженням",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "open pages saved with SingleFile in the annotation editor",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/zh_CN/messages.json

@@ -399,6 +399,10 @@
 		"message": "在保存前对该页面进行标注编辑",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "在标注编辑器中打开用 SingleFile 保存的页面",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

+ 4 - 0
_locales/zh_TW/messages.json

@@ -399,6 +399,10 @@
 		"message": "在保存前對該頁面進行標註編輯",
 		"description": "Options page label: 'annotate the page before saving'"
 	},
+	"optionOpenSavedPage": {
+		"message": "open saved pages in a new tab",
+		"description": "Options page label: 'open saved pages in a new tab'"
+	},
 	"optionAutoOpenEditor": {
 		"message": "在標註編輯器中打開用 SingleFile 保存的頁面",
 		"description": "Options page label: 'open pages saved with SingleFile in the annotation editor'"

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

@@ -90,6 +90,7 @@ const DEFAULT_CONFIG = {
 	resolveFragmentIdentifierURLs: false,
 	userScriptEnabled: false,
 	openEditor: false,
+	openSavedPage: false,
 	autoOpenEditor: false,
 	saveCreatedBookmarks: false,
 	ignoredBookmarkFolders: [],

+ 12 - 5
extension/core/bg/downloads.js

@@ -133,21 +133,21 @@ async function downloadTabPage(message, tab) {
 				saveToClipboard(message);
 				ui.onEnd(tab.id);
 			} else {
-				await downloadBlob(new Blob([contents], { type: MIMETYPE_HTML }), tab.id, tab.incognito, message);
+				await downloadBlob(new Blob([contents], { type: MIMETYPE_HTML }), tab, tab.incognito, message);
 			}
 		}
 	}
 	return {};
 }
 
-async function downloadBlob(blob, tabId, incognito, message) {
+async function downloadBlob(blob, tab, incognito, message) {
 	try {
 		if (message.saveToGDrive) {
 			await uploadPage(message.taskId, message.filename, blob, {
 				forceWebAuthFlow: message.forceWebAuthFlow,
 				extractAuthCode: message.extractAuthCode
 			}, {
-				onProgress: (offset, size) => ui.onUploadProgress(tabId, offset, size)
+				onProgress: (offset, size) => ui.onUploadProgress(tab.id, offset, size)
 			});
 		} else {
 			message.url = URL.createObjectURL(blob);
@@ -159,11 +159,18 @@ async function downloadBlob(blob, tabId, incognito, message) {
 				includeInfobar: message.includeInfobar
 			});
 		}
-		ui.onEnd(tabId);
+		ui.onEnd(tab.id);
+		if (message.openSavedPage) {
+			const createTabProperties = { active: true, url: URL.createObjectURL(blob) };
+			if (tab.index != null) {
+				createTabProperties.index = tab.index + 1;
+			}
+			tabs.create(createTabProperties);
+		}
 	} catch (error) {
 		if (!error.message || error.message != "upload_cancelled") {
 			console.error(error); // eslint-disable-line no-console
-			ui.onError(tabId);
+			ui.onError(tab.id);
 		}
 	} finally {
 		if (message.url) {

+ 5 - 1
extension/core/common/download.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, infobar, document, URL, Blob, MouseEvent, setTimeout */
+/* global browser, infobar, document, URL, Blob, MouseEvent, setTimeout, open */
 
 const MAX_CONTENT_SIZE = 32 * (1024 * 1024);
 
@@ -50,6 +50,7 @@ async function downloadPage(pageData, options) {
 				extractAuthCode: options.extractAuthCode,
 				filenameReplacementCharacter: options.filenameReplacementCharacter,
 				openEditor: options.openEditor,
+				openSavedPage: options.openSavedPage,
 				compressHTML: options.compressHTML,
 				backgroundSave: options.backgroundSave,
 				bookmarkId: options.bookmarkId,
@@ -74,6 +75,9 @@ async function downloadPage(pageData, options) {
 		} else {
 			await downloadPageForeground(pageData);
 		}
+		if (options.openSavedPage) {
+			open(URL.createObjectURL(new Blob([pageData.content], { type: "text/html" })));
+		}
 		browser.runtime.sendMessage({ method: "ui.processEnd" });
 	}
 	await browser.runtime.sendMessage({ method: "downloads.end", taskId: options.taskId, hash: pageData.hash });

+ 1 - 1
extension/lib/woleet/woleet.js

@@ -22,7 +22,7 @@
  */
 /* global fetch */
 const urlService = "https://api.woleet.io/v1/anchor";
-const apiKey = "__WOLEET_API_KEY__";
+const apiKey = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYzZmZTMzMi0wODNjLTRjZmMtYmYxNC0xNWU5MTJmMWY4OWIiLCJpYXQiOjE1NzYxNzQzNDV9.n31j9ctJj7R1Vjwyc5yd1d6Cmg0NDnpwSaLWsqtZJQA";
 export {
 	anchor
 };

+ 1 - 0
extension/ui/bg/ui-editor.js

@@ -259,6 +259,7 @@ addEventListener("message", event => {
 			filename: tabData.filename
 		};
 		tabData.options.openEditor = false;
+		tabData.options.openSavedPage = false;
 		download.downloadPage(pageData, tabData.options);
 	}
 	if (message.method == "onUpdate") {

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

@@ -96,6 +96,7 @@ const confirmInfobarLabel = document.getElementById("confirmInfobarLabel");
 const autoCloseLabel = document.getElementById("autoCloseLabel");
 const editorLabel = document.getElementById("editorLabel");
 const openEditorLabel = document.getElementById("openEditorLabel");
+const openSavedPageLabel = document.getElementById("openSavedPageLabel");
 const autoOpenEditorLabel = document.getElementById("autoOpenEditorLabel");
 const defaultEditorModeLabel = document.getElementById("defaultEditorModeLabel");
 const applySystemThemeLabel = document.getElementById("applySystemThemeLabel");
@@ -162,6 +163,7 @@ const includeInfobarInput = document.getElementById("includeInfobarInput");
 const confirmInfobarInput = document.getElementById("confirmInfobarInput");
 const autoCloseInput = document.getElementById("autoCloseInput");
 const openEditorInput = document.getElementById("openEditorInput");
+const openSavedPageInput = document.getElementById("openSavedPageInput");
 const autoOpenEditorInput = document.getElementById("autoOpenEditorInput");
 const defaultEditorModeInput = document.getElementById("defaultEditorModeInput");
 const defaultEditorModeNormalLabel = document.getElementById("defaultEditorModeNormalLabel");
@@ -511,6 +513,7 @@ confirmInfobarLabel.textContent = browser.i18n.getMessage("optionConfirmInfobar"
 autoCloseLabel.textContent = browser.i18n.getMessage("optionAutoClose");
 editorLabel.textContent = browser.i18n.getMessage("optionsEditorSubTitle");
 openEditorLabel.textContent = browser.i18n.getMessage("optionOpenEditor");
+openSavedPageLabel.textContent = browser.i18n.getMessage("optionOpenSavedPage");
 autoOpenEditorLabel.textContent = browser.i18n.getMessage("optionAutoOpenEditor");
 defaultEditorModeLabel.textContent = browser.i18n.getMessage("optionDefaultEditorMode");
 defaultEditorModeNormalLabel.textContent = browser.i18n.getMessage("optionDefaultEditorModeNormal");
@@ -703,6 +706,7 @@ async function refresh(profileName) {
 	confirmInfobarInput.checked = profileOptions.confirmInfobarContent;
 	autoCloseInput.checked = profileOptions.autoClose;
 	openEditorInput.checked = profileOptions.openEditor;
+	openSavedPageInput.checked = profileOptions.openSavedPage;
 	autoOpenEditorInput.checked = profileOptions.autoOpenEditor;
 	defaultEditorModeInput.value = profileOptions.defaultEditorMode;
 	applySystemThemeInput.checked = profileOptions.applySystemTheme;
@@ -771,6 +775,7 @@ async function update() {
 			confirmInfobarContent: confirmInfobarInput.checked,
 			autoClose: autoCloseInput.checked,
 			openEditor: openEditorInput.checked,
+			openSavedPage: openSavedPageInput.checked,
 			autoOpenEditor: autoOpenEditorInput.checked,
 			defaultEditorMode: defaultEditorModeInput.value,
 			applySystemTheme: applySystemThemeInput.checked,

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

@@ -47,6 +47,10 @@
 				<label for="confirmInfobarInput" id="confirmInfobarLabel"></label>
 				<input type="checkbox" id="confirmInfobarInput">
 			</div>
+			<div class="option">
+				<label for="openSavedPageInput" id="openSavedPageLabel"></label>
+				<input type="checkbox" id="openSavedPageInput">
+			</div>			
 			<div class="option">
 				<label for="autoCloseInput" id="autoCloseLabel"></label>
 				<input type="checkbox" id="autoCloseInput">