MojoFrontend/scripts/onload.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-05-05 03:45:54 +00:00
var networkIssuesInformed = false;
2022-05-04 20:12:44 +00:00
function checkStatus(){
var status = document.getElementById("status");
sendCommand("", "ping").then(res => {
if (res.code == 200) {
status.classList.add("ready");
status.classList.remove("error");
2022-05-10 07:48:06 +00:00
document.getElementById("statusText").innerText = "正常";
2022-05-05 03:45:54 +00:00
networkIssuesInformed = false;
2022-05-04 20:12:44 +00:00
} else {
throw new Error("");
}
}).catch(err => {
status.classList.add("error");
status.classList.remove("ready");
2022-05-10 07:48:06 +00:00
document.getElementById("statusText").innerText = "已断开";
2022-05-05 03:45:54 +00:00
if (!networkIssuesInformed) {
2022-05-10 07:48:06 +00:00
message("监测到网络或授权问题,请尝试在游戏内重新获取链接。", "fail");
2022-05-05 03:45:54 +00:00
networkIssuesInformed = true;
}
2022-05-04 20:12:44 +00:00
})
}
2022-05-03 10:12:38 +00:00
document.addEventListener("DOMContentLoaded", () => {
const sidebarItems = document.querySelector("#sidebar").children;
for (const item of sidebarItems) {
item.onclick = (e) => switchPage(e.target.dataset.value)
}
2022-05-04 20:12:44 +00:00
checkStatus();
2022-05-04 23:38:48 +00:00
setInterval(() => { // check console status
2022-05-04 20:12:44 +00:00
checkStatus();
}, 30 * 1000 );
2022-05-04 23:38:48 +00:00
// adjust frame height
2022-05-05 01:16:56 +00:00
setTimeout(() => {
2022-05-04 23:38:48 +00:00
var height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
var content = document.getElementById("content");
2022-05-10 07:48:06 +00:00
var height1 = height - content.getBoundingClientRect().y - 30;
content.style.height = height1 + "px";
var area = document.getElementById("right");
area.style.height = height - area.getBoundingClientRect().y + "px";
message("欢迎使用MojoConsolePlus!");
2022-05-05 01:16:56 +00:00
},10); // delay height modification to avoid issues
2022-05-04 23:38:48 +00:00
})