File "ponline.js"
Full path: /usr/home/mndrn/domains/mndrn.ru/public_html/pon3/ponline.js
File size: 3.85 KiB (3942 bytes)
MIME-type: text/plain
Charset: utf-8
"use strict";
let popen=false;
window.addEventListener("load", () => {
if(document.location.href.startsWith("file:")) {
alert("Файл должен быть открыт на http сервере!");
}else {
window.eaglercraftXOpts = {
container: "game_frame",
assetsURI: "assets.epk",
localesURI: "lang/",
servers: [
/* example: { addr: "ws://localhost:8081/", name: "Local test server" } */
]
};
}
});
function mshow(mopen){
if (mopen==false) {
document.querySelector(".dl-but").style.display="block";
}
if (mopen==true) {
document.querySelector(".dl-but").style.display="none";
}
}
function pshow(){
if (popen==false) {
popen=true;
document.querySelector(".pmenu").style.display="block";
return;
}
if (popen==true) {
popen=false;
document.querySelector(".pmenu").style.display="none";
return;
}
}
let canvas=undefined;
function addP(){
document.addEventListener("pointerlockchange",lcg,false);}
waitForElem("canvas",addP);
function waitForElem(selector, callback) {
const elem = document.querySelector(selector);
if (elem) {
callback();
canvas=elem;
} else {
setTimeout(() => {
waitForElem(selector, callback);
}, 100);
}
}
function lcg() {
if (document.pointerLockElement === canvas) {
mshow(true);
} else {
mshow(false);
}
}
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = src;
script.onload = () => {
resolve();
};
script.onerror = () => {
reject(new Error(`Error loading script ${src}`));
};
document.head.appendChild(script);
});
}
function prefetchAssets(d) {
return fetch(d)
.then(response => {
const total = response.headers.get('Content-Length');
let loaded = 0;
let chunks = [];
return new Promise(resolve => {
const reader = response.body.getReader();
const progressInterval = setInterval(() => {
document.querySelector("#progl").style.width=Math.round((loaded / total) * 100)+"%";
if (((loaded / total)*100).toFixed(2)==Infinity) {
document.querySelector(".load h1").innerHTML="100%";
document.querySelector("#progl").style.width="100%";
} else {
document.querySelector(".load h1").innerHTML=((loaded / total)*100).toFixed(2)+"%";}
console.log(`Prefetching assets.epk... ${Math.round((loaded / total) * 100)}%`);
}, 100);
function read() {
reader.read().then(result => {
if (result.done) {
clearInterval(progressInterval);
resolve();
} else {
loaded += result.value.length;
chunks.push(result.value);
read();
}
});
}
read();
}).then(() => {
const fileContent = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0));
let offset = 0;
chunks.forEach(chunk => {
fileContent.set(chunk, offset);
offset += chunk.length;
});
return fileContent;
});
});
}
prefetchAssets("assets.epk").then(()=>{
prefetchAssets("touch.js").then(()=>{
prefetchAssets("classes.js").then(()=>{
const script = document.createElement('script');
script.src = "classes.js";
script.onload = ()=>{document.querySelector(".load").style.display="none";
document.querySelector(".dsd").style.display="block";};
document.head.appendChild(script);
});
});
});