//https://www.boe.es/buscar/act.php?id=BOE-A-2002-18099
function copyToClipboard(text) {
const el = document.createElement('textarea');
el.value = text;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
console.log('Data copied to clipboard.');
}
var headers = document.querySelectorAll('h3, h4, h5');
var plainText = '';
for (var i = 0; i < headers.length; i++) {
var header = headers[i];
var correspondingParagraph = header.nextElementSibling;
var codeBefore = '';
var codeAfter = '';
while (correspondingParagraph) {
if (
correspondingParagraph.nodeName === 'P' &&
correspondingParagraph.classList.length > 0 &&
correspondingParagraph.textContent.includes('motor')
) {
var prevSibling = correspondingParagraph.previousElementSibling;
var nextSibling = correspondingParagraph.nextElementSibling;
if (prevSibling && prevSibling.tagName === 'P') {
codeBefore = prevSibling.textContent;
}
if (nextSibling && nextSibling.tagName === 'P') {
codeAfter = nextSibling.textContent;
}
plainText += header.textContent + ':\n';
plainText += codeBefore + '\n';
plainText += correspondingParagraph.textContent + '\n';
plainText += codeAfter + '\n';
break;
}
correspondingParagraph = correspondingParagraph.nextElementSibling;
}
}
copyToClipboard(plainText);
No hay comentarios:
Publicar un comentario