أضف الأكواد التالية في الوسم لإضافة زر النسخ التلقائي:
<script>
$(function() {
$('pre.prettyprint').parent().addClass('code-wrap');
$('pre.prettyprint').append('<div class="copy-button">نسخ</div>');
$('pre.prettyprint').hover(function() {
$(this).find('.copy-button').show();
}, function() {
$(this).find('.copy-button').hide();
});
$('.copy-button').click(function() {
var html = $(this).parent().html();
html = html.replace(/<br>/gi, '\n');
html = html.replace(/<(?:.|\n)*?>/gm, '');
html = html.replace(/>/g, '>');
html = html.replace(/</g, '<');
html = html.replace(/&/g, '&');
html = html.replace(/ /g, ' ');
html = html.replace(/"/g, '"');
html = html.replace(/'/g, "'");
var input = document.createElement('textarea');
document.body.appendChild(input);
input.value = html;
input.select();
document.execCommand('copy');
input.remove();
$(this).text('تم النسخ!');
});
});
</script>