ソースを参照

merged compress CSS and HTML options

Gildas 7 年 前
コミット
90a5deb8d9

+ 4 - 8
extension/core/bg/config.js

@@ -29,8 +29,7 @@ singlefile.config = (() => {
 		removeImports: true,
 		removeScripts: true,
 		rawDocument: false,
-		compressHTML: true,
-		compressCSS: true,
+		compress: true,
 		lazyLoadImages: true,
 		appendSaveDate: true,
 		confirmFilename: false,
@@ -54,7 +53,7 @@ singlefile.config = (() => {
 		} else {
 			pendingUpgradePromise = new Promise(resolve => browser.storage.local.get(config => {
 				upgradeConfig(config);
-				resolve();
+				browser.storage.local.set(config, resolve);
 			}));
 		}
 	}
@@ -63,11 +62,8 @@ singlefile.config = (() => {
 		if (config.removeScripts === undefined) {
 			config.removeScripts = true;
 		}
-		if (config.compressHTML === undefined) {
-			config.compressHTML = true;
-		}
-		if (config.compressCSS === undefined) {
-			config.compressCSS = true;
+		if (config.compress === undefined) {
+			config.compress = true;
 		}
 		if (config.lazyLoadImages === undefined) {
 			config.lazyLoadImages = true;

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

@@ -31,8 +31,7 @@
 		const removeImportsInput = document.getElementById("removeImportsInput");
 		const removeScriptsInput = document.getElementById("removeScriptsInput");
 		const saveRawPageInput = document.getElementById("saveRawPageInput");
-		const compressHTMLInput = document.getElementById("compressHTMLInput");
-		const compressCSSInput = document.getElementById("compressCSSInput");
+		const compressInput = document.getElementById("compressInput");
 		const lazyLoadImagesInput = document.getElementById("lazyLoadImagesInput");
 		const contextMenuEnabledInput = document.getElementById("contextMenuEnabledInput");
 		const appendSaveDateInput = document.getElementById("appendSaveDateInput");
@@ -58,8 +57,7 @@
 			removeImportsInput.checked = config.removeImports;
 			removeScriptsInput.checked = config.removeScripts;
 			saveRawPageInput.checked = config.saveRawPage;
-			compressHTMLInput.checked = config.compressHTML;
-			compressCSSInput.checked = config.compressCSS;
+			compressInput.checked = config.compress;
 			lazyLoadImagesInput.checked = config.lazyLoadImages;
 			contextMenuEnabledInput.checked = config.contextMenuEnabled;
 			appendSaveDateInput.checked = config.appendSaveDate;
@@ -79,8 +77,7 @@
 				removeImports: removeImportsInput.checked,
 				removeScripts: removeScriptsInput.checked,
 				saveRawPage: saveRawPageInput.checked,
-				compressHTML: compressHTMLInput.checked,
-				compressCSS: compressCSSInput.checked,
+				compress: compressInput.checked,
 				lazyLoadImages: lazyLoadImagesInput.checked,
 				contextMenuEnabled: contextMenuEnabledInput.checked,
 				appendSaveDate: appendSaveDateInput.checked,

+ 3 - 10
extension/ui/pages/help.html

@@ -84,16 +84,9 @@
 					</li>
 
 					<li>
-						<span class="option">compress HTML</span>
-						<p>Check this option to remove all HTML comments, and unneeded spaces or returns. This helps to reduce the size of the
-							file without altering the document.</p>
-						<p class="notice">It is recommended to
-							<u>check</u> this option</p>
-					</li>
-
-					<li>
-						<span class="option">compress CSS</span>
-						<p>Check this option to minify the CSS content. This helps to reduce the size of the file without altering the document.</p>
+						<span class="option">compress HTML and CSS</span>
+						<p>Check this option to minify CSS stylesheets and remove all HTML comments, and unneeded spaces or returns. This helps
+							to reduce the size of the file without altering the document.</p>
 						<p class="notice">It is recommended to
 							<u>check</u> this option</p>
 					</li>

+ 2 - 6
extension/ui/pages/options.html

@@ -35,12 +35,8 @@
 				<input type="checkbox" id="lazyLoadImagesInput">
 			</div>
 			<div class="option">
-				<label for="compressHTMLInput">compress HTML</label>
-				<input type="checkbox" id="compressHTMLInput">
-			</div>
-			<div class="option">
-				<label for="compressCSSInput">compress CSS</label>
-				<input type="checkbox" id="compressCSSInput">
+				<label for="compressInput">compress HTML and CSS</label>
+				<input type="checkbox" id="compressInput">
 			</div>
 			<div class="option">
 				<label for="removeFramesInput">remove frames</label>

+ 5 - 6
lib/single-file/single-file-core.js

@@ -102,7 +102,7 @@ const SingleFileCore = (() => {
 			}
 			this.processor.removeDiscardedResources();
 			this.processor.resetCharsetMeta();
-			if (this.options.compressHTML) {
+			if (this.options.compress) {
 				this.processor.compressHTML();
 			}
 			if (this.options.insertFaviconLink) {
@@ -357,7 +357,7 @@ const SingleFileCore = (() => {
 				if (style.sheet) {
 					DomProcessorHelper.processRules(this.doc, style.sheet.cssRules, cssRules);
 					const stylesheetContent = cssRules.join("");
-					style.textContent = this.options.compressCSS ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
+					style.textContent = this.options.compress ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
 				}
 			});
 		}
@@ -440,7 +440,7 @@ const SingleFileCore = (() => {
 		async inlineStylesheets(initialization) {
 			await Promise.all(Array.from(this.doc.querySelectorAll("style")).map(async styleElement => {
 				const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled }) : await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
-				styleElement.textContent = this.options.compressCSS && !this.options.removeUnusedCSSRules ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
+				styleElement.textContent = this.options.compress && !this.options.removeUnusedCSSRules ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
 			}));
 		}
 
@@ -506,8 +506,7 @@ const SingleFileCore = (() => {
 						jsEnabled: this.options.jsEnabled,
 						removeScripts: this.options.removeScripts,
 						saveRawPage: this.options.saveRawPage,
-						compressHTML: this.options.compressHTML,
-						compressCSS: this.options.compressCSS,
+						compress: this.options.compress,
 						lazyLoadImages: this.options.lazyLoadImages,
 						framesData: this.options.framesData
 					};
@@ -543,7 +542,7 @@ const SingleFileCore = (() => {
 			await Promise.all(Array.from(this.doc.querySelectorAll("link[rel*=stylesheet]")).map(async linkElement => {
 				const stylesheetContent = await DomProcessorHelper.resolveLinkStylesheetURLs(linkElement.href, this.baseURI, linkElement.media, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
 				const styleElement = this.doc.createElement("style");
-				styleElement.textContent = this.options.compressCSS && !this.options.removeUnusedCSSRules ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
+				styleElement.textContent = this.options.compress && !this.options.removeUnusedCSSRules ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
 				linkElement.parentElement.replaceChild(styleElement, linkElement);
 			}));
 		}