inject.js aktualisiert
This commit is contained in:
170
inject.js
170
inject.js
@@ -28,6 +28,26 @@
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("audioDownloadRequested", function(e) {
|
||||
try {
|
||||
let t = e.detail.url;
|
||||
let l = e.detail.name;
|
||||
tel_download_audio(t, l);
|
||||
} catch (err) {
|
||||
console.error('Error in audioDownloadRequested handler', err);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("documentDownloadRequested", function(e) {
|
||||
try {
|
||||
let t = e.detail.url;
|
||||
let l = e.detail.name;
|
||||
tel_download_document(t, l);
|
||||
} catch (err) {
|
||||
console.error('Error in documentDownloadRequested handler', err);
|
||||
}
|
||||
});
|
||||
|
||||
// Hilfsfunktion: progress-bar-container
|
||||
function ensureProgressContainer() {
|
||||
let container = document.getElementById("tel-downloader-progress-bar-container");
|
||||
@@ -377,20 +397,162 @@
|
||||
|
||||
const tel_download_image = (src, suggestedName) => {
|
||||
try {
|
||||
const safe = sanitizeFilenamePreserveFriendly(suggestedName || 'image') + "_" + Date.now() + ".jpg";
|
||||
console.log('=== IMAGE DOWNLOAD START ===');
|
||||
console.log('Image URL:', src);
|
||||
console.log('Suggested name:', suggestedName);
|
||||
|
||||
const baseName = sanitizeFilenamePreserveFriendly(suggestedName || 'telegram_image');
|
||||
const hasExt = /\.(jpg|jpeg|png|gif|webp)$/i.test(baseName);
|
||||
const finalName = hasExt ? baseName : (baseName + '.jpg');
|
||||
|
||||
fetch(src, {
|
||||
method: "GET",
|
||||
credentials: "include"
|
||||
}).then(res => {
|
||||
if (!res.ok) throw new Error("Fetch failed: " + res.status);
|
||||
|
||||
// Detect image type
|
||||
const contentType = res.headers.get("Content-Type") || "";
|
||||
let ext = "jpg";
|
||||
if (contentType.includes("png")) ext = "png";
|
||||
else if (contentType.includes("gif")) ext = "gif";
|
||||
else if (contentType.includes("webp")) ext = "webp";
|
||||
|
||||
const finalNameWithExt = hasExt ? baseName : (baseName + '.' + ext);
|
||||
|
||||
return res.blob().then(blob => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
document.body.appendChild(a);
|
||||
a.href = src;
|
||||
a.download = safe;
|
||||
a.href = url;
|
||||
a.download = finalNameWithExt;
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
setTimeout(() => URL.revokeObjectURL(url), 2000);
|
||||
console.log('Image downloaded:', finalNameWithExt);
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Image download error:', err);
|
||||
alert('Bild-Download fehlgeschlagen. Versuche es erneut.');
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('tel_download_image error', err);
|
||||
}
|
||||
};
|
||||
|
||||
const tel_download_audio = (src, suggestedName) => {
|
||||
try {
|
||||
console.log('=== AUDIO DOWNLOAD START ===');
|
||||
console.log('Audio URL:', src);
|
||||
console.log('Suggested name:', suggestedName);
|
||||
|
||||
const baseName = sanitizeFilenamePreserveFriendly(suggestedName || 'telegram_audio');
|
||||
const hasExt = /\.(mp3|ogg|wav|m4a|opus)$/i.test(baseName);
|
||||
|
||||
const id = (Math.random() + 1).toString(36).substring(2, 10) + "_" + Date.now().toString();
|
||||
|
||||
createProgressBar(id, baseName + (hasExt ? '' : '.mp3'));
|
||||
updateProgress(id, baseName + (hasExt ? '' : '.mp3'), 0);
|
||||
|
||||
fetch(src, {
|
||||
method: "GET",
|
||||
credentials: "include"
|
||||
}).then(res => {
|
||||
if (!res.ok) throw new Error("Fetch failed: " + res.status);
|
||||
|
||||
const contentType = res.headers.get("Content-Type") || "";
|
||||
let ext = "mp3";
|
||||
if (contentType.includes("ogg")) ext = "ogg";
|
||||
else if (contentType.includes("wav")) ext = "wav";
|
||||
else if (contentType.includes("m4a")) ext = "m4a";
|
||||
else if (contentType.includes("opus")) ext = "opus";
|
||||
|
||||
const finalName = hasExt ? baseName : (baseName + '.' + ext);
|
||||
|
||||
return res.blob().then(blob => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
document.body.appendChild(a);
|
||||
a.href = url;
|
||||
a.download = finalName;
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
setTimeout(() => URL.revokeObjectURL(url), 2000);
|
||||
|
||||
updateProgress(id, finalName, 100);
|
||||
completeProgress(id, null, finalName, null, null);
|
||||
console.log('Audio downloaded:', finalName);
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Audio download error:', err);
|
||||
AbortProgress(id);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('tel_download_audio error', err);
|
||||
}
|
||||
};
|
||||
|
||||
const tel_download_document = (src, suggestedName) => {
|
||||
try {
|
||||
console.log('=== DOCUMENT DOWNLOAD START ===');
|
||||
console.log('Document URL:', src);
|
||||
console.log('Suggested name:', suggestedName);
|
||||
|
||||
const baseName = sanitizeFilenamePreserveFriendly(suggestedName || 'telegram_file');
|
||||
const hasExt = /\.\w{2,5}$/i.test(baseName);
|
||||
|
||||
const id = (Math.random() + 1).toString(36).substring(2, 10) + "_" + Date.now().toString();
|
||||
|
||||
createProgressBar(id, baseName);
|
||||
updateProgress(id, baseName, 0);
|
||||
|
||||
fetch(src, {
|
||||
method: "GET",
|
||||
credentials: "include"
|
||||
}).then(res => {
|
||||
if (!res.ok) throw new Error("Fetch failed: " + res.status);
|
||||
|
||||
const contentType = res.headers.get("Content-Type") || "";
|
||||
let ext = "";
|
||||
|
||||
// Erkenne Extension aus Content-Type
|
||||
if (contentType.includes("zip")) ext = "zip";
|
||||
else if (contentType.includes("rar")) ext = "rar";
|
||||
else if (contentType.includes("pdf")) ext = "pdf";
|
||||
else if (contentType.includes("msword")) ext = "doc";
|
||||
else if (contentType.includes("spreadsheet")) ext = "xlsx";
|
||||
else if (contentType.includes("audio/mpeg")) ext = "mp3";
|
||||
else if (contentType.includes("audio/")) ext = "mp3";
|
||||
|
||||
const finalName = hasExt ? baseName : (baseName + (ext ? '.' + ext : ''));
|
||||
|
||||
return res.blob().then(blob => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
document.body.appendChild(a);
|
||||
a.href = url;
|
||||
a.download = finalName;
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
setTimeout(() => URL.revokeObjectURL(url), 2000);
|
||||
|
||||
updateProgress(id, finalName, 100);
|
||||
completeProgress(id, null, finalName, null, null);
|
||||
console.log('Document downloaded:', finalName);
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Document download error:', err);
|
||||
AbortProgress(id);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('tel_download_document error', err);
|
||||
}
|
||||
};
|
||||
|
||||
window.telDownloader = {
|
||||
startVideo: tel_download_video,
|
||||
startImage: tel_download_image
|
||||
startImage: tel_download_image,
|
||||
startAudio: tel_download_audio,
|
||||
startDocument: tel_download_document
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user