Browse Source

Fix file uploading for FF extension

pull/46/head
coomdev 2 years ago
parent
commit
b13aa0504f
  1. 5
      build-ff.js
  2. 7
      firefox/manifest.json
  3. 2
      firefox_update.json
  4. 3
      main.d.ts
  5. 17
      src/Components/PostOptions.svelte
  6. 19
      src/utils.ts

5
build-ff.js

@ -64,13 +64,10 @@ const manif = {
"64": "1449696017588.png"
},
"permissions": [
"notifications",
"clipboardWrite",
"menus",
"activeTab",
"webRequest",
"webRequestBlocking",
"contextMenus",
"storage",
...domains
],
"content_scripts": [

7
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/*",

2
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"}]}}}
{"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"}]}}}

3
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<string, string>)
declare function GM_addElement(parent: HTMLElement, tagname: string, attrs: Record<string, string>);
declare function cloneInto<T>(e: T, where: Window & typeof globalThis | null): T;

17
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!`

19
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> };

Loading…
Cancel
Save