Closed ridingmower closed 1 year ago
@ridingmower Currently it can be used for code blocks dynamically created by markdown, I hope it will be helpful to you, but there are also some fly in the ointment! As shown in the video below!
window.addEventListener("load", event_pageLoaded, false);
function event_pageLoaded() {
// let codeChunk = document.querySelectorAll("code:nth-child(2)");
let codeChunk = document.querySelectorAll("pre > code:nth-child(2)");
// var codeChunk = document.querySelectorAll("pre > code.hljs");
for (let i = 0; i < codeChunk.length; i++) {
let pre = codeChunk.item(i);
let btns = document.createElement("button");
// btns.insertAdjacentElement('afterend', btns);
btns.insertAdjacentHTML('afterbegin', '<i class="bi bi-clipboard text-white fs-3" data-bs-toggle="tooltip" title="复制"></i>');
btns.classList.add("btn", "btn-none");
// btn.classList.add("btn", "btn-none");
pre.appendChild(btns, pre.nextSibling);
btns.setAttribute("data-clipboard-action", "copy");
// btns.innerHTML = '<i class="bi bi-clipboard text-white fs-3" data-bs-toggle="tooltip" data-bs-placement="top" title="复制"></i>';
// btns.setAttribute("data-bs-toggle", "tooltip");
// btns.setAttribute("data-bs-placement", "top");
// btns.setAttribute("title", "复制");
// Copy to clipboard
var clipboard = new ClipboardJS('[data-clipboard-action="copy"]', {
target: function(trigger) {
return trigger.parentElement;
// return trigger.nextElementSibling;
},
});
// const ggdd = document.getElementsByClassName("bi bi-clipboard text-white fs-3");
//https://github.com/yajra/laravel-datatables/issues/741#issuecomment-245780785
clipboard.on('success', function(e) {
console.info('Action:', e.action);
// console.info('Text:', e.text);
// console.info('Trigger:', e.trigger);
// var sss = document.getElementsByClassName(".bi-clipboard");
// for (var ii = 0; ii < myNodeList.length; ii++) {
// var item = myNodeList[ii]; // 调用 myNodeList.item(i) 是没有必要的
e.clearSelection();
// }
// sss.setAttribute("class","bi bi-clipboard-check text-success fs-3")
// myNodeList.innerHTML = '<i class="bi bi-clipboard-check text-success fs-3"></i>';
// for (var checkbox of baseElement) {
// checkbox.checked = true;
// checkbox.innerHTML = '<i class="bi bi-clipboard-check text-success fs-3"></i>';
// }
//var ssds = baseElement.length;
// checkbox.innerHTML= '<i class="bi bi-clipboard-check text-success fs-3"></i>';
// btns.remove();
// btns.classList.remove("btn","bi","bi-clipboard","text-white","fs-2");
// sds.innerHTML = '<button class="" data-clipboard-copy><i class="bi bi-clipboard-check text-success fs-3"></i></button>';
// checkbox.insertAdjacentHTML('beforebegin', '<i class="bi bi-clipboard-check text-success fs-3"></i>');
// btns.innerHTML = '<i class="bi bi-clipboard-check text-success fs-3"></i>';
// btns.setAttribute('class', 'bi bi-clipboard-check text-success fs-3');
// clipboard.destroy();
// var baseElement = document.querySelector("bi bi-clipboard text-white fs-3");
// clipboard.destroy();
// e.clearSelection();
});
}
};
I am usingBootstrap Icons
would be nice as a feature option in the main plugin if possible, I am closing for now, thanks
📚 Documentation
Can you please help clarify in your documentation.
Often webpages that explain something in code, have several snippets.
Some of these snippets scroll past the page, could you show us how to select and copy all the codeblocks or sections in markdown code or a specific css.
thanks