فهرست منبع

save in foreground in Safari

Gildas 3 سال پیش
والد
کامیت
ef2646e0d4
2فایلهای تغییر یافته به همراه22 افزوده شده و 4 حذف شده
  1. 10 2
      src/ui/bg/ui-editor.js
  2. 12 2
      src/ui/content/content-ui-editor-web.js

+ 10 - 2
src/ui/bg/ui-editor.js

@@ -21,11 +21,13 @@
  *   Source.
  */
 
-/* global browser, document, matchMedia, addEventListener */
+/* global browser, document, matchMedia, addEventListener, navigator */
 
 import * as download from "../../core/common/download.js";
 import { onError } from "./../common/content-error.js";
 
+const FOREGROUND_SAVE = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent);
+
 const editorElement = document.querySelector(".editor");
 const toolbarElement = document.querySelector(".toolbar");
 const highlightYellowButton = document.querySelector(".highlight-yellow-button");
@@ -428,7 +430,13 @@ function enableCutOuterPage() {
 }
 
 function savePage() {
-	editorElement.contentWindow.postMessage(JSON.stringify({ method: "getContent", compressHTML: tabData.options.compressHTML, updatedResources }), "*");
+	editorElement.contentWindow.postMessage(JSON.stringify({
+		method: "getContent",
+		compressHTML: tabData.options.compressHTML,
+		updatedResources,
+		filename: tabData.filename,
+		foregroundSave: FOREGROUND_SAVE
+	}), "*");
 }
 
 function getPosition(event) {

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

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global globalThis, window, document, fetch, DOMParser, getComputedStyle, setTimeout, clearTimeout, NodeFilter, Readability, isProbablyReaderable, matchMedia, TextDecoder, Node */
+/* global globalThis, window, document, fetch, DOMParser, getComputedStyle, setTimeout, clearTimeout, NodeFilter, Readability, isProbablyReaderable, matchMedia, TextDecoder, Node, URL, MouseEvent */
 
 (globalThis => {
 
@@ -1077,7 +1077,17 @@ pre code {
 			if (initScriptContent) {
 				content = content.replace(/<script data-template-shadow-root src.*?<\/script>/g, initScriptContent);
 			}
-			window.parent.postMessage(JSON.stringify({ method: "setContent", content }), "*");
+			if (message.foregroundSave) {
+				if (message.filename && message.filename.length) {
+					const link = document.createElement("a");
+					link.download = message.filename;
+					link.href = URL.createObjectURL(new Blob([content], { type: "text/html" }));
+					link.dispatchEvent(new MouseEvent("click"));
+				}
+				return new Promise(resolve => setTimeout(resolve, 1));
+			} else {
+				window.parent.postMessage(JSON.stringify({ method: "setContent", content }), "*");
+			}
 		}
 		if (message.method == "printPage") {
 			printPage();