Browse Source

Enable download button for unhandled types

pull/7/head
coomdev 2 years ago
parent
commit
db3d1c42a1
  1. 13
      main.user.js
  2. 10
      src/main.ts

13
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.38
// @version 0.39
// @description uhh
// @author You
// @match https://boards.4channel.org/*/thread/*
@ -12624,7 +12624,7 @@
inlining = false;
a = document.createRange().createContextualFragment(cf).children[0];
}
const type = await fileTypeFromBuffer(res.data);
let type = await fileTypeFromBuffer(res.data);
let cont;
let w, h;
if (type?.mime.startsWith("image")) {
@ -12637,16 +12637,15 @@
} else if (type?.mime.startsWith("audio")) {
cont = document.createElement("audio");
cont.autoplay = true;
} else if (type) {
} else {
if (!type)
type = { mime: "application/unknown", "ext": "data" };
cont = document.createElement("a");
let fn = res.filename;
if (!fn.includes("."))
fn += "." + type.ext;
cont.download = fn;
a.textContent = "Download " + cont.download;
} else {
debugger;
return;
cont.textContent = "Download " + cont.download;
}
let src;
src = post.getAttribute("data-processed");

10
src/main.ts

@ -88,7 +88,8 @@ const processPost = async (post: HTMLDivElement) => {
if (!a) {
inlining = false;
a = document.createRange().createContextualFragment(cf).children[0] as HTMLAnchorElement;
} const type = await fileTypeFromBuffer(res.data);
}
let type = await fileTypeFromBuffer(res.data);
let cont: HTMLImageElement | HTMLVideoElement | HTMLAudioElement | HTMLAnchorElement;
let w: number, h: number;
if (type?.mime.startsWith("image")) {
@ -101,15 +102,16 @@ const processPost = async (post: HTMLDivElement) => {
} else if (type?.mime.startsWith("audio")) {
cont = document.createElement("audio");
cont.autoplay = true;
} else if (type) {
} else {
// If type detection fails, you'd better have an extension
if (!type)
type = { mime: "application/unknown" as any, 'ext': "data" as any };
cont = document.createElement('a');
let fn = res.filename;
if (!fn.includes('.'))
fn += '.' + type.ext;
cont.download = fn;
cont.textContent = "Download " + cont.download;
} else {
return; // don't know what kind of file: don't touch
}
let src: string | null;

Loading…
Cancel
Save