I would like to be able to have 2 buttons in my admin panel. One to copy my text as "pure text". And one button to copy my text while adding extra html tags( AND
). I do a lot of copy and paste for my work, and this would really help me work a bit faster.
Let's say you have this array:
let array = [{'head': 1, 'body': 'This is the body 1', 'content': 'This is the content 1'},{'head': 2, 'body': 'This is the body 2', 'content': 'This is the content 2'},{'head': 3, 'body': 'This is the body 3', 'content': 'This is the content 3'}]
In this array, I would like to copy /paste the content(from the above array) like this to a text file:
This is the body 1
This is the content 1
This is the body 2
This is the content 2
This is the body 3
This is the content 3
(The <br> cannot be visible on the text file...it needs to be a blank space that works in a .txt format, could this " " works?)
The second button should also copy the text from the array but surrounds the body and content with the below tags:
<h2>This is the body 1</h2>
<p>This is the content 1</p>
<br>
<h2>This is the body 2</h2>
<p>This is the content 2</p>
<br>
<h2>This is the body 3</h2>
<p>This is the content 3</p>
At the moment, I am here:
function copyToClipboard(){
let array = [{'head': 1, 'body': 'This is the body 1', 'content': 'This is the content 1'},{'head': 2, 'body': 'This is the body 2', 'content': 'This is the content 2'},{'head': 3, 'body': 'This is the body 3', 'content': 'This is the content 3'}]
//Copy(clipboard) Text only
var text = "";
//For Text only
for (let i = 0; i < array.length; i++) {
text += array[i]['body'] + " " + array[i]['content'] + " ";
}
//Copy(clipboard) Text with html tags
for (let i = 0; i < array.length; i++) {
text += "<h2>" + array[i]['body'] + "</h2>" + "<p>" + array[i]['content'] + "</p>";
}
navigator.clipboard.writeText(text).then(() => {
alert("Copied to clipboard");
console.log("Copied to clipboard");
})
}
I am not sure if I am going in the right direction.
Thanks for your help