ソースを参照

added "group duplicate images together" option

Gildas 7 年 前
コミット
94739a4212

+ 4 - 0
_locales/en/messages.json

@@ -135,6 +135,10 @@
         "message": "Images",
         "description": "Options sub-title: 'Images'"
     },
+    "optionGroupDuplicateImages": {
+        "message": "group duplicate images together",
+        "description": "Options page label: 'group duplicate images together'"
+    },
     "optionLazyLoadImages": {
         "message": "save deferred images",
         "description": "Options page label: 'save deferred images'"

+ 4 - 0
_locales/fr/messages.json

@@ -135,6 +135,10 @@
         "message": "Images",
         "description": "Options sub-title: 'Images'"
     },
+    "optionGroupDuplicateImages": {
+        "message": "regrouper les images dupliquées",
+        "description": "Options page label: 'group duplicate images together'"
+    },
     "optionLazyLoadImages": {
         "message": "sauver les images chargées de manière différées",
         "description": "Options page label: 'save deferred images'"

+ 4 - 0
_locales/ja/messages.json

@@ -135,6 +135,10 @@
         "message": "画像",
         "description": "オプションのサブタイトル: '画像'"
     },
+    "optionGroupDuplicateImages": {
+        "message": "group duplicate images together",
+        "description": "Options page label: 'group duplicate images together'"
+    },
     "optionLazyLoadImages": {
         "message": "遅延画像を保存する",
         "description": "オプションのページラベル: '遅延画像を保存する'"

+ 4 - 0
_locales/pl/messages.json

@@ -135,6 +135,10 @@
         "message": "Obrazy",
         "description": "Options sub-title: 'Images'"
     },
+    "optionGroupDuplicateImages": {
+        "message": "group duplicate images together",
+        "description": "Options page label: 'group duplicate images together'"
+    },
     "optionLazyLoadImages": {
         "message": "zapisuj odroczone obrazy",
         "description": "Options page label: 'save deferred images'"

+ 4 - 0
_locales/ru/messages.json

@@ -135,6 +135,10 @@
         "message": "Изображения",
         "description": "Options sub-title: 'Images'"
     },
+    "optionGroupDuplicateImages": {
+        "message": "group duplicate images together",
+        "description": "Options page label: 'group duplicate images together'"
+    },
     "optionLazyLoadImages": {
         "message": "сохранить отложенные изображения",
         "description": "Options page label: 'save deferred images'"

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

@@ -49,7 +49,8 @@ singlefile.config = (() => {
 		autoSaveLoadOrUnload: true,
 		removeAlternativeFonts: true,
 		removeAlternativeMedias: true,
-		removeSrcSet: true
+		removeSrcSet: true,
+		groupDuplicateImages: true
 	};
 
 	let pendingUpgradePromise;
@@ -141,6 +142,9 @@ singlefile.config = (() => {
 		if (config.removeSrcSet === undefined) {
 			config.removeSrcSet = true;
 		}
+		if (config.groupDuplicateImages === undefined) {
+			config.groupDuplicateImages = true;
+		}
 		if (config.autoSaveLoadOrUnload === undefined && !config.autoSaveUnload) {
 			config.autoSaveLoadOrUnload = true;
 			config.autoSaveLoad = false;

+ 4 - 2
extension/core/bg/script-loader.js

@@ -48,8 +48,7 @@ singlefile.scriptLoader = (() => {
 	const optionalContentScriptFiles = {
 		compressHTML: [
 			"/lib/single-file/html-minifier.js",
-			"/lib/single-file/html-serializer.js",
-			"lib/single-file/html-images-minifier.js"
+			"/lib/single-file/html-serializer.js"
 		],
 		compressCSS: [
 			"/lib/single-file/css-minifier.js"
@@ -69,6 +68,9 @@ singlefile.scriptLoader = (() => {
 		],
 		lazyLoadImages: [
 			"/lib/single-file/lazy-loader.js"
+		],
+		groupDuplicateImages: [
+			"lib/single-file/html-images-minifier.js"
 		]
 	};
 

+ 7 - 2
extension/ui/bg/options.js

@@ -58,6 +58,7 @@
 	const stylesheetsLabel = document.getElementById("stylesheetsLabel");
 	const otherResourcesLabel = document.getElementById("otherResourcesLabel");
 	const autoSaveLabel = document.getElementById("autoSaveLabel");
+	const groupDuplicateImagesLabel = document.getElementById("groupDuplicateImagesLabel");
 	const miscLabel = document.getElementById("miscLabel");
 	const helpLabel = document.getElementById("helpLabel");
 	const resetButton = document.getElementById("resetButton");
@@ -89,6 +90,7 @@
 	const removeAlternativeFontsInput = document.getElementById("removeAlternativeFontsInput");
 	const removeSrcSetInput = document.getElementById("removeSrcSetInput");
 	const removeAlternativeMediasInput = document.getElementById("removeAlternativeMediasInput");
+	const groupDuplicateImagesInput = document.getElementById("groupDuplicateImagesInput");
 	const expandAllButton = document.getElementById("expandAllButton");
 	let pendingSave = Promise.resolve();
 	resetButton.addEventListener("click", async () => {
@@ -147,6 +149,7 @@
 	removeAlternativeFontsLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeFonts");
 	removeAlternativeImagesLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeImages");
 	removeAlternativeMediasLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeMedias");
+	groupDuplicateImagesLabel.textContent = browser.i18n.getMessage("optionGroupDuplicateImages");
 	titleLabel.textContent = browser.i18n.getMessage("optionsTitle");
 	userInterfaceLabel.textContent = browser.i18n.getMessage("optionsUserInterfaceSubTitle");
 	filenameLabel.textContent = browser.i18n.getMessage("optionsFileNameSubTitle");
@@ -156,7 +159,7 @@
 	otherResourcesLabel.textContent = browser.i18n.getMessage("optionsOtherResourcesSubTitle");
 	autoSaveLabel.textContent = browser.i18n.getMessage("optionsAutoSaveSubTitle");
 	miscLabel.textContent = browser.i18n.getMessage("optionsMiscSubTitle");
-	helpLabel.textContent = browser.i18n.getMessage("optionsHelpLink");
+	helpLabel.textContent = browser.i18n.getMessage("optionsHelpLink");	
 	resetButton.textContent = browser.i18n.getMessage("optionsResetButton");
 	resetButton.title = browser.i18n.getMessage("optionsResetTooltip");
 
@@ -194,6 +197,7 @@
 		autoSaveUnloadInput.disabled = config.autoSaveLoadOrUnload;
 		removeAlternativeFontsInput.checked = config.removeAlternativeFonts;
 		removeSrcSetInput.checked = config.removeSrcSet;
+		groupDuplicateImagesInput.checked = config.groupDuplicateImages;
 		removeAlternativeMediasInput.checked = config.removeAlternativeMedias;
 	}
 
@@ -226,7 +230,8 @@
 			autoSaveLoadOrUnload: autoSaveLoadOrUnloadInput.checked,
 			removeAlternativeFonts: removeAlternativeFontsInput.checked,
 			removeSrcSet: removeSrcSetInput.checked,
-			removeAlternativeMedias: removeAlternativeMediasInput.checked
+			removeAlternativeMedias: removeAlternativeMediasInput.checked,
+			groupDuplicateImages: groupDuplicateImagesInput.checked
 		});
 		await pendingSave;
 		await bgPage.singlefile.ui.menu.refresh();

+ 13 - 6
extension/ui/pages/help.html

@@ -209,10 +209,8 @@
 					<li>
 						<span class="option">remove frames</span>
 						<p>Check this option to remove all frame and iframe elements. This can considerably reduce the size of the file
-							without
-							altering the document most of the time. Checking this this option option may also increase the time needed to
-							save
-							a page</p>
+							without altering the document most of the time. Checking this option may also increase the time needed to save a
+							page</p>
 						<p class="notice">It is recommended to
 							<u>check</u> this option</p>
 					</li>
@@ -226,6 +224,15 @@
 				</ul>
 				<p>Images</p>
 				<ul>
+					<li>
+						<span class="option">group duplicate images together</span>
+						<p>Check this option to avoid saving multiple times duplicate images. Checking this this option should not alter
+							the document in modern browsers and can considerably reduce the size of the file. Checking this this option
+							option may also increase the CPU consumption and the time needed to save a page</p>
+						<p class="notice">It is recommended to
+							<u>check</u> this option</p>
+					</li>
+
 					<li>
 						<span class="option">save deferred images</span>
 						<p>Check this option to save all the deferred images that are not displayed. This may help to save all the
@@ -256,9 +263,9 @@
 
 					<li>
 						<span class="option">remove unused styles</span>
-						<p>Check this option to remove all CSS rules and styles that do not match any element. Checking this this option
+						<p>Check this option to remove all CSS rules and styles that do not match any element. Checking this option
 							should
-							not alter the document and can considerably reduce the size of the file. Checking this this option option may
+							not alter the document and can considerably reduce the size of the file. Checking this option may
 							also
 							increase the CPU consumption and the time needed to save a page.</p>
 						<p class="notice">It is recommended to

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

@@ -55,7 +55,11 @@
 		</div>
 	</details>
 	<details>
-		<summary id="imagesLabel"></summary>
+		<summary id="imagesLabel"></summary>		
+		<div class="option">
+			<label for="groupDuplicateImagesInput" id="groupDuplicateImagesLabel"></label>
+			<input type="checkbox" id="groupDuplicateImagesInput">
+		</div>
 		<div class="option">
 			<label for="lazyLoadImagesInput" id="lazyLoadImagesLabel"></label>
 			<input type="checkbox" id="lazyLoadImagesInput">

+ 3 - 3
lib/single-file/single-file-core.js

@@ -97,7 +97,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 	}, {
 		sequential: [
 			{ option: "removeUnusedStyles", action: "removeUnusedStyles" },
-			{ option: "compressHTML", action: "minifyImages" },
+			{ option: "groupDuplicateImages", action: "groupDuplicateImages" },
 			{ option: "removeAlternativeFonts", action: "removeAlternativeFonts" },
 			{ option: "removeAlternativeMedias", action: "removeAlternativeMedias" }
 		],
@@ -581,7 +581,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 		}
 
-		minifyImages() {
+		groupDuplicateImages() {
 			if (this.options.imageData) {
 				if (!this.mediaAllInfo) {
 					this.mediaAllInfo = DOM.getMediaAllInfo(this.doc);
@@ -1023,7 +1023,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					const regExpUrlFunction = DomUtil.getRegExp(urlFunction);
 					if (!inline && options.compressCSS && dataURI.startsWith(PREFIX_DATA_URI_IMAGE) && !dataURI.startsWith(PREFIX_DATA_URI_IMAGE_SVG)) {
 						const functions = stylesheetContent.match(regExpUrlFunction);
-						if (functions && functions.length > 1) {
+						if (options.groupDuplicateImages && functions && functions.length > 1) {
 							const variableName = "--single-file-" + indexStyle + "-" + indexVariable;
 							stylesheetContent = variableName + ":url(\"" + dataURI + "\")" + (indexVariable ? ";" : "}") + stylesheetContent;
 							stylesheetContent = stylesheetContent.replace(regExpUrlFunction, "var(" + variableName + ")");