편집 요약 없음 |
편집 요약 없음 |
||
4번째 줄: | 4번째 줄: | ||
const copybutton = document.createElement('button'); | const copybutton = document.createElement('button'); | ||
const code = element.firstChild.innerText; | const code = element.firstChild.innerText; | ||
copybutton.innerText = "copy"; | copybutton.innerText = "copy"; | ||
copybutton.addEventListener('click',function() {copyCode(code)}); | copybutton.addEventListener('click',function() {copyCode(code)}); | ||
copybutton.style = "float:right"; | |||
const endBlock = document.createElement('div'); | |||
endBlock.style = "clear:both"; | |||
element.appendChild(copybutton); | element.appendChild(copybutton); | ||
element.appendChild(endBlock); | |||
}); | }); | ||
} | } | ||
14번째 줄: | 17번째 줄: | ||
navigator.clipboard.writeText(codeText); | navigator.clipboard.writeText(codeText); | ||
} | } | ||
$(function() {addCopyLinkToCodeElements()}); | $(function() {addCopyLinkToCodeElements()}); |
2022년 4월 3일 (일) 13:11 판
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;
copybutton.innerText = "copy";
copybutton.addEventListener('click',function() {copyCode(code)});
copybutton.style = "float:right";
const endBlock = document.createElement('div');
endBlock.style = "clear:both";
element.appendChild(copybutton);
element.appendChild(endBlock);
});
}
function copyCode(codeText) {
navigator.clipboard.writeText(codeText);
}
$(function() {addCopyLinkToCodeElements()});