var el = document.createElement("div");
el.id="mb-wlp"
var s = document.currentScript;
s.parentNode.insertBefore(el, s.nextSibling);
var aesScript = document.createElement("script");
aesScript.type = "text/javascript";
aesScript.onload = function() {
console.log("aes ready");
}
aesScript.src = "https://www.pic-mediabox.de/js/aes.js";
document.getElementsByTagName("head")[0].appendChild(aesScript);
(()=>{
getCss();
getFiles();
})()
async function getCss() {
const response = await fetch('https://www.pic-mediabox.de/desktop/wlp/getDisplayStyleAjax?sharelink='+s.dataset.sharelink);
const css = await response.json();
if (css.status == 1) {
el.innerHTML += "";
} else {
console.log("something is wrong", " : ", "getCss");
}
}
async function getFiles() {
const response = await fetch('https://www.pic-mediabox.de/desktop/wlp/getDisplayFilesAjax?sharelink='+s.dataset.sharelink);
const files = await response.json();
if (files.status == 1) {
drawFiles(files.data)
} else {
console.log("something is wrong", " : ", "getFiles");
}
}
function drawFiles(data) {
const tbl_tpl = `
`;
let tr = "";
for (let i in data) {
file = data[i];
if(file.file_ext == "enc"){
tr += `
${file.file_name} |
${Math.round(file.file_size/1024)} KB |
`
}else{
tr += `
${file.file_name} |
${Math.round(file.file_size/1024)} KB |
`
}
}
let tbl_tpl_repl = tbl_tpl.replace("###ROWS###",tr);
tbl_tpl_repl +=``
el.innerHTML += tbl_tpl_repl;
}
function startDownload(){
const dialog = document.querySelector("dialog");
const pass = document.querySelector("#mbFilePasswort").value;
dialog.close();
console.log(pass);
chunkyDownload(dialog.dataset.id, 0, pass);
}
function opneDialog(id, fileName){
const dialog = document.querySelector("dialog");
dialog.dataset.id = id
dialog.dataset.fileName = fileName
dialog.showModal();
dialog.addEventListener("click", (event) => {
if (event.target === dialog) {
document.querySelector("#mbFilePasswort").value = ""
dialog.close();
}
});
}
async function chunkyDownload(file, line, myPass, chunks = []) {
const response = await fetch("https://www.pic-mediabox.de/desktop/wlp/getFileToDownloadEncAjax/?share_id=" + file+"&l="+line);
let fileLine = await response.text();
//console.log(fileLine);
line++;
if (fileLine != "") {
chunkArr = fileLine.split("||");
let lineDecrypt = CryptoJS.AES.decrypt(chunkArr[1], myPass).toString(CryptoJS.enc.Latin1);
try {
lineDecrypt = _base64ToArrayBuffer(lineDecrypt);
} catch (e) {
alert("Das Passwort ist falsch");
return false;
}
///console.log(e);
chunks[chunkArr[0]] = lineDecrypt;
delete chunkArr;
chunkyDownload(file, line, myPass,chunks)
} else {
var blob = new Blob(chunks);
var urlCreator = window.URL || window.webkitURL || {}.createObjectURL
var objectUrl = urlCreator.createObjectURL(blob);
//name = $(".mpv_active").attr("data-name");
document.querySelector("#mbFilePasswort").value = ""
forceBrowserDownload(objectUrl);
}
}
function _base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
function forceBrowserDownload(href) {
const dialog = document.querySelector("dialog");
var link = document.createElement('a');
link.setAttribute('href', href);
link.setAttribute('download', dialog.dataset.fileName.replace(".enc", ""));
link.setAttribute('target', '_blank');
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}