diff --git a/build-ff.js b/build-ff.js index 9220fa8..00d1732 100644 --- a/build-ff.js +++ b/build-ff.js @@ -64,13 +64,10 @@ const manif = { "64": "1449696017588.png" }, "permissions": [ - "notifications", "clipboardWrite", - "menus", - "activeTab", "webRequest", "webRequestBlocking", - "contextMenus", + "storage", ...domains ], "content_scripts": [ diff --git a/firefox/manifest.json b/firefox/manifest.json index 8e3607c..fda6b2a 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -7,18 +7,15 @@ }, "name": "PngExtraEmbedder", "description": "Discover embedded files on 4chan and archives!", - "version": "0.222", + "version": "0.226", "icons": { "64": "1449696017588.png" }, "permissions": [ - "notifications", "clipboardWrite", - "menus", - "activeTab", "webRequest", "webRequestBlocking", - "contextMenus", + "storage", "https://*.coom.tech/*", "https://boards.4channel.org/*", "https://boards.4chan.org/*", diff --git a/firefox_update.json b/firefox_update.json index ac5c57f..d59a8bf 100644 --- a/firefox_update.json +++ b/firefox_update.json @@ -1 +1 @@ -{"addons":{"{34ac4994-07f2-44d2-8599-682516a6c6a6}":{"updates":[{"version":"0.222","update_link":"https://github.com/coomdev/pngextraembedder/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pee-firefox.zip"}]}}} \ No newline at end of file +{"addons":{"{34ac4994-07f2-44d2-8599-682516a6c6a6}":{"updates":[{"version":"0.226","update_link":"https://github.com/coomdev/pngextraembedder/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pee-firefox.zip"}]}}} \ No newline at end of file diff --git a/main.d.ts b/main.d.ts index ccaad74..1c2d7fb 100644 --- a/main.d.ts +++ b/main.d.ts @@ -61,4 +61,5 @@ declare const isBackground: boolean; declare const chrome: typeof browser; declare const _DOMParser: typeof DOMParser; declare const manifest: 2 | 3; -declare function GM_addElement(parent: HTMLElement, tagname: string, attrs: Record) \ No newline at end of file +declare function GM_addElement(parent: HTMLElement, tagname: string, attrs: Record); +declare function cloneInto(e: T, where: Window & typeof globalThis | null): T; \ No newline at end of file diff --git a/src/Components/PostOptions.svelte b/src/Components/PostOptions.svelte index 648158e..a44fc76 100644 --- a/src/Components/PostOptions.svelte +++ b/src/Components/PostOptions.svelte @@ -5,6 +5,7 @@ import { addToEmbeds, embeddedToBlob, + externalDispatch, fireNotification, getFileFromHydrus, uploadFiles, @@ -24,11 +25,7 @@ let currentEmbed: { file: File } | undefined; function restore() { - document.dispatchEvent( - new CustomEvent("QRSetFile", { - detail: { file: original }, - }) - ); + externalDispatch("QRSetFile", { file: original }); } // This is an event to signal a change in the container file @@ -36,7 +33,9 @@ const isSame = (a: File | null, b: File | null) => { if (a == null || b == null) return false; - return (["size", "name", "lastModified"] as const).every((e) => a[e] == b[e]); + return (["size", "name", "lastModified"] as const).every( + (e) => a[e] == b[e] + ); }; document.addEventListener("PEEFile", async (e) => { @@ -108,11 +107,7 @@ currentEmbed = { file: new File([buff], file.name, { type }), } as { file: File }; - document.dispatchEvent( - new CustomEvent("QRSetFile", { - detail: currentEmbed, - }) - ); + externalDispatch("QRSetFile", currentEmbed); fireNotification( "success", `File${links.length > 1 ? "s" : ""} successfully embedded!` diff --git a/src/utils.ts b/src/utils.ts index cacc093..940f084 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -203,11 +203,9 @@ export const decodeCoom3Payload = async (buff: Buffer) => { }; export const fireNotification = (type: 'success' | 'error' | 'info' | 'warning', content: string, lifetime = 3) => { - document.dispatchEvent(new CustomEvent("CreateNotification", { - detail: { - type, content, lifetime - } - })); + externalDispatch("CreateNotification", { + type, content, lifetime + }); }; function parseForm(data: object) { @@ -285,6 +283,17 @@ export async function getFileFromHydrus(client: HydrusClient, ); } +export function externalDispatch(name: string, data: any) { + let event: Event; + if (execution_mode == "ff_api") { + const clonedDetail = cloneInto(data, document.defaultView); + event = new CustomEvent(name, { detail: clonedDetail }); + } else { + event = new CustomEvent(name, { detail: data }); + } + document.dispatchEvent(event); +} + export class peeTarget { targets = {} as { [k in string]: Array<(e: any) => any> };