Sfoglia il codice sorgente

added save to clipbard feature in the content script

Gildas 6 anni fa
parent
commit
81d344cb45
1 ha cambiato i file con 18 aggiunte e 1 eliminazioni
  1. 18 1
      extension/core/content/content.js

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

@@ -179,7 +179,11 @@ this.singlefile.top = this.singlefile.top || (() => {
 				response = await browser.runtime.sendMessage(message);
 				response = await browser.runtime.sendMessage(message);
 			}
 			}
 		} else {
 		} 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();
+		}
+	}
+
 })();
 })();