diff --git a/src/screens/PluginsScreen.tsx b/src/screens/PluginsScreen.tsx index 841cd55..f41e208 100644 --- a/src/screens/PluginsScreen.tsx +++ b/src/screens/PluginsScreen.tsx @@ -849,8 +849,9 @@ const PluginsScreen: React.FC = () => { const [isLoading, setIsLoading] = useState(false); const [isRefreshing, setIsRefreshing] = useState(false); const [hasRepository, setHasRepository] = useState(false); - const [showboxCookie, setShowboxCookie] = useState(''); - const [showboxRegion, setShowboxRegion] = useState(''); + const [showboxUiToken, setShowboxUiToken] = useState(''); + const [showboxSavedToken, setShowboxSavedToken] = useState(''); + const [showboxScraperId, setShowboxScraperId] = useState(null); // Multiple repositories state const [repositories, setRepositories] = useState([]); @@ -1071,12 +1072,22 @@ const PluginsScreen: React.FC = () => { setInstalledScrapers(scrapers); - // preload showbox settings if present - const sb = scrapers.find(s => s.id === 'showboxog'); + // Detect ShowBox scraper dynamically and preload settings + const sb = scrapers.find(s => { + const id = (s.id || '').toLowerCase(); + const name = (s.name || '').toLowerCase(); + const filename = (s.filename || '').toLowerCase(); + return id.includes('showbox') || name.includes('showbox') || filename.includes('showbox'); + }); if (sb) { - const s = await localScraperService.getScraperSettings('showboxog'); - setShowboxCookie(s.cookie || ''); - setShowboxRegion(s.region || ''); + setShowboxScraperId(sb.id); + const s = await localScraperService.getScraperSettings(sb.id); + setShowboxUiToken(s.uiToken || ''); + setShowboxSavedToken(s.uiToken || ''); + } else { + setShowboxScraperId(null); + setShowboxUiToken(''); + setShowboxSavedToken(''); } } catch (error) { logger.error('[ScraperSettings] Failed to load scrapers:', error); @@ -1615,59 +1626,49 @@ const PluginsScreen: React.FC = () => { )} - {/* ShowBox Settings */} - {scraper.id === 'showboxog' && settings.enableLocalScrapers && ( + {/* ShowBox Settings - only visible when ShowBox scraper is available */} + {showboxScraperId && scraper.id === showboxScraperId && settings.enableLocalScrapers && ( - ShowBox Cookie + ShowBox UI Token - Region - - {regionOptions.map(opt => { - const selected = showboxRegion === opt.value; - return ( - setShowboxRegion(opt.value)} - > - - {opt.label} - - - ); - })} - - - { - await localScraperService.setScraperSettings('showboxog', { cookie: showboxCookie, region: showboxRegion }); - openAlert('Saved', 'ShowBox settings updated'); - }} - > - Save - - { - setShowboxCookie(''); - setShowboxRegion(''); - await localScraperService.setScraperSettings('showboxog', {}); - }} - > - Clear - - + + {showboxUiToken !== showboxSavedToken && ( + { + if (showboxScraperId) { + await localScraperService.setScraperSettings(showboxScraperId, { uiToken: showboxUiToken }); + } + setShowboxSavedToken(showboxUiToken); + openAlert('Saved', 'ShowBox settings updated'); + }} + > + Save + + )} + { + setShowboxUiToken(''); + setShowboxSavedToken(''); + if (showboxScraperId) { + await localScraperService.setScraperSettings(showboxScraperId, {}); + } + }} + > + Clear + + )} diff --git a/src/services/localScraperService.ts b/src/services/localScraperService.ts index 0c5cbe4..fa63e4f 100644 --- a/src/services/localScraperService.ts +++ b/src/services/localScraperService.ts @@ -1117,7 +1117,7 @@ class LocalScraperService { try { // Create function from code const func = new Function('sandbox', 'params', 'PRIMARY_KEY', 'TMDB_API_KEY', ` - const { console, setTimeout, clearTimeout, Promise, JSON, Date, Math, parseInt, parseFloat, encodeURIComponent, decodeURIComponent, require, axios, fetch, module, exports, global, URL_VALIDATION_ENABLED } = sandbox; + const { console, setTimeout, clearTimeout, Promise, JSON, Date, Math, parseInt, parseFloat, encodeURIComponent, decodeURIComponent, require, axios, fetch, module, exports, global, URL_VALIDATION_ENABLED, SCRAPER_SETTINGS, SCRAPER_ID } = sandbox; // Inject MovieBox constants into global scope global.PRIMARY_KEY = PRIMARY_KEY; @@ -1125,6 +1125,12 @@ class LocalScraperService { window.PRIMARY_KEY = PRIMARY_KEY; window.TMDB_API_KEY = TMDB_API_KEY; + // Expose per-scraper context to plugin globals + global.SCRAPER_SETTINGS = SCRAPER_SETTINGS; + global.SCRAPER_ID = SCRAPER_ID; + window.SCRAPER_SETTINGS = SCRAPER_SETTINGS; + window.SCRAPER_ID = SCRAPER_ID; + ${code} // Call the main function (assuming it's exported)