@צדיק-תמים
הקוד העדכני:
// הוספת לחצן להעתקת קטעי קוד
// ==UserScript==
// @name Nodebb copy code
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add a copy button to code areas
// @author yossizahn
// @match https://tchumim.com/*
// @match http://forum.netfree.link/*
// @match https://xn--9dbazrsfz.com/*
// @grant none
// ==/UserScript==
(function() {
/* globals require, $ */
'use strict';
require(['clipboard'], clipboard => {
new clipboard('.copy-code', { target: trigger => trigger.previousElementSibling })
.on('success', e => {
e.clearSelection();
$(e.trigger).attr('data-original-title', 'הועתק!').tooltip('fixTitle').tooltip('show');
setTimeout(() => $(e.trigger).attr('data-original-title', 'העתק').tooltip('fixTitle').tooltip('hide'), 1000);
});
});
$(window).on('action:posts.loaded action:topic.loaded action:posts.edited', () => {
$('[component="post/content"]>pre').wrap('<div class="pre-wrapper"><div>').after('<i class="copy-code fa fa-copy"></i>');
$('.copy-code').attr('title', 'העתק').tooltip({ container: 'body' });
});
})();
// הוספת לחצן "קוד" ליצירת קוד - inline.
(function () {
'use strict';
/* globals require, $ */
require(['composer/formatting'], function (formatting) {
require(['composer/controls'], function (controls) {
formatting.addButton('fa fa-terminal', function (textarea, selectionStart, selectionEnd) {
if (selectionStart === selectionEnd) {
var block = controls.getBlockData(textarea, '`', selectionStart);
if (block.in && block.atEnd) {
controls.updateTextareaSelection(textarea, selectionStart + 1, selectionStart + 1);
} else {
controls.insertIntoTextarea(textarea, `\`code\``);
controls.updateTextareaSelection(textarea, selectionStart + 1, selectionStart + 'code'.length + 1);
}
} else {
var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '`');
controls.updateTextareaSelection(textarea, selectionStart + 1 + wrapDelta[0], selectionEnd + 1 - wrapDelta[1]);
}
}, 'code', 'inlineCode');
});
});
})();