PageSourceSearch

https://www.snapfish.com.au/resources/js/platform/common/copy-code.js

js snapfish.com.au collected 2026-09-24 20:06:23 UTC 2,062 bytes, 60 lines download raw bytes

1/*** Starts - Copy code function  */
2function copyCode(element) {
3    // Find the closest `.code` container
4    const codeContainer = element.closest(".code");
5    if (!codeContainer) return;
6
7    // Get the code value text
8    const codeValueEl = codeContainer.querySelector(".code-value");
9    if (!codeValueEl) return;
10
11    const codeValue = codeValueEl.textContent.trim();
12    const codecontainerValue = codeContainer.innerHTML;
13    if (!codeValue) return;
14
15    const copiedText = codeContainer.getAttribute("data-copied-text") || 'Code copied!';
16
17    // Helper: fallback for non-HTTPS / old browsers
18    function fallbackCopy(text) {
19        const textarea = document.createElement("textarea");
20        textarea.value = text;
21        textarea.setAttribute("readonly", "");
22        textarea.style.position = "absolute";
23        textarea.style.left = "-9999px";
24        document.body.appendChild(textarea);
25        textarea.select();
26        try {
27            document.execCommand("copy");
28            console.log(`Copied (fallback): ${text}`);
29        } catch (err) {
30            console.error("Fallback copy failed", err);
31        }
32        document.body.removeChild(textarea);
33
34        // Show feedback
35        codeContainer.textContent = copiedText;
36        setTimeout(() => {
37            codeContainer.innerHTML = codecontainerValue;
38        }, 3000);
39    }
40
41    // Try modern API first
42    if (navigator.clipboard && navigator.clipboard.writeText) {
43        navigator.clipboard.writeText(codeValue)
44            .then(() => {
45                console.log(`Copied: ${codeValue}`);
46                codeContainer.textContent = copiedText;
47                setTimeout(() => {
48                    codeContainer.innerHTML = codecontainerValue;
49                }, 3000);
50            })
51            .catch(err => {
52                console.error("Failed to copy via navigator.clipboard", err);
53                fallbackCopy(codeValue);
54            });
55    } else {
56        // Fallback path
57        fallbackCopy(codeValue);
58    }
59}
60/*** Ends - Copy code function  */

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.