Hier mal eine Idee als Userscript (Violentmonkey/Tampermonkey sonstige *mokeys) und Browserunabhängig. Also egal ob FF oder Chrome oder irgendwas derartig basiertes.
Bitte mal mit testen wer Lust hat.
erkennt JPEG, PNG, GIF, WebP, AVIF und SVG anhand des Inhalts - auch dann wenn die Dateiendung fehlt
keine Speicherung auf Festplatte
// ==UserScript==
// @name UbuntuUsers Bilder direkt öffnen (vollständig)
// @namespace Violentmonkey
// @author schwarzheit
// @version 2.0
// @description Öffnet Bildanhänge von ubuntuusers direkt und prüft den echten Dateiinhalt.
// @match https://*.ubuntuusers.de/*
// @grant GM_xmlhttpRequest
// @connect media-cdn.ubuntu-de.org
// ==/UserScript==
(function () {
'use strict';
// Prüft die tatsächlichen Dateidaten
// und nicht nur Dateiendungen oder Dateinamen
function erkenneBild(buffer) {
const bytes = new Uint8Array(buffer);
// JPEG
if (
bytes[0] === 0xff &&
bytes[1] === 0xd8 &&
bytes[2] === 0xff
) {
return "image/jpeg";
}
// PNG
if (
bytes[0] === 0x89 &&
bytes[1] === 0x50 &&
bytes[2] === 0x4e &&
bytes[3] === 0x47
) {
return "image/png";
}
// GIF
const text6 = new TextDecoder().decode(bytes.slice(0, 6));
if (
text6 === "GIF87a" ||
text6 === "GIF89a"
) {
return "image/gif";
}
// WebP
const text12 = new TextDecoder().decode(bytes.slice(0, 12));
if (
text12.startsWith("RIFF") &&
text12.substring(8, 12) === "WEBP"
) {
return "image/webp";
}
// AVIF
// ISO Base Media File Format:
// Bytes 4-11 enthalten den Brand-Namen
const text16 = new TextDecoder().decode(bytes.slice(4, 16));
if (
text16.includes("avif") ||
text16.includes("avis")
) {
return "image/avif";
}
// SVG
const text = new TextDecoder().decode(bytes.slice(0, 500));
if (
text.includes("<svg") ||
text.includes("<?xml")
) {
return "image/svg+xml";
}
// Kein bekanntes Bildformat
return null;
}
// Alle Klicks auf der Ubuntuusers-Seite überwachen
document.addEventListener(
"click",
function (e) {
const link = e.target.closest("a");
if (!link) {
return;
}
const url = link.href;
// Nur echte Ubuntuusers-CDN-Dateien prüfen
if (
!url.startsWith(
"https://media-cdn.ubuntu-de.org/"
)
) {
return;
}
// Original-Download verhindern
e.preventDefault();
e.stopImmediatePropagation();
// Datei in den Arbeitsspeicher laden
GM_xmlhttpRequest({
method: "GET",
url: url,
responseType: "arraybuffer",
onload: function (antwort) {
const bildtyp =
erkenneBild(
antwort.response
);
// Keine Bilddatei erkannt
if (!bildtyp) {
alert(
"Die Datei ist kein unterstütztes Bild."
);
return;
}
// Erst nach erfolgreicher Prüfung anzeigen
const blob = new Blob(
[
antwort.response
],
{
type: bildtyp
}
);
const blobUrl =
URL.createObjectURL(
blob
);
const tab =
window.open();
tab.document.write(`
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Bild</title>
</head>
<body style="
margin:0;
background:#222;
display:flex;
justify-content:center;
align-items:center;
height:100vh;
">
<img src="${blobUrl}" style="
max-width:100%;
max-height:100%;
">
</body>
</html>
`);
tab.document.close();
},
onerror: function () {
alert(
"Bild konnte nicht geladen werden."
);
}
});
},
true
);
})();Nachtrag: Ich werde mir trotzdem keine dummen Bildanhänge anguggen.
Nachtrag 2: ich find atm keine jpeg, gif und svg Dateien im Forum zum testen. Wenn jemand welche hat einfach mal zum testen anhängen. Danke.