2023-02-14 17:44:04 +00:00
|
|
|
|
|
|
|
/* addFormattingCopyButtons(): creates a button in the first column of each row of a table
|
|
|
|
that copies the text in the second column of that row */
|
|
|
|
function addFormattingCopyButtons() {
|
2023-09-28 23:58:09 +00:00
|
|
|
let allTablesGenerateCopyButtons = document.getElementsByClassName('generate-copy-buttons')
|
2023-02-14 17:44:04 +00:00
|
|
|
|
|
|
|
for (let table = 0; table < allTablesGenerateCopyButtons.length; table++) {
|
|
|
|
|
2023-08-06 03:33:34 +00:00
|
|
|
if (allTablesGenerateCopyButtons[table].tagName != 'TABLE') {
|
2023-02-14 17:44:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-09-28 23:58:09 +00:00
|
|
|
for (let i = 1, row; row = allTablesGenerateCopyButtons[table].rows[i]; i++) {
|
2023-02-14 17:44:04 +00:00
|
|
|
|
2023-02-18 15:58:08 +00:00
|
|
|
const textCopyButton = document.createElement("button");
|
2023-02-14 17:44:04 +00:00
|
|
|
textCopyButton.setAttribute("type", "button");
|
2023-02-18 15:58:08 +00:00
|
|
|
textCopyButton.className = "btn caction ml-1 py-0 nobackground px-1 text-muted copy-link";
|
2023-02-14 17:44:04 +00:00
|
|
|
|
|
|
|
/* replace HTML newlines with text newlines */
|
2023-09-28 23:58:09 +00:00
|
|
|
let cleanedText = row.cells[1].cloneNode(true)
|
2023-02-14 17:44:04 +00:00
|
|
|
cleanedText.innerHTML = cleanedText.innerHTML.replace(/<br>/gi, "\n")
|
|
|
|
/* remove lots of extraneous tabs */
|
|
|
|
cleanedText = cleanedText.textContent.replace(/\t/g,'');
|
|
|
|
textCopyButton.setAttribute("data-clipboard-text", cleanedText);
|
|
|
|
|
|
|
|
copyIcon = document.createElement("i");
|
|
|
|
copyIcon.className = "fas fa-copy";
|
|
|
|
|
|
|
|
textCopyButton.insertAdjacentElement('afterbegin', copyIcon)
|
2023-02-18 15:58:08 +00:00
|
|
|
|
|
|
|
const textCopyButtonDiv = document.createElement("div");
|
|
|
|
textCopyButtonDiv.appendChild(textCopyButton);
|
|
|
|
textCopyButtonDiv.className = "mr-4 ml-auto my-auto";
|
|
|
|
|
2023-04-25 11:19:00 +00:00
|
|
|
const x = row.cells[1].innerHTML
|
|
|
|
row.cells[1].innerHTML = `<div class="d-flex">${x}${textCopyButtonDiv.outerHTML}</div>`
|
2023-02-14 17:44:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addFormattingCopyButtons();
|