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

add option "auto-save on tab discard" (cf #703)

Gildas 4 лет назад
Родитель
Сommit
e7c0754188

+ 4 - 0
_locales/de/messages.json

@@ -375,6 +375,10 @@
 		"message": "Automatische Speicherung beim Schließen der Seite",
 		"message": "Automatische Speicherung beim Schließen der Seite",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "Automatische Speicherung nach Seitenaufbau verzögern (s)",
 		"message": "Automatische Speicherung nach Seitenaufbau verzögern (s)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/en/messages.json

@@ -375,6 +375,10 @@
 		"message": "auto-save on page unload",
 		"message": "auto-save on page unload",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "auto-save waiting delay after page load (s)",
 		"message": "auto-save waiting delay after page load (s)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/es/messages.json

@@ -375,6 +375,10 @@
 		"message": "auto-guardar al purgar la página",
 		"message": "auto-guardar al purgar la página",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "retardo de auto-guardado tras cargar la página (s)",
 		"message": "retardo de auto-guardado tras cargar la página (s)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/fr/messages.json

@@ -375,6 +375,10 @@
 		"message": "auto-sauvegarder au déchargement de la page",
 		"message": "auto-sauvegarder au déchargement de la page",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "délai d'attente après le chargement de la page (s)",
 		"message": "délai d'attente après le chargement de la page (s)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/ja/messages.json

@@ -375,6 +375,10 @@
 		"message": "ページの非読み込み時に自動保存",
 		"message": "ページの非読み込み時に自動保存",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "ページ読み込み後の自動保存待ち時間(秒)",
 		"message": "ページ読み込み後の自動保存待ち時間(秒)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/pl/messages.json

@@ -375,6 +375,10 @@
 		"message": "automatycznie zapisuj przy wyładowaniu strony",
 		"message": "automatycznie zapisuj przy wyładowaniu strony",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "opóźnienie oczekiwania automatycznego zapisywania po załadowaniu strony (s.)",
 		"message": "opóźnienie oczekiwania automatycznego zapisywania po załadowaniu strony (s.)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/ru/messages.json

@@ -375,6 +375,10 @@
 		"message": "автосохранение после выгрузки страницы",
 		"message": "автосохранение после выгрузки страницы",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "задержка автосохранения после загрузки страницы (сек.)",
 		"message": "задержка автосохранения после загрузки страницы (сек.)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/uk/messages.json

@@ -375,6 +375,10 @@
 		"message": "автозбереження після розвантаження сторінки",
 		"message": "автозбереження після розвантаження сторінки",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "затримка автозбереження після завантаження сторінки (с)",
 		"message": "затримка автозбереження після завантаження сторінки (с)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/zh_CN/messages.json

@@ -375,6 +375,10 @@
 		"message": "在页面开始卸载时进行自动保存",
 		"message": "在页面开始卸载时进行自动保存",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "页面加载完成后延迟该时间再进行自动保存(秒)",
 		"message": "页面加载完成后延迟该时间再进行自动保存(秒)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 4 - 0
_locales/zh_TW/messages.json

@@ -375,6 +375,10 @@
 		"message": "在頁面開始卸載時進行自動保存",
 		"message": "在頁面開始卸載時進行自動保存",
 		"description": "Options page label: 'auto-save on page unload'"
 		"description": "Options page label: 'auto-save on page unload'"
 	},
 	},
+	"optionAutoSaveDiscard": {
+		"message": "auto-save on tab discard",
+		"description": "Options page label: 'auto-save on tab discard'"
+	},
 	"optionAutoSaveDelay": {
 	"optionAutoSaveDelay": {
 		"message": "頁面加載完成後延遲該時間再進行自動保存(秒)",
 		"message": "頁面加載完成後延遲該時間再進行自動保存(秒)",
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"
 		"description": "Options page label: 'auto-save waiting delay after page load (s)'"

+ 66 - 46
extension/core/bg/autosave.js

@@ -33,12 +33,15 @@ import * as ui from "./../../ui/bg/index.js";
 import { getPageData } from "./../../index.js";
 import { getPageData } from "./../../index.js";
 import * as woleet from "./../../lib/woleet/woleet.js";
 import * as woleet from "./../../lib/woleet/woleet.js";
 
 
+const pendingDiscardedTabs = {};
+
 export {
 export {
 	onMessage,
 	onMessage,
 	onMessageExternal,
 	onMessageExternal,
 	onInit,
 	onInit,
 	isEnabled,
 	isEnabled,
-	refreshTabs
+	refreshTabs,
+	onTabRemoved
 };
 };
 
 
 async function onMessage(message, sender) {
 async function onMessage(message, sender) {
@@ -48,16 +51,28 @@ async function onMessage(message, sender) {
 	}
 	}
 	if (message.method.endsWith(".save")) {
 	if (message.method.endsWith(".save")) {
 		const tabId = sender.tab.id;
 		const tabId = sender.tab.id;
-		const options = await config.getOptions(sender.tab.url, true);
-		if (options) {
-			ui.onStart(tabId, 1, true);
+		let resolvePendingDiscardedTab;
+		pendingDiscardedTabs[tabId] = new Promise(resolve => resolvePendingDiscardedTab = resolve);
+		if (message.autoSaveDiscard) {
+			message.tab = sender.tab;
+			resolvePendingDiscardedTab(message);
+			if (message.autoSaveUnload) {
+				await saveContent(message, sender.tab);
+			}
+		} else {
 			await saveContent(message, sender.tab);
 			await saveContent(message, sender.tab);
-			ui.onEnd(tabId, true);
 		}
 		}
 		return {};
 		return {};
 	}
 	}
 }
 }
 
 
+async function onTabRemoved(tabId) {
+	const pendingDiscardedTab = await pendingDiscardedTabs[tabId];
+	if (pendingDiscardedTab) {
+		await saveContent(pendingDiscardedTab, pendingDiscardedTab.tab);
+	}
+}
+
 async function onMessageExternal(message, currentTab) {
 async function onMessageExternal(message, currentTab) {
 	if (message.method == "enableAutoSave") {
 	if (message.method == "enableAutoSave") {
 		const allTabsData = await tabsData.get(currentTab.id);
 		const allTabsData = await tabsData.get(currentTab.id);
@@ -101,50 +116,55 @@ async function refreshTabs() {
 
 
 async function saveContent(message, tab) {
 async function saveContent(message, tab) {
 	const options = await config.getOptions(tab.url, true);
 	const options = await config.getOptions(tab.url, true);
-	const tabId = tab.id;
-	options.content = message.content;
-	options.url = message.url;
-	options.frames = message.frames;
-	options.canvases = message.canvases;
-	options.fonts = message.fonts;
-	options.stylesheets = message.stylesheets;
-	options.images = message.images;
-	options.posters = message.posters;
-	options.usedFonts = message.usedFonts;
-	options.shadowRoots = message.shadowRoots;
-	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;
-	options.tabId = tabId;
-	options.tabIndex = tab.index;	
-	let pageData;
-	try {
-		if (options.autoSaveExternalSave) {
-			await companion.save(options);
-		} else {
-			pageData = await getPageData(options, null, null, { fetch });
-			if (options.includeInfobar) {
-				await infobar.includeScript(pageData);
-			}
-			const blob = new Blob([pageData.content], { type: "text/html" });
-			if (options.saveToGDrive) {
-				await downloads.uploadPage(message.taskId, pageData.filename, blob, options, {});
+	if (options) {
+		const tabId = tab.id;
+		delete pendingDiscardedTabs[tabId];
+		ui.onStart(tabId, 1, true);
+		options.content = message.content;
+		options.url = message.url;
+		options.frames = message.frames;
+		options.canvases = message.canvases;
+		options.fonts = message.fonts;
+		options.stylesheets = message.stylesheets;
+		options.images = message.images;
+		options.posters = message.posters;
+		options.usedFonts = message.usedFonts;
+		options.shadowRoots = message.shadowRoots;
+		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;
+		options.tabId = tabId;
+		options.tabIndex = tab.index;
+		let pageData;
+		try {
+			if (options.autoSaveExternalSave) {
+				await companion.save(options);
 			} else {
 			} else {
-				pageData.url = URL.createObjectURL(blob);
-				await downloads.downloadPage(pageData, options);
+				pageData = await getPageData(options, null, null, { fetch });
+				if (options.includeInfobar) {
+					await infobar.includeScript(pageData);
+				}
+				const blob = new Blob([pageData.content], { type: "text/html" });
+				if (options.saveToGDrive) {
+					await downloads.uploadPage(message.taskId, pageData.filename, blob, options, {});
+				} else {
+					pageData.url = URL.createObjectURL(blob);
+					await downloads.downloadPage(pageData, options);
+				}
+				if (pageData.hash) {
+					await woleet.anchor(pageData.hash);
+				}
 			}
 			}
-			if (pageData.hash) {
-				await woleet.anchor(pageData.hash);
+		} finally {
+			business.onSaveEnd(message.taskId);
+			if (pageData && pageData.url) {
+				URL.revokeObjectURL(pageData.url);
 			}
 			}
-		}
-	} finally {
-		business.onSaveEnd(message.taskId);
-		if (pageData && pageData.url) {
-			URL.revokeObjectURL(pageData.url);
+			ui.onEnd(tabId, true);
 		}
 		}
 	}
 	}
 }
 }

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

@@ -75,6 +75,7 @@ const DEFAULT_CONFIG = {
 	autoSaveLoad: false,
 	autoSaveLoad: false,
 	autoSaveUnload: false,
 	autoSaveUnload: false,
 	autoSaveLoadOrUnload: true,
 	autoSaveLoadOrUnload: true,
+	autoSaveDiscard: false,
 	autoSaveRepeat: false,
 	autoSaveRepeat: false,
 	autoSaveRepeatDelay: 10,
 	autoSaveRepeatDelay: 10,
 	removeAlternativeFonts: true,
 	removeAlternativeFonts: true,

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

@@ -212,4 +212,5 @@ function onTabRemoved(tabId) {
 	tabsData.remove(tabId);
 	tabsData.remove(tabId);
 	editor.onTabRemoved(tabId);
 	editor.onTabRemoved(tabId);
 	business.onTabRemoved(tabId);
 	business.onTabRemoved(tabId);
+	autosave.onTabRemoved(tabId);
 }
 }

+ 7 - 5
extension/core/content/content-bootstrap.js

@@ -151,7 +151,7 @@ async function autoSavePage() {
 }
 }
 
 
 function refresh() {
 function refresh() {
-	if (autoSaveEnabled && options && (options.autoSaveUnload || options.autoSaveLoadOrUnload)) {
+	if (autoSaveEnabled && options && (options.autoSaveUnload || options.autoSaveLoadOrUnload || options.autoSaveDiscard)) {
 		if (!unloadListenerAdded) {
 		if (!unloadListenerAdded) {
 			globalThis.addEventListener("unload", onUnload);
 			globalThis.addEventListener("unload", onUnload);
 			unloadListenerAdded = true;
 			unloadListenerAdded = true;
@@ -164,7 +164,7 @@ function refresh() {
 
 
 function onUnload() {
 function onUnload() {
 	const helper = singlefile.helper;
 	const helper = singlefile.helper;
-	if (!pageAutoSaved || options.autoSaveUnload) {
+	if (!pageAutoSaved || options.autoSaveUnload || options.autoSaveDiscard) {
 		const waitForUserScript = window._singleFile_waitForUserScript;
 		const waitForUserScript = window._singleFile_waitForUserScript;
 		let frames = [];
 		let frames = [];
 		if (!options.removeFrames && globalThis.frames && globalThis.frames.length) {
 		if (!options.removeFrames && globalThis.frames && globalThis.frames.length) {
@@ -174,11 +174,11 @@ function onUnload() {
 			waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
 			waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
 		}
 		}
 		const docData = helper.preProcessDoc(document, globalThis, options);
 		const docData = helper.preProcessDoc(document, globalThis, options);
-		savePage(docData, frames);
+		savePage(docData, frames, options.autoSaveUnload, options.autoSaveDiscard);
 	}
 	}
 }
 }
 
 
-function savePage(docData, frames) {
+function savePage(docData, frames, autoSaveUnload, autoSaveDiscard) {
 	const helper = singlefile.helper;
 	const helper = singlefile.helper;
 	const updatedResources = singlefile.pageInfo.updatedResources;
 	const updatedResources = singlefile.pageInfo.updatedResources;
 	const visitDate = singlefile.pageInfo.visitDate.getTime();
 	const visitDate = singlefile.pageInfo.visitDate.getTime();
@@ -199,7 +199,9 @@ function savePage(docData, frames) {
 		frames: frames,
 		frames: frames,
 		url: location.href,
 		url: location.href,
 		updatedResources,
 		updatedResources,
-		visitDate
+		visitDate,
+		autoSaveUnload,
+		autoSaveDiscard
 	});
 	});
 }
 }
 
 

+ 13 - 3
extension/ui/bg/ui-options.js

@@ -64,6 +64,7 @@ const autoSaveDelayLabel = document.getElementById("autoSaveDelayLabel");
 const autoSaveLoadLabel = document.getElementById("autoSaveLoadLabel");
 const autoSaveLoadLabel = document.getElementById("autoSaveLoadLabel");
 const autoSaveUnloadLabel = document.getElementById("autoSaveUnloadLabel");
 const autoSaveUnloadLabel = document.getElementById("autoSaveUnloadLabel");
 const autoSaveLoadOrUnloadLabel = document.getElementById("autoSaveLoadOrUnloadLabel");
 const autoSaveLoadOrUnloadLabel = document.getElementById("autoSaveLoadOrUnloadLabel");
+const autoSaveDiscardLabel = document.getElementById("autoSaveDiscardLabel");
 const autoSaveRepeatLabel = document.getElementById("autoSaveRepeatLabel");
 const autoSaveRepeatLabel = document.getElementById("autoSaveRepeatLabel");
 const autoSaveRepeatDelayLabel = document.getElementById("autoSaveRepeatDelayLabel");
 const autoSaveRepeatDelayLabel = document.getElementById("autoSaveRepeatDelayLabel");
 const autoSaveExternalSaveLabel = document.getElementById("autoSaveExternalSaveLabel");
 const autoSaveExternalSaveLabel = document.getElementById("autoSaveExternalSaveLabel");
@@ -146,6 +147,7 @@ const backgroundSaveInput = document.getElementById("backgroundSaveInput");
 const autoSaveDelayInput = document.getElementById("autoSaveDelayInput");
 const autoSaveDelayInput = document.getElementById("autoSaveDelayInput");
 const autoSaveLoadInput = document.getElementById("autoSaveLoadInput");
 const autoSaveLoadInput = document.getElementById("autoSaveLoadInput");
 const autoSaveUnloadInput = document.getElementById("autoSaveUnloadInput");
 const autoSaveUnloadInput = document.getElementById("autoSaveUnloadInput");
+const autoSaveDiscardInput = document.getElementById("autoSaveDiscardInput");
 const autoSaveLoadOrUnloadInput = document.getElementById("autoSaveLoadOrUnloadInput");
 const autoSaveLoadOrUnloadInput = document.getElementById("autoSaveLoadOrUnloadInput");
 const autoSaveRepeatInput = document.getElementById("autoSaveRepeatInput");
 const autoSaveRepeatInput = document.getElementById("autoSaveRepeatInput");
 const autoSaveRepeatDelayInput = document.getElementById("autoSaveRepeatDelayInput");
 const autoSaveRepeatDelayInput = document.getElementById("autoSaveRepeatDelayInput");
@@ -355,19 +357,24 @@ importButton.addEventListener("click", () => {
 	fileInput.click();
 	fileInput.click();
 }, false);
 }, false);
 autoSaveUnloadInput.addEventListener("click", async () => {
 autoSaveUnloadInput.addEventListener("click", async () => {
-	if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked) {
+	if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked && !autoSaveDiscardInput.checked) {
 		autoSaveLoadOrUnloadInput.checked = true;
 		autoSaveLoadOrUnloadInput.checked = true;
 	}
 	}
 }, false);
 }, false);
 autoSaveLoadInput.addEventListener("click", async () => {
 autoSaveLoadInput.addEventListener("click", async () => {
-	if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked) {
+	if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked && !autoSaveDiscardInput.checked) {
+		autoSaveLoadOrUnloadInput.checked = true;
+	}
+}, false);
+autoSaveDiscardInput.addEventListener("click", async () => {
+	if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked && !autoSaveDiscardInput.checked) {
 		autoSaveLoadOrUnloadInput.checked = true;
 		autoSaveLoadOrUnloadInput.checked = true;
 	}
 	}
 }, false);
 }, false);
 autoSaveLoadOrUnloadInput.addEventListener("click", async () => {
 autoSaveLoadOrUnloadInput.addEventListener("click", async () => {
 	if (autoSaveLoadOrUnloadInput.checked) {
 	if (autoSaveLoadOrUnloadInput.checked) {
 		autoSaveUnloadInput.checked = autoSaveLoadInput.checked = false;
 		autoSaveUnloadInput.checked = autoSaveLoadInput.checked = false;
-	} else {
+	} else if (!autoSaveDiscardInput.checked) {
 		autoSaveUnloadInput.checked = false;
 		autoSaveUnloadInput.checked = false;
 		autoSaveLoadInput.checked = true;
 		autoSaveLoadInput.checked = true;
 	}
 	}
@@ -483,6 +490,7 @@ autoSaveDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveDelay");
 autoSaveLoadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoad");
 autoSaveLoadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoad");
 autoSaveUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveUnload");
 autoSaveUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveUnload");
 autoSaveLoadOrUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoadOrUnload");
 autoSaveLoadOrUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoadOrUnload");
+autoSaveDiscardLabel.textContent = browser.i18n.getMessage("optionAutoSaveDiscard");
 autoSaveRepeatLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeat");
 autoSaveRepeatLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeat");
 autoSaveRepeatDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeatDelay");
 autoSaveRepeatDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeatDelay");
 autoSaveExternalSaveLabel.textContent = browser.i18n.getMessage("optionAutoSaveExternalSave");
 autoSaveExternalSaveLabel.textContent = browser.i18n.getMessage("optionAutoSaveExternalSave");
@@ -685,6 +693,7 @@ async function refresh(profileName) {
 	autoSaveUnloadInput.checked = !profileOptions.autoSaveLoadOrUnload && profileOptions.autoSaveUnload;
 	autoSaveUnloadInput.checked = !profileOptions.autoSaveLoadOrUnload && profileOptions.autoSaveUnload;
 	autoSaveLoadInput.disabled = profileOptions.autoSaveLoadOrUnload;
 	autoSaveLoadInput.disabled = profileOptions.autoSaveLoadOrUnload;
 	autoSaveUnloadInput.disabled = profileOptions.autoSaveLoadOrUnload;
 	autoSaveUnloadInput.disabled = profileOptions.autoSaveLoadOrUnload;
+	autoSaveDiscardInput.checked = profileOptions.autoSaveDiscard;
 	autoSaveRepeatInput.checked = profileOptions.autoSaveRepeat;
 	autoSaveRepeatInput.checked = profileOptions.autoSaveRepeat;
 	autoSaveRepeatInput.disabled = !profileOptions.autoSaveLoadOrUnload && !profileOptions.autoSaveLoad;
 	autoSaveRepeatInput.disabled = !profileOptions.autoSaveLoadOrUnload && !profileOptions.autoSaveLoad;
 	autoSaveRepeatDelayInput.value = profileOptions.autoSaveRepeatDelay;
 	autoSaveRepeatDelayInput.value = profileOptions.autoSaveRepeatDelay;
@@ -758,6 +767,7 @@ async function update() {
 			autoSaveDelay: Math.max(autoSaveDelayInput.value, 0),
 			autoSaveDelay: Math.max(autoSaveDelayInput.value, 0),
 			autoSaveLoad: autoSaveLoadInput.checked,
 			autoSaveLoad: autoSaveLoadInput.checked,
 			autoSaveUnload: autoSaveUnloadInput.checked,
 			autoSaveUnload: autoSaveUnloadInput.checked,
+			autoSaveDiscard: autoSaveDiscardInput.checked,
 			autoSaveLoadOrUnload: autoSaveLoadOrUnloadInput.checked,
 			autoSaveLoadOrUnload: autoSaveLoadOrUnloadInput.checked,
 			autoSaveRepeat: autoSaveRepeatInput.checked,
 			autoSaveRepeat: autoSaveRepeatInput.checked,
 			autoSaveRepeatDelay: Math.max(autoSaveRepeatDelayInput.value, 1),
 			autoSaveRepeatDelay: Math.max(autoSaveRepeatDelayInput.value, 1),

+ 5 - 1
extension/ui/pages/options.html

@@ -50,7 +50,7 @@
 			<div class="option">
 			<div class="option">
 				<label for="openSavedPageInput" id="openSavedPageLabel"></label>
 				<label for="openSavedPageInput" id="openSavedPageLabel"></label>
 				<input type="checkbox" id="openSavedPageInput">
 				<input type="checkbox" id="openSavedPageInput">
-			</div>			
+			</div>
 			<div class="option">
 			<div class="option">
 				<label for="autoCloseInput" id="autoCloseLabel"></label>
 				<label for="autoCloseInput" id="autoCloseLabel"></label>
 				<input type="checkbox" id="autoCloseInput">
 				<input type="checkbox" id="autoCloseInput">
@@ -244,6 +244,10 @@
 				<label for="autoSaveUnloadInput" id="autoSaveUnloadLabel"></label>
 				<label for="autoSaveUnloadInput" id="autoSaveUnloadLabel"></label>
 				<input type="checkbox" id="autoSaveUnloadInput">
 				<input type="checkbox" id="autoSaveUnloadInput">
 			</div>
 			</div>
+			<div class="option">
+				<label for="autoSaveDiscardInput" id="autoSaveDiscardLabel"></label>
+				<input type="checkbox" id="autoSaveDiscardInput">
+			</div>
 			<div class="option">
 			<div class="option">
 				<label for="autoSaveDelayInput" id="autoSaveDelayLabel"></label>
 				<label for="autoSaveDelayInput" id="autoSaveDelayLabel"></label>
 				<input type="number" id="autoSaveDelayInput" min="0">
 				<input type="number" id="autoSaveDelayInput" min="0">