PageSourceSearch

https://zhouyingsasa.github.io/js/copy.js?version=1.9.0

js zhouyingsasa.github.io collected 2026-10-03 10:14:53 UTC 2,188 bytes, 80 lines download raw bytes

1$(function () {
2  // Add copy icon
3  $('figure.highlight').wrap('<div class="code-area-wrap"></div>')
4  var $copyIcon = $('<i class="fa fa-clipboard" aria-hidden="true"></i>')
5  var $notice = $('<div class="copy-notice"></div>')
6  var $codeLanguage = $('<span class="codeblock-language"></span>')
7  $('.code-area-wrap').prepend($copyIcon)
8  $('.code-area-wrap').prepend($notice)
9  $('.code-area-wrap').prepend($codeLanguage)
10  $('.code-area-wrap').each(function (index, element) {
11    var codeLanguage = $(element)
12      .find('figure.highlight')
13      .attr('class')
14      .replace('highlight', '')
15      .trim()
16    $(element)
17      .find('.codeblock-language')
18      .text(codeLanguage)
19  })
20  // copy function
21  function copy (text, ctx) {
22    if (
23      document.queryCommandSupported &&
24      document.queryCommandSupported('copy')
25    ) {
26      try {
27        document.execCommand('copy') // Security exception may be thrown by some browsers.
28        $(ctx)
29          .prev('.copy-notice')
30          .text(GLOBAL_CONFIG.copy.success)
31          .velocity(
32            {
33              translateX: -30,
34              opacity: 1
35            },
36            {
37              loop: 1,
38              duration: 750,
39              easing: 'easeOutQuint'
40            }
41          )
42      } catch (ex) {
43        $(ctx)
44          .prev('.copy-notice')
45          .text(GLOBAL_CONFIG.copy.error)
46          .velocity(
47            {
48              translateX: -30,
49              opacity: 1
50            },
51            {
52              loop: 1,
53              duration: 750,
54              easing: 'easeOutQuint'
55            }
56          )
57        return false
58      }
59    } else {
60      $(ctx)
61        .prev('.copy-notice')
62        .text(GLOBAL_CONFIG.copy.noSupport)
63    }
64  }
65  // click events
66  $('.code-area-wrap .fa-clipboard').on('click', function () {
67    var selection = window.getSelection()
68    var range = document.createRange()
69    range.selectNodeContents(
70      $(this)
71        .siblings('figure')
72        .find('.code pre')[0]
73    )
74    selection.removeAllRanges()
75    selection.addRange(range)
76    var text = selection.toString()
77    copy(text, this)
78    selection.removeAllRanges()
79  })
80})

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.