PageSourceSearch

https://zeromq.org/js/copy-code-button.js

js zeromq.org collected 2026-10-01 08:36:03 UTC 1,812 bytes, 54 lines download raw bytes

1/* global clipboard */
2/* eslint-disable no-console */
3
4function addCopyButtons(clipboard) {
5    document.querySelectorAll('pre > code').forEach(function(codeBlock) {
6        var button = document.createElement('button');
7        button.className = 'copy-code-button';
8        button.type = 'button';
9        button.innerText = 'Copy';
10
11        button.addEventListener('click', function() {
12            clipboard.writeText(codeBlock.textContent).then(
13                function() {
14                    /* Chrome doesn't seem to blur automatically, leaving the button
15                       in a focused state */
16                    button.blur();
17
18                    button.innerText = 'Copied!';
19                    setTimeout(function() {
20                        button.innerText = 'Copy';
21                    }, 2000);
22                },
23                function(error) {
24                    button.innerText = 'Error';
25                    console.error(error);
26                }
27            );
28        });
29
30        var pre = codeBlock.parentNode;
31        if (pre.parentNode.classList.contains('highlight')) {
32            var highlight = pre.parentNode;
33            highlight.parentNode.insertBefore(button, highlight);
34        } else {
35            pre.parentNode.insertBefore(button, pre);
36        }
37    });
38}
39
40if (navigator && navigator.clipboard) {
41    addCopyButtons(navigator.clipboard);
42} else {
43    var script = document.createElement('script');
44    script.src =
45        'https://cdnjs.cloudflare.com/ajax/libs/clipboard-polyfill/2.7.0/clipboard-polyfill.promise.js';
46    script.integrity = 'sha256-waClS2re9NUbXRsryKoof+F9qc1gjjIhc2eT7ZbIv94=';
47    script.crossOrigin = 'anonymous';
48
49    script.onload = function() {
50        addCopyButtons(clipboard);
51    };
52
53    document.body.appendChild(script);
54}

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.