mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2025-02-28 03:43:35 +01:00
horrible notifications
This commit is contained in:
parent
7d87fb50ca
commit
c93a3aacbb
@ -1,3 +1,7 @@
|
|||||||
|
if (Notification.permission == "default") {
|
||||||
|
Notification.requestPermission();
|
||||||
|
}
|
||||||
|
|
||||||
// Minecraft.id
|
// Minecraft.id
|
||||||
let urlParams = new URLSearchParams();
|
let urlParams = new URLSearchParams();
|
||||||
window.location.hash.substr(1).split("?").map(it => new URLSearchParams(it).forEach((a, b) => urlParams.append(b, a)));
|
window.location.hash.substr(1).split("?").map(it => new URLSearchParams(it).forEach((a, b) => urlParams.append(b, a)));
|
||||||
@ -27,6 +31,13 @@ var listening = document.getElementById("listening");
|
|||||||
var actions = document.getElementById("actions");
|
var actions = document.getElementById("actions");
|
||||||
var accounts = document.getElementById("accounts-list");
|
var accounts = document.getElementById("accounts-list");
|
||||||
var listenVisible = false;
|
var listenVisible = false;
|
||||||
|
var pageBlur = false;
|
||||||
|
document.addEventListener("focus", () => {
|
||||||
|
pageBlur = false;
|
||||||
|
});
|
||||||
|
document.addEventListener("blur", () => {
|
||||||
|
pageBlur = true;
|
||||||
|
});
|
||||||
|
|
||||||
// Util
|
// Util
|
||||||
isMojang = it => !!it.clientToken;
|
isMojang = it => !!it.clientToken;
|
||||||
@ -239,7 +250,9 @@ function renderActions() {
|
|||||||
addAction("Listen to premium login in VIAaaS instance", () => {
|
addAction("Listen to premium login in VIAaaS instance", () => {
|
||||||
let user = prompt("Premium username (case-sensitive): ", "");
|
let user = prompt("Premium username (case-sensitive): ", "");
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
let callbackUrl = new URL(location.origin + location.pathname + "#username=" + encodeURIComponent(user));
|
let callbackUrl = new URL(location);
|
||||||
|
callbackUrl.search = "";
|
||||||
|
callbackUrl.hash = "#username=" + encodeURIComponent(user);
|
||||||
location = "https://api.minecraft.id/gateway/start/" + encodeURIComponent(user)
|
location = "https://api.minecraft.id/gateway/start/" + encodeURIComponent(user)
|
||||||
+ "?callback=" + encodeURIComponent(callbackUrl);
|
+ "?callback=" + encodeURIComponent(callbackUrl);
|
||||||
});
|
});
|
||||||
@ -277,8 +290,31 @@ function listen(token) {
|
|||||||
function confirmJoin(hash) {
|
function confirmJoin(hash) {
|
||||||
socket.send(JSON.stringify({action: "session_hash_response", session_hash: hash}));
|
socket.send(JSON.stringify({action: "session_hash_response", session_hash: hash}));
|
||||||
}
|
}
|
||||||
|
function authNotification(msg, yes, no) {
|
||||||
|
if (!pageBlur || (false && Notification.permission != "granted")) {
|
||||||
|
if (confirm(msg)) yes(); else no();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let notification = new Notification("Click to allow auth impersionation", {
|
||||||
|
body: msg,
|
||||||
|
//actions: [
|
||||||
|
// {action: "reject", title: "Reject"},
|
||||||
|
// {action: "confirm", title: "Confirm"}
|
||||||
|
//]
|
||||||
|
});
|
||||||
|
notification.onclick = e => {
|
||||||
|
if (e.action == "reject") {
|
||||||
|
no();
|
||||||
|
} else if (!e.action || e.action == "confirm") {
|
||||||
|
yes();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
notification.close();
|
||||||
|
};
|
||||||
|
}
|
||||||
function handleJoinRequest(parsed) {
|
function handleJoinRequest(parsed) {
|
||||||
if (confirm("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'")) {
|
authNotification("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'", () => {
|
||||||
let account = findAccountByMcName(parsed.user);
|
let account = findAccountByMcName(parsed.user);
|
||||||
if (account) {
|
if (account) {
|
||||||
getMcUserToken(account).then(data => {
|
getMcUserToken(account).then(data => {
|
||||||
@ -288,12 +324,10 @@ function handleJoinRequest(parsed) {
|
|||||||
.finally(() => confirmJoin(parsed.session_hash))
|
.finally(() => confirmJoin(parsed.session_hash))
|
||||||
.catch((e) => alert("Couldn't contact session server for " + parsed.user + " account in browser. error: " + e));
|
.catch((e) => alert("Couldn't contact session server for " + parsed.user + " account in browser. error: " + e));
|
||||||
} else {
|
} else {
|
||||||
|
confirmJoin(parsed.session_hash);
|
||||||
alert("Couldn't find " + parsed.user + " account in browser.");
|
alert("Couldn't find " + parsed.user + " account in browser.");
|
||||||
confirmJoin(parsed.session_hash);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
confirmJoin(parsed.session_hash);
|
|
||||||
}
|
}
|
||||||
|
}, () => confirmJoin(parsed.session_hash));
|
||||||
}
|
}
|
||||||
function onSocketMsg(event) {
|
function onSocketMsg(event) {
|
||||||
let parsed = JSON.parse(event.data);
|
let parsed = JSON.parse(event.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user