PageSourceSearch

https://zhzhdoai.github.io/js/clipboard-use.js

js zhzhdoai.github.io collected 2026-10-03 10:14:59 UTC 1,467 bytes, 49 lines download raw bytes

1// eslint-disable-next-line no-unused-expressions
2!(function(e, t, a) {
3  function initCopyCode() {
4    var copyHtml = '';
5    copyHtml += '<button class="copy-btn" data-clipboard-snippet="">';
6    copyHtml += '<i class="iconfont icon-copy"></i><span>Copy</span>';
7    copyHtml += '</button>';
8    $('.markdown-body pre').each(function() {
9      const pre = $(this);
10      if (pre.find('code.mermaid').length > 0) {
11        return;
12      }
13      pre.append(copyHtml);
14    });
15    // eslint-disable-next-line no-undef
16    var clipboard = new ClipboardJS('.copy-btn', {
17      target: function(trigger) {
18        return trigger.previousElementSibling;
19      }
20    });
21    $('.copy-btn').addClass(getBgClass());
22    clipboard.on('success', function(e) {
23      e.clearSelection();
24      var tmp = e.trigger.outerHTML;
25      e.trigger.innerHTML = 'Success';
26      setTimeout(function() {
27        e.trigger.outerHTML = tmp;
28      }, 2000);
29    });
30  }
31
32  function getBgClass() {
33    var ele = $('div.hljs, pre');
34    if (ele.length === 0) {
35      return 'copy-btn-dark';
36    }
37    var rgbArr = ele.css('background-color').replace(
38      /rgba*\(/, '').replace(')', '').split(',');
39    var color = (0.213 * rgbArr[0]) + (0.715 * rgbArr[1]) + (0.072 * rgbArr[2]) > 255 / 2;
40    return color ? 'copy-btn-dark' : 'copy-btn-light';
41  }
42
43  var oldLoadCb = window.onload;
44  window.onload = function() {
45    oldLoadCb && oldLoadCb();
46
47    initCopyCode();
48  };
49})(window, document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.