diff --git a/src/entrypoints/amenzb.content.ts b/src/entrypoints/amenzb.content.ts new file mode 100644 index 0000000..70ba6f8 --- /dev/null +++ b/src/entrypoints/amenzb.content.ts @@ -0,0 +1,69 @@ +import { defineContentScript } from 'wxt/sandbox'; +import { Content } from '~/Content'; + +export default defineContentScript({ + matches: ['*://*.amenzb.moe/*', '*://amenzb.moe/*'], + + main(ctx) { + new AmenzbContent(ctx); + }, +}); + +class AmenzbContent extends Content { + + get id() { + return 'amenzb'; + } + + apiKey: string = ''; + + get isList(): boolean { + return document.querySelectorAll('a[href*="/download/"]').length > 1; + } + + get isDetail(): boolean { + return window.location.pathname.startsWith('/release/'); + } + + // Fetches the API key from the profile page and caches it + async ready(): Promise { + const res = await fetch('https://amenzb.moe/profile', { credentials: 'include' }); + const html = await res.text(); + const parser = new DOMParser(); + const doc = parser.parseFromString(html, 'text/html'); + const input = doc.getElementById('apiKeyInput') as HTMLInputElement; + if (input?.value) { + this.apiKey = input.value; + console.info(`[NZB Unity] ameNZB API key loaded`); + } else { + console.warn(`[NZB Unity] ameNZB API key not found — are you logged in?`); + } + } + + // Converts a /download/123456 URL into the authenticated API URL + buildApiUrl(downloadUrl: string): string { + const id = downloadUrl.split('/download/')[1]; + return `https://amenzb.moe/api?t=get&apikey=${this.apiKey}&id=${id}`; + } + + initializeListLinks = () => { + const links = document.querySelectorAll('a[href*="/download/"]'); + links.forEach(el => { + const anchor = el as HTMLAnchorElement; + this.createAddUrlLink({ + url: this.buildApiUrl(anchor.href), + adjacent: anchor, + }); + }); + } + + initializeDetailLinks = () => { + const anchor = document.querySelector('a[href*="/download/"]') as HTMLAnchorElement; + if (anchor) { + this.createAddUrlLink({ + url: this.buildApiUrl(anchor.href), + adjacent: anchor, + }); + } + } +} \ No newline at end of file diff --git a/src/entrypoints/dognzb.content.ts b/src/entrypoints/dognzb.content.ts index 95a1640..c129212 100644 --- a/src/entrypoints/dognzb.content.ts +++ b/src/entrypoints/dognzb.content.ts @@ -43,6 +43,34 @@ class DognzbContent extends Content { } async ready() { +// Only apply CSS fix in Chrome — Firefox handles CSP differently and shows the icon fine +const isChrome = navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Firefox'); + +if (isChrome) { + const style = document.createElement('style'); + style.textContent = ` + .NZBUnityLink { + background-image: none !important; + min-width: 16px !important; + border-radius: 2px !important; + background-color: #40a040 !important; + color: white !important; + font-size: 13px !important; + font-weight: bold !important; + text-align: center !important; + line-height: 16px !important; + text-decoration: none !important; + } + .NZBUnityLink::before { + content: '↓' !important; + } + .NZBUnityLink.pending { background-color: #808080 !important; } + .NZBUnityLink.success { background-color: #40a040 !important; } + .NZBUnityLink.error { background-color: #cc3333 !important; } + `; + document.head.appendChild(style); +} + this.observer = new MutationObserver((mutations) => { console.info(`[NZB Unity] Content changed, updating links...`); this.onReady(); // Re-run initialization diff --git a/src/store.ts b/src/store.ts index a5c9d4e..5b59098 100644 --- a/src/store.ts +++ b/src/store.ts @@ -81,6 +81,7 @@ export const DefaultDownloaderOptions: DownloaderOptions = { export const DefaultIndexers: Record = { abnzb: { Display: 'abNZB', Enabled: true }, althub: { Display: 'altHUB', Enabled: true }, + amenzb: { Display: 'ameNZB', Enabled: true }, animetosho: { Display: 'AnimeTosho', Enabled: true }, binsearch: { Display: 'BinSearch', Enabled: true }, dognzb: { Display: 'DogNZB', Enabled: true },