편집 요약 없음 |
편집 요약 없음 |
||
11번째 줄: | 11번째 줄: | ||
}); | }); | ||
const code = element.firstChild.innerText; | const code = element.firstChild.innerText; | ||
copybutton.on('click', function () { | copybutton.on('click', function () { copy(code); }); | ||
const endBlock = document.createElement('div'); | const endBlock = document.createElement('div'); | ||
endBlock.style = "clear:both"; | endBlock.style = "clear:both"; | ||
19번째 줄: | 19번째 줄: | ||
} | } | ||
function | function copy(string) { | ||
navigator.clipboard.writeText( | navigator.clipboard.writeText(string); | ||
} | } | ||
2022년 9월 4일 (일) 16:25 판
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 () { copy(code); });
const endBlock = document.createElement('div');
endBlock.style = "clear:both";
$(element).prepend(copybutton.$element);
element.appendChild(endBlock);
});
}
function copy(string) {
navigator.clipboard.writeText(string);
}
mw.loader.using(['oojs-ui-core'], function () {
addCopyLinkToCodeElements();
});