편집 요약 없음 |
편집 요약 없음 |
||
1번째 줄: | 1번째 줄: | ||
function addCopyLinkToCodeElements() { | function addCopyLinkToCodeElements() { | ||
mw.util.addCSS('.copy-button { float:right; margin-left: -9999999px; margin-top: 0.7em; margin-right: 0.7em; }') | mw.util.addCSS('.copy-button { float:right; margin-left: -9999999px; margin-top: 0.7em; margin-right: 0.7em; }') | ||
const elements = document.querySelectorAll(".mw-parser-output .mw-highlight"); | |||
elements.forEach(function (element) { | |||
var copybutton = new OO.ui.ButtonWidget({ | |||
label: 'copy', | |||
/*icon: 'code',*/ | |||
title: 'copy', | |||
classes: ['copy-button'] | |||
}); | |||
const code = element.firstChild.innerText; | |||
copybutton.on('click', function () { copyCode(code); }); | |||
const endBlock = document.createElement('div'); | |||
endBlock.style = "clear:both"; | |||
$(element).prepend(copybutton.$element); | |||
element.appendChild(endBlock); | |||
}); | |||
} | } | ||
function copyCode(codeText) { | function copyCode(codeText) { | ||
navigator.clipboard.writeText(codeText); | |||
} | } | ||
mw.loader.using(['oojs-ui-core'], function () { | |||
addCopyLinkToCodeElements() | |||
}); | }); |
2022년 9월 4일 (일) 13:35 판
function addCopyLinkToCodeElements() {
mw.util.addCSS('.copy-button { float:right; margin-left: -9999999px; margin-top: 0.7em; margin-right: 0.7em; }')
const elements = document.querySelectorAll(".mw-parser-output .mw-highlight");
elements.forEach(function (element) {
var copybutton = new OO.ui.ButtonWidget({
label: 'copy',
/*icon: 'code',*/
title: 'copy',
classes: ['copy-button']
});
const code = element.firstChild.innerText;
copybutton.on('click', function () { copyCode(code); });
const endBlock = document.createElement('div');
endBlock.style = "clear:both";
$(element).prepend(copybutton.$element);
element.appendChild(endBlock);
});
}
function copyCode(codeText) {
navigator.clipboard.writeText(codeText);
}
mw.loader.using(['oojs-ui-core'], function () {
addCopyLinkToCodeElements()
});