PageSourceSearch

https://mortezavaezi.ir/wp-content/themes/TerminalOS/assets/js/copy-code.js?ver=1764804195

js mortezavaezi.ir collected 2026-10-02 01:58:17 UTC 2,103 bytes, 49 lines download raw bytes

1// assets/js/copy-code.js
2
3document.addEventListener('DOMContentLoaded', () => {
4    // Function to handle copying text to clipboard
5    const copyToClipboard = (text, button) => {
6        navigator.clipboard.writeText(text).then(() => {
7            const originalText = button.textContent;
8            button.textContent = '[COPIED]';
9            button.classList.add('copied');
10            setTimeout(() => {
11                button.textContent = originalText;
12                button.classList.remove('copied');
13            }, 2000);
14        }).catch(err => {
15            console.error('Failed to copy text: ', err);
16        });
17    };
18
19    // Event listener for copy buttons within the terminal GUI (for AJAX-loaded content)
20    const guiContent = document.getElementById('gui-content');
21    if (guiContent) {
22        guiContent.addEventListener('click', (event) => {
23            const copyButton = event.target.closest('.code-box .copy-btn');
24            if (copyButton) {
25                const codeBox = copyButton.closest('.code-box');
26                const codeContent = codeBox ? codeBox.querySelector('.code-content pre') : null;
27                if (codeContent) {
28                    copyToClipboard(codeContent.textContent, copyButton);
29                }
30            }
31        });
32    }
33
34    // Event listener for copy buttons in single post pages (if rendered directly by WordPress)
35    // This assumes the code-box might appear directly in the main content area
36    const mainContentArea = document.querySelector('.entry-content'); // Common class for main post content
37    if (mainContentArea) {
38        mainContentArea.addEventListener('click', (event) => {
39            const copyButton = event.target.closest('.code-box .copy-btn');
40            if (copyButton) {
41                const codeBox = copyButton.closest('.code-box');
42                const codeContent = codeBox ? codeBox.querySelector('.code-content pre') : null;
43                if (codeContent) {
44                    copyToClipboard(codeContent.textContent, copyButton);
45                }
46            }
47        });
48    }
49});

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.