I have now been able to read for the clipboard with this function for my addon:
function readClipboard() {
field = document.activeElement;
var area = document.getElementById("fcb_txt_area");
if (area) {
// console.log("Found existing area");
//area.setAttribute("style", "visibility:visible;");
area.setAttribute("style", "display:inline;");
} else {
// console.log("Creating new area");
area = document.createElement("textarea");
area.setAttribute("id", "fcb_txt_area");
if (field) {
field.parentNode.append(area);
} else {
document.body.appendChild(area);
}
area.contentEditable = true;
}
area.textContent = '';
area.select();
//console.log('Pre-paste: ' + area.value);
//console.log(document.execCommand("paste"));
document.execCommand("paste");
var value = area.value;
//console.log('Post-paste: ' + area.value);
area.setAttribute("style", "display:none");
console.log("Clipboard Contents: ",value);
return value;
}
It works properly, , but only on single lines of text or html:
On a single line of text, I get:
Clipboard Contents: "https://discourse.mozilla.org/c"
On a single line of html, I get:
Unknown property âzoomâ. Declaration dropped.
On multiline text, I get:
Clipboard Contents: line1line2line3
but I copied:
line1
line2
line3
With MS word, I copy, and I get: (Just copying one word, âtryâ)
Clipboard Contents: content_script.js:70:5
Unknown property âmso-ascii-theme-fontâ. Declaration dropped. posting.php
Unknown property âmso-fareast-font-familyâ. Declaration dropped. posting.php
Unknown property âmso-fareast-theme-fontâ. Declaration dropped. posting.php
Unknown property âmso-hansi-theme-fontâ. Declaration dropped.
âŚâŚâŚ
Which is pretty clearly the function choking on MS Wordâs bloated style/html defaults.
My questions re:
How do read the clipboard contents and preserve new lines, and how do I clean up/decrapify things like html and word?