-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphpman.js
More file actions
35 lines (30 loc) · 1.14 KB
/
Copy pathphpman.js
File metadata and controls
35 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* phpMan copy-button script */
/* Extracted from phpMan.php for external caching and XHTML validity */
(function () {
var blocks = document.querySelectorAll('#content-wrap pre code');
if (!blocks.length) return;
blocks.forEach(function (code) {
var pre = code.parentElement;
var wrapper = document.createElement('div');
wrapper.className = 'code-block';
// Wrap <pre> in .code-block div
pre.insertBefore(wrapper, code);
wrapper.appendChild(code);
// Create copy button
var btn = document.createElement('button');
btn.className = 'copy-btn';
btn.textContent = '📋 Copy';
btn.title = 'Copy code to clipboard';
btn.onclick = function () {
navigator.clipboard.writeText(code.textContent).then(function () {
btn.textContent = '✓ Copied!';
btn.classList.add('copied');
setTimeout(function () {
btn.textContent = '📋 Copy';
btn.classList.remove('copied');
}, 1500);
});
};
wrapper.appendChild(btn);
});
})();