Gildas преди 6 години
родител
ревизия
4d0fc878a9
променени са 4 файла, в които са добавени 7 реда и са изтрити 69 реда
  1. 0 41
      extension/core/content/content-download.js
  2. 6 16
      extension/core/content/content-main.js
  3. 0 9
      extension/core/pages/downloader.html
  4. 1 3
      manifest.json

+ 0 - 41
extension/core/content/content-download.js

@@ -1,41 +0,0 @@
-/*
- * Copyright 2010-2019 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 addEventListener, removeEventListener, document, URL, MouseEvent, Blob */
-
-(() => {
-
-	addEventListener("message", listener, false);
-
-	function listener(event) {
-		removeEventListener("message", listener, false);
-		const [filename, content] = JSON.parse(event.data);
-		const link = document.createElement("a");
-		link.download = filename;
-		link.href = URL.createObjectURL(new Blob([content], { type: "text/html" }));
-		document.body.appendChild(link);
-		link.dispatchEvent(new MouseEvent("click"));
-		URL.revokeObjectURL(link.href);
-	}
-
-})();

+ 6 - 16
extension/core/content/content-main.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, document, window, setTimeout */
+/* global browser, document, window, setTimeout, URL, Blob, MouseEvent */
 
 this.singlefile.extension.core.content.main = this.singlefile.extension.core.content.main || (() => {
 
@@ -30,7 +30,6 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 	let ui;
 
 	const MAX_CONTENT_SIZE = 64 * (1024 * 1024);
-	const DOWNLOADER_FRAME_ID = "single-file-downloader";
 	const SingleFile = singlefile.lib.SingleFile.getClass();
 
 	let processing = false;
@@ -72,10 +71,6 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 	async function processPage(options) {
 		const frames = singlefile.lib.frameTree.content.frames;
 		singlefile.lib.helper.initDoc(document);
-		const iframe = document.getElementById(DOWNLOADER_FRAME_ID);
-		if (iframe) {
-			iframe.remove();
-		}
 		ui.onStartPage(options);
 		const processor = new SingleFile(options);
 		const preInitializationPromises = [];
@@ -202,16 +197,11 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 			page.filename = ui.prompt("File name", page.filename);
 		}
 		if (page.filename && page.filename.length) {
-			const iframe = document.createElement("iframe");
-			iframe.id = DOWNLOADER_FRAME_ID;
-			iframe.style.setProperty("display", "inline-block", "important");
-			iframe.style.setProperty("max-width", "0", "important");
-			iframe.style.setProperty("max-height", "0", "important");
-			iframe.style.setProperty("border-width", "0", "important");
-			iframe.style.setProperty("margin", "0", "important");
-			iframe.src = browser.runtime.getURL("/extension/core/pages/downloader.html");
-			iframe.onload = () => iframe.contentWindow.postMessage(JSON.stringify([page.filename, page.content]), "*");
-			document.body.appendChild(iframe);
+			const link = document.createElement("a");
+			link.download = page.filename;
+			link.href = URL.createObjectURL(new Blob([page.content], { type: "text/html" }));
+			link.dispatchEvent(new MouseEvent("click"));
+			URL.revokeObjectURL(link.href);
 		}
 	}
 

+ 0 - 9
extension/core/pages/downloader.html

@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-    <title>SingleFile</title>
-</head>
-<body>
-    <script src="/extension/core/content/content-download.js"></script>
-</body>
-</html>

+ 1 - 3
manifest.json

@@ -120,9 +120,7 @@
 	},
 	"web_accessible_resources": [
 		"lib/hooks/content/content-hooks-web.js",
-		"lib/hooks/content/content-hooks-frames-web.js",
-		"extension/core/content/content-download.js",
-		"extension/core/pages/downloader.html"
+		"lib/hooks/content/content-hooks-frames-web.js"
 	],
 	"permissions": [
 		"menus",