-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopycode.js
More file actions
30 lines (30 loc) · 1.5 KB
/
copycode.js
File metadata and controls
30 lines (30 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*页面载入完成后,创建复制按钮*/
!function (e, t, a) {
var script = document.currentScript || (function () {
var scripts = document.getElementsByTagName("script");
return scripts[scripts.length - 1]
})()
var successText = $(script).attr("successtext")
var copyHtml = '';
copyHtml += '<div class="btn-copy" >';
copyHtml += '<svg viewBox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg>';
copyHtml += '</div>';
$(".highlight .code pre").before(copyHtml);
var clipboard = new ClipboardJS('.btn-copy', {
target: function (trigger) {
return trigger.nextElementSibling;
}
});
clipboard.on('success',
function (e) {
//清除内容被选择状态
e.clearSelection();
if (successText) {
toastr.options = {
"positionClass": "toast-top-center",
"timeOut": "1000",
}
toastr.success(successText)
}
});
}(window, document);