편집 요약 없음 |
편집 요약 없음 |
||
(같은 사용자의 중간 판 14개는 보이지 않습니다) | |||
1번째 줄: | 1번째 줄: | ||
/** | |||
* 코드 상자에 코드를 복사하는 버튼을 추가합니다. | |||
*/ | |||
mw.loader.using(['oojs-ui-core', 'oojs-ui.styles.icons-editing-advanced'], () => { | |||
mw.util.addCSS('.copyToClipBoard-button { margin-top: 0.7em; margin-right: 0.7em; position: absolute; z-index: 100; right: 0; }\ | |||
.mw-highlight { position: relative; }'); | |||
const highlightElements = document.querySelectorAll(".mw-parser-output .mw-highlight"); | |||
highlightElements.forEach(element => { | |||
var copyToClipBoardbutton = new OO.ui.ButtonWidget({ | |||
label: 'copy', | |||
icon: 'code', | |||
title: 'copy this code to clipboard', | |||
classes: ['copyToClipBoard-button'] | |||
}); | |||
const codeText = element.firstChild.innerText; | |||
copyToClipBoardbutton.on('click', () => copyToClipBoard(codeText)); | |||
const endBlock = document.createElement('div'); | |||
} | endBlock.style = "clear:both"; | ||
$(element).prepend(copyToClipBoardbutton.$element); | |||
element.appendChild(endBlock); | |||
}); | |||
}); | |||
function | /** | ||
* content를 클립보드로 복사합니다. | |||
* @param {string} content | |||
*/ | |||
function copyToClipBoard(content) { | |||
navigator.clipboard.writeText(content); | |||
} | } | ||
2023년 12월 31일 (일) 03:21 기준 최신판
/**
* 코드 상자에 코드를 복사하는 버튼을 추가합니다.
*/
mw.loader.using(['oojs-ui-core', 'oojs-ui.styles.icons-editing-advanced'], () => {
mw.util.addCSS('.copyToClipBoard-button { margin-top: 0.7em; margin-right: 0.7em; position: absolute; z-index: 100; right: 0; }\
.mw-highlight { position: relative; }');
const highlightElements = document.querySelectorAll(".mw-parser-output .mw-highlight");
highlightElements.forEach(element => {
var copyToClipBoardbutton = new OO.ui.ButtonWidget({
label: 'copy',
icon: 'code',
title: 'copy this code to clipboard',
classes: ['copyToClipBoard-button']
});
const codeText = element.firstChild.innerText;
copyToClipBoardbutton.on('click', () => copyToClipBoard(codeText));
const endBlock = document.createElement('div');
endBlock.style = "clear:both";
$(element).prepend(copyToClipBoardbutton.$element);
element.appendChild(endBlock);
});
});
/**
* content를 클립보드로 복사합니다.
* @param {string} content
*/
function copyToClipBoard(content) {
navigator.clipboard.writeText(content);
}