2022-05-04 23:38:03 +00:00
|
|
|
async function sendCommand(payload, method="invoke", background=false, persistent="auto") {
|
2022-05-03 09:40:07 +00:00
|
|
|
let key = new window.URLSearchParams(window.location.search).get("k");
|
|
|
|
let url = '/mojoplus/api';
|
2022-05-04 20:12:44 +00:00
|
|
|
let data = JSON.stringify({ "k": key, "request": method, "payload": payload });
|
2022-05-03 09:40:07 +00:00
|
|
|
|
2022-05-03 11:19:25 +00:00
|
|
|
let response = await fetch(url, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: data,
|
|
|
|
})
|
2022-05-03 09:40:07 +00:00
|
|
|
|
2022-05-03 11:19:25 +00:00
|
|
|
let json = await response.json();
|
2022-05-04 20:12:44 +00:00
|
|
|
if (method == 'invoke' && !background) {
|
2022-05-04 23:38:03 +00:00
|
|
|
var m = json.payload.trim().replace(/\r/g, "").replace(/\n\n/g, "\n");
|
|
|
|
console.log(json);
|
|
|
|
console.log(m);
|
|
|
|
if(persistent == "auto") {
|
|
|
|
var m2 = m.replace(/\n/g, "");
|
|
|
|
persistent = (m.length - m2.length) > 3; // true more than 3 lines
|
|
|
|
}
|
|
|
|
console.log(persistent);
|
|
|
|
message(`${m}`, null, persistent);
|
2022-05-04 20:12:44 +00:00
|
|
|
}
|
2022-05-03 11:19:25 +00:00
|
|
|
return json
|
2022-05-03 10:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 20:12:44 +00:00
|
|
|
function dismissMessage(){
|
|
|
|
document.getElementById("message").style.opacity = 1;
|
|
|
|
setTimeout(() => {
|
|
|
|
document.getElementById("message").classList.add("hide");
|
|
|
|
}, 500);
|
|
|
|
document.getElementById("message").style.opacity = 0;
|
|
|
|
}
|
|
|
|
|
2022-05-03 10:12:30 +00:00
|
|
|
function switchPage(page) {
|
|
|
|
const iframe = document.getElementById("content");
|
|
|
|
iframe.src = `pages/${page}.html`;
|
2022-05-04 20:12:44 +00:00
|
|
|
}
|
2022-05-04 23:38:03 +00:00
|
|
|
|
|
|
|
function message(message, className, persistent=false) {
|
|
|
|
var m = document.createElement("div");
|
|
|
|
m.classList.add("messageBox");
|
|
|
|
m.classList.add("initial");
|
|
|
|
if (className) m.classList.add(className);
|
|
|
|
var mc = document.createElement("div");
|
|
|
|
var dismissButton = document.createElement("button");
|
|
|
|
mc.classList.add("messageContent");
|
|
|
|
mc.innerText = message;
|
|
|
|
dismissButton.innerText = "Dissmiss";
|
|
|
|
m.appendChild(mc);
|
|
|
|
m.appendChild(dismissButton);
|
|
|
|
document.getElementById("message").appendChild(m);
|
|
|
|
dismissButton.onclick = (e) => {
|
|
|
|
dismissMessageInternal(e.target.parentNode);
|
|
|
|
}
|
|
|
|
// m.classList.remove("initial");
|
|
|
|
setTimeout(function() {
|
|
|
|
m.classList.remove("initial");
|
|
|
|
}, 100);
|
|
|
|
if (!persistent) setTimeout(() => dismissMessageInternal(m), 4000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dismissMessageInternal(target) {
|
|
|
|
if (target){
|
|
|
|
target.classList.add("finish");
|
|
|
|
setTimeout(()=>{target.remove();}, 400);
|
|
|
|
}
|
|
|
|
}
|