Browse Source

Throw an error if the user forgets to embed

pull/46/head
coomdev 2 years ago
parent
commit
5b402c205e
  1. 2
      main.meta.js
  2. 54
      main.user.js
  3. 3
      src/Components/PostOptions.svelte
  4. 35
      src/main.ts

2
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.174
// @version 0.175
// @description uhh
// @author You
// @match https://boards.4channel.org/*

54
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.174
// @version 0.175
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -81,7 +81,7 @@
var define_BUILD_VERSION_default;
var init_define_BUILD_VERSION = __esm({
"<define:BUILD_VERSION>"() {
define_BUILD_VERSION_default = [0, 174];
define_BUILD_VERSION_default = [0, 175];
}
});
@ -17312,7 +17312,7 @@
component_subscribe($$self, appState, ($$value) => $$invalidate(1, $appState = $$value));
let { processors: processors2 = [] } = $$props;
let { textinput } = $$props;
let files = [];
let { files = [] } = $$props;
const addContent = (...newfiles) => {
$$invalidate(0, files = [...files, ...newfiles]);
if (files.length > $settings.maxe) {
@ -17346,6 +17346,7 @@
name: file.name
}
}));
$$invalidate(0, files = []);
fireNotification("success", `File${files.length > 1 ? "s" : ""} successfully embedded!`);
} catch (err) {
const e2 = err;
@ -17369,6 +17370,8 @@
$$invalidate(6, processors2 = $$props2.processors);
if ("textinput" in $$props2)
$$invalidate(5, textinput = $$props2.textinput);
if ("files" in $$props2)
$$invalidate(0, files = $$props2.files);
};
return [
files,
@ -17384,7 +17387,7 @@
var PostOptions = class extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance9, create_fragment9, safe_not_equal, { processors: 6, textinput: 5 }, add_css8);
init(this, options, instance9, create_fragment9, safe_not_equal, { processors: 6, textinput: 5, files: 0 }, add_css8);
}
get processors() {
return this.$$.ctx[6];
@ -17400,6 +17403,13 @@
this.$$set({ textinput });
flush();
}
get files() {
return this.$$.ctx[0];
}
set files(files) {
this.$$set({ files });
flush();
}
};
var PostOptions_default = PostOptions;
@ -21317,10 +21327,21 @@
});
document.addEventListener("QRDialogCreation", (e) => {
const a = document.createElement("span");
new PostOptions_default({
const po = new PostOptions_default({
target: a,
props: { processors, textinput: (e.detail || e.target).querySelector("textarea") }
});
document.addEventListener("keydown", (e2) => {
if (e2.ctrlKey && (e2.key == "Enter" || e2.keyCode == 13)) {
if (po.files.length > 0) {
e2.preventDefault();
e2.stopImmediatePropagation();
e2.stopPropagation();
fireNotification("error", "You have files you forgot to embed!", 3e3);
return false;
}
}
}, true);
let target;
if (!cappState.is4chanX) {
target = e.detail;
@ -21329,6 +21350,29 @@
} else {
target = e.target;
target.querySelector("#qr-filename-container")?.appendChild(a);
const sub = target.querySelector("input[type=submit]");
sub.addEventListener("click", (e2) => {
if (po.files.length > 0) {
e2.preventDefault();
e2.stopImmediatePropagation();
e2.stopPropagation();
fireNotification("error", "You have files you forgot to embed!", 3e3);
return false;
}
}, true);
const obs = new MutationObserver((m) => {
for (const r of m) {
switch (r.type) {
case "attributes":
break;
case "characterData":
break;
}
}
});
obs.observe(sub, {
attributes: true
});
}
}, { once: !cappState.is4chanX });
var customStyles = document.createElement("style");

3
src/Components/PostOptions.svelte

@ -7,7 +7,7 @@
export let processors: ImageProcessor[] = []
export let textinput: HTMLTextAreaElement
let files: File[] = []
export let files: File[] = []
const addContent = (...newfiles: File[]) => {
files = [...files, ...newfiles]
@ -51,6 +51,7 @@
detail: { file: new Blob([buff], { type }), name: file.name },
}),
)
files = [];
fireNotification(
'success',
`File${files.length > 1 ? 's' : ''} successfully embedded!`,

35
src/main.ts

@ -392,11 +392,27 @@ document.addEventListener('ThreadUpdate', <any>(async (e: CustomEvent<any>) => {
document.addEventListener('QRDialogCreation', <any>((e: CustomEvent<HTMLElement>) => {
const a = document.createElement('span');
new PostOptions({
const po = new PostOptions({
target: a,
props: { processors, textinput: (e.detail || e.target).querySelector('textarea')! }
});
const checkEvent = (e: Event) => {
if ((po as any).files.length > 0) {
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
fireNotification("error", "You have files you forgot to embed!");
return false;
}
};
document.addEventListener("keydown", (e) => {
if (e.ctrlKey && (e.key == "Enter" || e.keyCode == 13)) {
return checkEvent(e);
}
}, true);
let target;
if (!cappState.is4chanX) {
target = e.detail;
@ -406,6 +422,23 @@ document.addEventListener('QRDialogCreation', <any>((e: CustomEvent<HTMLElement>
else {
target = e.target as HTMLDivElement;
target.querySelector('#qr-filename-container')?.appendChild(a);
const sub = target.querySelector("input[type=submit]") as HTMLElement;
sub.addEventListener("click", checkEvent, true);
const obs = new MutationObserver((m) => {
for (const r of m) {
switch (r.type) {
case "attributes":
break;
case "characterData":
break;
}
}
});
obs.observe(sub, {
attributes: true
});
}
}), { once: !cappState!.is4chanX }); // 4chan's normal extension destroys the QR form everytime

Loading…
Cancel
Save