1
0
Эх сурвалжийг харах

added save to clipbard feature in the content script

Gildas 6 жил өмнө
parent
commit
81d344cb45

+ 18 - 1
extension/core/content/content.js

@@ -179,7 +179,11 @@ this.singlefile.top = this.singlefile.top || (() => {
 				response = await browser.runtime.sendMessage(message);
 			}
 		} else {
-			downloadPageForeground(page, options);
+			if (options.saveToClipboard) {
+				saveToClipboard(page);
+			} else {
+				downloadPageForeground(page, options);
+			}
 		}
 	}
 
@@ -198,4 +202,17 @@ this.singlefile.top = this.singlefile.top || (() => {
 		}
 	}
 
+	function saveToClipboard(page) {
+		const command = "copy";
+		document.addEventListener(command, listener);
+		document.execCommand(command);
+		document.removeEventListener(command, listener);
+
+		function listener(event) {
+			event.clipboardData.setData("text/html", page.content);
+			event.clipboardData.setData("text/plain", page.content);
+			event.preventDefault();
+		}
+	}
+
 })();