fix: MakerWorld Bookmarklet-Kopieren mit execCommand-Fallback + sichtbarem Textfeld
This commit is contained in:
@@ -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 <div style={{color:'rgba(255,255,255,0.3)',fontFamily:'monospace',fontSize:12}}>Lädt…</div>;
|
||||
@@ -281,6 +311,12 @@ function MakerworldTab({ toast }) {
|
||||
<button onClick={copyBookmarklet} style={{...S.btn('#4ecdc4')}}>
|
||||
📋 Bookmarklet-Code kopieren
|
||||
</button>
|
||||
<div style={{...S.sub,marginTop:10,marginBottom:6}}>
|
||||
Falls der Button nichts in die Zwischenablage legt (kommt auf manchen Handys/PWAs vor):
|
||||
hier antippen, „Alles auswählen" wählen, dann normal kopieren.
|
||||
</div>
|
||||
<textarea ref={codeRef} readOnly value={bookmarkletCode} onClick={selectAllCode}
|
||||
rows={3} style={{...S.inp,resize:'vertical',fontSize:9,fontFamily:'monospace',wordBreak:'break-all'}}/>
|
||||
<div style={{...S.sub,marginTop:10}}>
|
||||
Firefox für Android unterstützt diesen Trick leider nicht zuverlässig — dafür entweder kurz zu
|
||||
Chrome wechseln, oder den <b>Kiwi Browser</b> installieren (Chromium-basiert, unterstützt
|
||||
|
||||
Reference in New Issue
Block a user