편집 요약 없음 |
편집 요약 없음 |
||
3번째 줄: | 3번째 줄: | ||
elements.forEach(function(element) { | elements.forEach(function(element) { | ||
const copybutton = document.createElement('button'); | const copybutton = document.createElement('button'); | ||
const code = element.firstChild. | const code = element.firstChild.innerText; | ||
console.log(element.firstChild); | console.log(element.firstChild); | ||
copybutton. | copybutton.innerText = "copy"; | ||
copybutton.addEventListener('click',function() {copyCode(code)}); | copybutton.addEventListener('click',function() {copyCode(code)}); | ||
element.appendChild(copybutton); | element.appendChild(copybutton); |
2022년 4월 3일 (일) 13:08 판
function addCopyLinkToCodeElements() {
const elements = document.querySelectorAll(".mw-parser-output .mw-highlight");
elements.forEach(function(element) {
const copybutton = document.createElement('button');
const code = element.firstChild.innerText;
console.log(element.firstChild);
copybutton.innerText = "copy";
copybutton.addEventListener('click',function() {copyCode(code)});
element.appendChild(copybutton);
});
}
function copyCode(codeText) {
navigator.clipboard.writeText(codeText);
}
$(function() {addCopyLinkToCodeElements()});