편집 요약 없음 |
편집 요약 없음 |
||
1번째 줄: | 1번째 줄: | ||
function addCopyLinkToCodeElements() { | function addCopyLinkToCodeElements() { | ||
mw.util.addCSS('.copy-button { margin-top: 0.7em; margin-right: 0.7em; position: absolute; z-index: 100; right: 0; }'); | mw.util.addCSS('.copy-button { margin-top: 0.7em; margin-right: 0.7em; position: absolute; z-index: 100; right: 0; }\ | ||
.mw-highlight { position: relative; }'); | |||
const elements = document.querySelectorAll(".mw-parser-output .mw-highlight"); | const elements = document.querySelectorAll(".mw-parser-output .mw-highlight"); | ||
elements.forEach(function (element) { | elements.forEach(function (element) { |
2022년 9월 4일 (일) 16:24 판
function addCopyLinkToCodeElements() {
mw.util.addCSS('.copy-button { margin-top: 0.7em; margin-right: 0.7em; position: absolute; z-index: 100; right: 0; }\
.mw-highlight { position: relative; }');
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();
});