Procházet zdrojové kódy

update and integrate changes in `single-file-core`

Gildas před 2 roky
rodič
revize
c1e4ef0136

+ 0 - 1
lib/single-file-extension-infobar.js

@@ -1 +0,0 @@
-!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).infobar={})}(this,(function(e){"use strict";const t=globalThis.browser;e.getScript=async function(){if(t&&t.runtime&&t.runtime.getURL){return"<script>document.currentScript.remove();"+await(await fetch(t.runtime.getURL("/lib/single-file-infobar.js"))).text()+"<\/script>"}},Object.defineProperty(e,"__esModule",{value:!0})}));

+ 13 - 8
package-lock.json

@@ -10,7 +10,7 @@
 			"license": "AGPL-3.0-or-later",
 			"dependencies": {
 				"single-file-cli": "1.0.58",
-				"single-file-core": "1.0.64"
+				"single-file-core": "1.0.66"
 			},
 			"bin": {
 				"single-file": "cli/single-file"
@@ -186,9 +186,9 @@
 			}
 		},
 		"node_modules/@rollup/pluginutils": {
-			"version": "5.0.2",
-			"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz",
-			"integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==",
+			"version": "5.0.3",
+			"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.3.tgz",
+			"integrity": "sha512-hfllNN4a80rwNQ9QCxhxuHCGHMAvabXqxNdaChUSSadMre7t4iEUI6fFAhBOn/eIYTgYVhBv7vCLsAJ4u3lf3g==",
 			"dev": true,
 			"dependencies": {
 				"@types/estree": "^1.0.0",
@@ -227,9 +227,9 @@
 			"dev": true
 		},
 		"node_modules/@types/node": {
-			"version": "20.4.9",
-			"resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.9.tgz",
-			"integrity": "sha512-8e2HYcg7ohnTUbHk8focoklEQYvemQmu9M/f43DZVx43kHn0tE3BY/6gSDxS7k0SprtS0NHvj+L80cGLnoOUcQ==",
+			"version": "20.5.0",
+			"resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.0.tgz",
+			"integrity": "sha512-Mgq7eCtoTjT89FqNoTzzXg2XvCi5VMhRV6+I2aYanc6kQCBImeNaAYRs/DyoVqk1YEUJK5gN9VO7HRIdz4Wo3Q==",
 			"devOptional": true
 		},
 		"node_modules/@types/resolve": {
@@ -1657,11 +1657,16 @@
 				"single-file": "single-file"
 			}
 		},
-		"node_modules/single-file-core": {
+		"node_modules/single-file-cli/node_modules/single-file-core": {
 			"version": "1.0.64",
 			"resolved": "https://registry.npmjs.org/single-file-core/-/single-file-core-1.0.64.tgz",
 			"integrity": "sha512-CTySJ6ZT89Dts66GFYBOOwQnbYbL9n53IXyWegcU08R5cM1JS9S8e7oxNJ35zu6A20e4sP5Sy77tBeZlJxIkLg=="
 		},
+		"node_modules/single-file-core": {
+			"version": "1.0.66",
+			"resolved": "https://registry.npmjs.org/single-file-core/-/single-file-core-1.0.66.tgz",
+			"integrity": "sha512-IXgWQjDWTOejH91TcH6S4yyXd7fvrskc8NljxDrGHjJiRyJI+XjCdja8WIsC5sp6EV1b866+52GwrQdDHELUiw=="
+		},
 		"node_modules/smart-buffer": {
 			"version": "4.2.0",
 			"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",

+ 1 - 1
package.json

@@ -12,7 +12,7 @@
 		"single-file": "./cli/single-file"
 	},
 	"dependencies": {
-		"single-file-core": "1.0.64",
+		"single-file-core": "1.0.66",
 		"single-file-cli": "1.0.58"
 	},
 	"devDependencies": {

+ 6 - 14
rollup.config.dev.js

@@ -53,13 +53,15 @@ export default [{
 	plugins: PLUGINS,
 	external: EXTERNAL
 }, {
-	input: ["src/core/content/content-infobar.js"],
+	input: ["single-file-core/single-file-mini-helper.js"],
 	output: [{
-		file: "lib/single-file-extension-infobar.js",
+		file: "lib/single-file-extension-editor-helper.js",
 		format: "umd",
-		name: "infobar",
+		name: "singlefile",
 		plugins: []
-	}]
+	}],
+	plugins: PLUGINS,
+	external: EXTERNAL
 }, {
 	input: ["src/core/content/content-bootstrap.js"],
 	output: [{
@@ -103,16 +105,6 @@ export default [{
 		format: "iife",
 		plugins: []
 	}]
-}, {
-	input: ["src/ui/content/content-ui-editor-helper-web"],
-	output: [{
-		file: "lib/single-file-extension-editor-helper.js",
-		format: "umd",
-		name: "singlefile",
-		plugins: []
-	}],
-	plugins: PLUGINS,
-	external: EXTERNAL
 }, {
 	input: ["src/lib/single-file/browser-polyfill/chrome-browser-polyfill.js"],
 	output: [{

+ 6 - 14
rollup.config.js

@@ -53,13 +53,15 @@ export default [{
 	plugins: PLUGINS,
 	external: EXTERNAL
 }, {
-	input: ["src/core/content/content-infobar.js"],
+	input: ["single-file-core/single-file-mini-helper.js"],
 	output: [{
-		file: "lib/single-file-extension-infobar.js",
+		file: "lib/single-file-extension-editor-helper.js",
 		format: "umd",
-		name: "infobar",
+		name: "singlefile",
 		plugins: [terser()]
-	}]
+	}],
+	plugins: PLUGINS,
+	external: EXTERNAL
 }, {
 	input: ["src/core/content/content-bootstrap.js"],
 	output: [{
@@ -103,16 +105,6 @@ export default [{
 		format: "iife",
 		plugins: []
 	}]
-}, {
-	input: ["src/ui/content/content-ui-editor-helper-web"],
-	output: [{
-		file: "lib/single-file-extension-editor-helper.js",
-		format: "umd",
-		name: "singlefile",
-		plugins: [terser()]
-	}],
-	plugins: PLUGINS,
-	external: EXTERNAL
 }, {
 	input: ["src/lib/single-file/browser-polyfill/chrome-browser-polyfill.js"],
 	output: [{

+ 1 - 4
src/core/bg/autosave.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, infobar, URL, Blob */
+/* global browser, URL, Blob */
 
 import * as config from "./config.js";
 import * as business from "./business.js";
@@ -160,9 +160,6 @@ async function saveContent(message, tab) {
 					enableReferrerOnError();
 				}
 				pageData = await getPageData(options, null, null, { fetch });
-				if (options.includeInfobar) {
-					pageData.content += await infobar.getScript();
-				}
 				if (options.saveToGDrive) {
 					const blob = new Blob([pageData.content], { type: "text/html" });
 					await downloads.saveToGDrive(message.taskId, downloads.encodeSharpCharacter(pageData.filename), blob, options, {

+ 0 - 1
src/core/bg/background.html

@@ -10,7 +10,6 @@
 	<script src="/lib/chrome-browser-polyfill.js"></script>
 	<script src="/lib/single-file-extension-background.js"></script>
 	<script src="/lib/single-file.js"></script>
-	<script src="/lib/single-file-extension-infobar.js"></script>
 </body>
 
 </html>

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

@@ -40,7 +40,6 @@ const TASK_PENDING_STATE = "pending";
 const TASK_PROCESSING_STATE = "processing";
 
 const extensionScriptFiles = [
-	"lib/single-file-extension-infobar.js",
 	"lib/single-file-extension.js"
 ];
 

+ 1 - 4
src/core/common/download.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, infobar, document, URL, Blob, MouseEvent, setTimeout, open */
+/* global browser, document, URL, Blob, MouseEvent, setTimeout, open */
 
 const MAX_CONTENT_SIZE = 32 * (1024 * 1024);
 
@@ -33,9 +33,6 @@ async function downloadPage(pageData, options) {
 	if (options.includeBOM) {
 		pageData.content = "\ufeff" + pageData.content;
 	}
-	if (options.includeInfobar) {
-		pageData.content += await infobar.getScript();
-	}
 	if (options.backgroundSave || options.openEditor || options.saveToGDrive || options.saveToGitHub || options.saveWithCompanion || options.saveWithWebDAV) {
 		for (let blockIndex = 0; blockIndex * MAX_CONTENT_SIZE < pageData.content.length; blockIndex++) {
 			const message = {

+ 0 - 4
src/core/content/content-bootstrap.js

@@ -219,10 +219,6 @@ function savePage(docData, frames, { autoSaveUnload, autoSaveDiscard, autoSaveRe
 }
 
 async function openEditor(document) {
-	const infobarElement = document.querySelector("singlefile-infobar");
-	if (infobarElement) {
-		infobarElement.remove();
-	}
 	serializeShadowRoots(document);
 	const content = singlefile.helper.serialize(document);
 	for (let blockIndex = 0; blockIndex * MAX_CONTENT_SIZE < content.length; blockIndex++) {

+ 0 - 39
src/core/content/content-infobar.js

@@ -1,39 +0,0 @@
-/*
- * Copyright 2010-2020 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 globalThis, fetch */
-
-const SCRIPT_PATH = "/lib/single-file-infobar.js";
-
-const browser = globalThis.browser;
-
-export {
-	getScript
-};
-
-async function getScript() {
-	if (browser && browser.runtime && browser.runtime.getURL) {
-		const infobarContent = await (await fetch(browser.runtime.getURL(SCRIPT_PATH))).text();
-		return "<script>document.currentScript.remove();" + infobarContent + "</script>";
-	}
-}

+ 5 - 1
src/ui/bg/ui-editor.js

@@ -408,7 +408,10 @@ function enableEditPage() {
 function formatPage() {
 	formatPageButton.classList.remove("format-disabled");
 	updatedResources = {};
-	editorElement.contentWindow.postMessage(JSON.stringify({ method: tabData.options.applySystemTheme ? "formatPage" : "formatPageNoTheme" }), "*");
+	editorElement.contentWindow.postMessage(JSON.stringify({
+		method: "formatPage",
+		applySystemTheme: tabData.options.applySystemTheme
+	}), "*");
 }
 
 function cancelFormatPage() {
@@ -437,6 +440,7 @@ function savePage() {
 	editorElement.contentWindow.postMessage(JSON.stringify({
 		method: "getContent",
 		compressHTML: tabData.options.compressHTML,
+		includeInfobar: tabData.options.includeInfobar,
 		updatedResources,
 		filename: tabData.filename,
 		foregroundSave: FOREGROUND_SAVE

+ 0 - 34
src/ui/content/content-ui-editor-helper-web.js

@@ -1,34 +0,0 @@
-/*
- * Copyright 2010-2020 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.
- */
-
-import * as serializer from "single-file-core/modules/html-serializer.js";
-
-const helper = {
-	serialize(doc, compressHTML) {
-		return serializer.process(doc, compressHTML);
-	}
-};
-
-export {
-	helper
-};

+ 12 - 7
src/ui/content/content-ui-editor-web.js

@@ -974,7 +974,7 @@ pre code {
 
 	let NOTES_WEB_STYLESHEET, MASK_WEB_STYLESHEET, HIGHLIGHTS_WEB_STYLESHEET;
 	let selectedNote, anchorElement, maskNoteElement, maskPageElement, highlightSelectionMode, removeHighlightMode, resizingNoteMode, movingNoteMode, highlightColor, collapseNoteTimeout, cuttingOuterMode, cuttingMode, cuttingTouchTarget, cuttingPath, cuttingPathIndex, previousContent;
-	let removedElements = [], removedElementIndex = 0, initScriptContent;
+	let removedElements = [], removedElementIndex = 0, initScriptContent, includeInfobar;
 
 	window.onmessage = async event => {
 		const message = JSON.parse(event.data);
@@ -1021,10 +1021,7 @@ pre code {
 			onUpdate(false);
 		}
 		if (message.method == "formatPage") {
-			formatPage(true);
-		}
-		if (message.method == "formatPageNoTheme") {
-			formatPage(false);
+			formatPage(!message.applySystemTheme);
 		}
 		if (message.method == "cancelFormatPage") {
 			cancelFormatPage();
@@ -1067,6 +1064,7 @@ pre code {
 		}
 		if (message.method == "getContent") {
 			onUpdate(true);
+			includeInfobar = message.includeInfobar;
 			let content = getContent(message.compressHTML, message.updatedResources);
 			if (initScriptContent) {
 				content = content.replace(/<script data-template-shadow-root src.*?<\/script>/g, initScriptContent);
@@ -1087,7 +1085,7 @@ pre code {
 			printPage();
 		}
 		if (message.method == "displayInfobar") {
-			singlefile.infobar.displayIcon();
+			singlefile.helper.displayIcon(document, true);
 		}
 	};
 	window.onresize = reflowNotes;
@@ -1119,6 +1117,10 @@ pre code {
 			} else if (document.doctype) {
 				document.doctype.remove();
 			}
+			const infobarElement = contentDocument.querySelector(singlefile.helper.INFOBAR_TAGNAME);
+			if (infobarElement) {
+				infobarElement.remove();
+			}
 			contentDocument.querySelectorAll("noscript").forEach(element => {
 				element.setAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME, element.innerHTML);
 				element.textContent = "";
@@ -1906,7 +1908,10 @@ pre code {
 			element.textContent = element.getAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME);
 			element.removeAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME);
 		});
-		doc.querySelectorAll("." + MASK_CLASS + ", ." + REMOVED_CONTENT_CLASS).forEach(maskElement => maskElement.remove());
+		doc.querySelectorAll("." + MASK_CLASS + ", " + singlefile.helper.INFOBAR_TAGNAME + ", ." + REMOVED_CONTENT_CLASS).forEach(maskElement => maskElement.remove());
+		if (includeInfobar) {
+			singlefile.helper.appendInfobar(doc, singlefile.helper.extractInfobarData(doc));
+		}
 		doc.querySelectorAll("." + HIGHLIGHT_CLASS).forEach(noteElement => noteElement.classList.remove(HIGHLIGHT_HIDDEN_CLASS));
 		doc.querySelectorAll(`template[${SHADOWROOT_ATTRIBUTE_NAME}]`).forEach(templateElement => {
 			const noteElement = templateElement.querySelector("." + NOTE_CLASS);

+ 1 - 2
src/ui/pages/editor.html

@@ -68,11 +68,10 @@
 		</div>
 	</div>
 	<iframe class="editor"
-		srcdoc="&lt;!DOCTYPE html&gt;&lt;body&gt;&lt;script src=/lib/single-file-extension-editor-helper.js&gt;&lt;/script&gt;&lt;script src=/lib/single-file-extension-editor.js&gt;&lt;/script&gt;&lt;script src=/lib/single-file-infobar.js&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability.js&gt;&lt;/script&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability-readerable.js&gt;&lt;/script&gt;&lt;/script&gt;&lt;/script&gt;&lt;/body&gt;"
+		srcdoc="&lt;!DOCTYPE html&gt;&lt;body&gt;&lt;script src=/lib/single-file-extension-editor-helper.js&gt;&lt;/script&gt;&lt;script src=/lib/single-file-extension-editor.js&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability.js&gt;&lt;/script&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability-readerable.js&gt;&lt;/script&gt;&lt;/script&gt;&lt;/script&gt;&lt;/body&gt;"
 		sandbox="allow-scripts allow-modals"></iframe>
 	<script src="/lib/chrome-browser-polyfill.js"></script>
 	<script src="/lib/single-file.js"></script>
-	<script src="/lib/single-file-extension-infobar.js"></script>
 	<script type="module" src="/src/ui/bg/ui-editor.js"></script>
 </body>