Browse Source

Fix accidentally broken GIF embeds

pull/46/head
coomdev 2 years ago
parent
commit
03bbf13277
  1. 2
      main.meta.js
  2. 6
      main.user.js
  3. 2
      src/gif.ts
  4. 51
      src/main.ts
  5. 6
      src/requests.ts

2
main.meta.js

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

6
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.75
// @version 0.76
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -11176,7 +11176,7 @@
if (gcte)
endo += 3 * (1 << (field & 7) + 1);
if (netscape.compare(contbuff, endo, endo + netscape.byteLength) == 0)
endo += netscape.byteLength;
endo += 19;
await writer.write(contbuff.slice(0, endo));
await write_embedding(writer, import_buffer3.Buffer.from(await inj.arrayBuffer()));
await writer.write(contbuff.slice(endo));
@ -11218,7 +11218,7 @@
// src/requests.ts
init_esbuild_inject();
var xmlhttprequest = typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : typeof GM != "undefined" ? GM.xmlHttpRequest : GM_xmlhttpRequest;
var xmlhttprequest = typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : typeof GM != "undefined" ? GM.xmlHttpRequest : window["GM_xmlhttpRequest"];
var headerStringToObject = (s) => Object.fromEntries(s.split("\n").map((e) => {
const [name, ...rest] = e.split(":");
return [name.toLowerCase(), rest.join(":").trim()];

2
src/gif.ts

@ -78,7 +78,7 @@ const inject = async (container: File, inj: File) => {
endo += 3 * (1 << ((field & 7) + 1));
if (netscape.compare(contbuff, endo, endo + netscape.byteLength) == 0)
endo += netscape.byteLength;
endo += 19;
await writer.write(contbuff.slice(0, endo));
await write_embedding(writer, Buffer.from(await inj.arrayBuffer()));
await writer.write(contbuff.slice(endo));

51
src/main.ts

@ -173,7 +173,7 @@ const processPost = async (post: HTMLDivElement) => {
}
});
if (!ahem)
opFile?.append(imgcont);
opFile?.append(imgcont);
}
post.setAttribute('data-processed', "true");
@ -340,24 +340,31 @@ customStyles.appendChild(document.createTextNode(
document.documentElement.insertBefore(customStyles, null);
//import * as gif2 from './png';
//
//onload = () => {
// const container = document.getElementById("container") as HTMLInputElement;
// const injection = document.getElementById("injection") as HTMLInputElement;
// container.onchange = injection.onchange = async () => {
// if (container.files?.length && injection.files?.length) {
// const res = await gif2.inject(container.files[0], injection.files[0]);
// const result = document.getElementById("result") as HTMLImageElement;
// const extracted = document.getElementById("extracted") as HTMLImageElement;
// const res2 = new Blob([res], { type: 'image/gif' });
// result.src = URL.createObjectURL(res2);
// const embedded = await gif2.extract(res);
// extracted.src = URL.createObjectURL(new Blob([embedded?.data!]));
// const dlr = document.getElementById("dlr") as HTMLAnchorElement;
// const dle = document.getElementById("dle") as HTMLAnchorElement;
// dlr.href = result.src;
// dle.href = extracted.src;
// }
// };
//};
// if ((window as any)['pagemode']) {
// onload = () => {
// const resbuf = async (s: EmbeddedFile['data']) => Buffer.isBuffer(s) ? s : await s();
// const container = document.getElementById("container") as HTMLInputElement;
// const injection = document.getElementById("injection") as HTMLInputElement;
// container.onchange = injection.onchange = async () => {
// console.log('eval changed');
// if (container.files?.length && injection.files?.length) {
// const dlr = document.getElementById("dlr") as HTMLAnchorElement;
// const dle = document.getElementById("dle") as HTMLAnchorElement;
// const res = await gif.inject!(container.files[0], injection.files[0]);
// console.log('inj done');
// const result = document.getElementById("result") as HTMLImageElement;
// const extracted = document.getElementById("extracted") as HTMLImageElement;
// const res2 = new Blob([res], { type: 'image/gif' });
// result.src = URL.createObjectURL(res2);
// dlr.href = result.src;
// console.log('url created');
// const embedded = await gif.extract(res);
// if (!embedded)
// debugger;
// extracted.src = URL.createObjectURL(new Blob([await resbuf(embedded?.data!)]));
// dle.href = extracted.src;
// }
// };
// };
// }

6
src/requests.ts

@ -1,4 +1,8 @@
const xmlhttprequest = typeof GM_xmlhttpRequest != 'undefined' ? GM_xmlhttpRequest : (typeof GM != "undefined" ? GM.xmlHttpRequest : GM_xmlhttpRequest);
const xmlhttprequest = typeof GM_xmlhttpRequest != 'undefined' ?
GM_xmlhttpRequest :
(typeof GM != "undefined" ?
GM.xmlHttpRequest :
(window as any)['GM_xmlhttpRequest']);
export const headerStringToObject = (s: string) =>
Object.fromEntries(s.split('\n').map(e => {

Loading…
Cancel
Save