diff --git a/src/components/PageShell.tsx b/src/components/PageShell.tsx index e919671..0cecb37 100644 --- a/src/components/PageShell.tsx +++ b/src/components/PageShell.tsx @@ -7,6 +7,74 @@ interface PageShellProps { } const PageShell: React.FC = ({ children }) => { + React.useEffect(() => { + // Select all
 elements inside .ps-content
+    const preBlocks = document.querySelectorAll('.ps-content pre');
+    preBlocks.forEach(pre => {
+      // Avoid duplicate buttons
+      if (
+        pre.querySelector('.global-copy-btn') ||
+        pre.parentElement?.querySelector('button')
+      )
+        return;
+
+      const preEl = pre as HTMLElement;
+      preEl.style.position = 'relative';
+
+      // Create button
+      const btn = document.createElement('button');
+      btn.className =
+        'global-copy-btn absolute top-2 right-2 backdrop-filter backdrop-blur-xl bg-white/10 border border-white/20 p-2 hover:bg-white/30 rounded-md transition-all duration-300 z-10 text-white flex items-center justify-center';
+      btn.title = 'Copy to clipboard';
+
+      const copyIcon = ``;
+      const checkIcon = ``;
+
+      btn.innerHTML = copyIcon;
+
+      btn.addEventListener('click', () => {
+        // Exclude the button text itself if it was copied
+        const textToCopy = (preEl.innerText || '')
+          .replace(/Copy|Copied!/g, '')
+          .trim();
+
+        if (navigator.clipboard) {
+          navigator.clipboard
+            .writeText(textToCopy)
+            .then(() => {
+              btn.innerHTML = checkIcon;
+              setTimeout(() => {
+                btn.innerHTML = copyIcon;
+              }, 2000);
+            })
+            .catch(err => {
+              console.error('Failed to copy: ', err);
+            });
+        } else {
+          // Fallback
+          const textarea = document.createElement('textarea');
+          textarea.value = textToCopy;
+          textarea.style.position = 'absolute';
+          textarea.style.left = '-9999px';
+          document.body.appendChild(textarea);
+          textarea.select();
+          try {
+            document.execCommand('copy');
+            btn.innerHTML = checkIcon;
+            setTimeout(() => {
+              btn.innerHTML = copyIcon;
+            }, 2000);
+          } catch (e) {
+            console.error('Fallback copy failed', e);
+          }
+          document.body.removeChild(textarea);
+        }
+      });
+
+      preEl.appendChild(btn);
+    });
+  }, [children]);
+
   return (
     
{/* Animated background orbs — matches landing page */}