diff --git a/frontend/src/tools/statistik.jsx b/frontend/src/tools/statistik.jsx index 1c384b7..4584362 100644 --- a/frontend/src/tools/statistik.jsx +++ b/frontend/src/tools/statistik.jsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useRef } from 'react'; import { BarChart, Bar, LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell, PieChart, Pie, Legend } from 'recharts'; const api = (path, opts={}) => { @@ -228,9 +228,39 @@ function MakerworldTab({ toast }) { const bookmarkletCode = tokenInfo ? `javascript:(function(){try{var el=document.getElementById('__NEXT_DATA__');if(!el){alert('MakerWorld: __NEXT_DATA__ nicht gefunden. Bist du auf der Statistikseite (/my/data-overview/model)?');return;}var nd=JSON.parse(el.textContent);var sd=nd.props&&nd.props.pageProps&&nd.props.pageProps.statisticalData;if(!sd||!sd.summary){alert('MakerWorld: Keine Statistikdaten auf dieser Seite gefunden.');return;}fetch('${tokenInfo.origin}/api/tools/makerworld/ingest',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({token:'${tokenInfo.token}',statisticalData:sd})}).then(function(r){return r.json();}).then(function(j){alert(j.ok?'DickenDock aktualisiert ✓':('Fehler: '+(j.error||'unbekannt')));}).catch(function(e){alert('Fehler: '+e.message);});}catch(e){alert('Fehler: '+e.message);}})();//%s` : ''; + const codeRef = useRef(null); + const copyBookmarklet = async () => { - try { await navigator.clipboard.writeText(bookmarkletCode); toast?.('Bookmarklet-Code kopiert'); } - catch { toast?.('Kopieren nicht möglich — bitte manuell markieren','error'); } + // Moderne Clipboard-API zuerst versuchen + try { + await navigator.clipboard.writeText(bookmarkletCode); + toast?.('Bookmarklet-Code kopiert'); + return; + } catch {} + // Fallback: klassisches execCommand über eine unsichtbare Textarea + // (Clipboard-API meldet in manchen PWA/Mobile-Kontexten fälschlich Erfolg + // oder schlägt ohne Fehler fehl — dieser Weg ist zuverlässiger) + try { + const ta = document.createElement('textarea'); + ta.value = bookmarkletCode; + ta.style.position = 'fixed'; + ta.style.left = '-9999px'; + document.body.appendChild(ta); + ta.focus(); + ta.select(); + const ok = document.execCommand('copy'); + document.body.removeChild(ta); + if (ok) { toast?.('Bookmarklet-Code kopiert'); return; } + } catch {} + toast?.('Kopieren nicht möglich — bitte Code unten manuell markieren und kopieren','error'); + selectAllCode(); + }; + + const selectAllCode = () => { + if (codeRef.current) { + codeRef.current.focus(); + codeRef.current.select(); + } }; if (loading) return