Compatibility tweaks
- Fix (i hope all) electron issues - Add complete blah support - Add userscript
This commit is contained in:
parent
588d55abf8
commit
7ff648ba3a
19 changed files with 478 additions and 576 deletions
204
webroot/main.js
204
webroot/main.js
|
|
@ -1,50 +1,74 @@
|
|||
console.log(window.location.protocol);
|
||||
var prot = window.location.protocol;
|
||||
|
||||
var url = `${window.location.protocol}//${window.location.hostname}/_larpix`;
|
||||
async function updateProtocolAndUrl(host)
|
||||
{
|
||||
prot = window.location.protocol == "miarven:" ? "http:" : window.location.protocol;
|
||||
if (prot == "http:") {
|
||||
try {
|
||||
JSON.parse(await fetchAsync(`${prot}//${host}/_larpix/serverinfo`));
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
JSON.parse(await fetchAsync(`https://${host}/_larpix/serverinfo`));
|
||||
prot = "https:";
|
||||
}
|
||||
catch (error) {}
|
||||
}
|
||||
}
|
||||
url = `${prot}//${host}/_larpix`;
|
||||
}
|
||||
|
||||
console.log(prot);
|
||||
|
||||
var url = `${prot}//${window.location.hostname}/_larpix`;
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
|
||||
const collapseDmsBtn = document.getElementById("collapse-dms");
|
||||
const collapseGroupsBtn = document.getElementById("collapse-groups");
|
||||
|
||||
const addDmBtn = document.getElementById("add-dm-btn");
|
||||
const addGroupBtn = document.getElementById("add-group-btn");
|
||||
|
||||
const sidebarHome = document.getElementById("sidebar-home");
|
||||
const sidebarHomeButton = sidebarHome.children.item(1);
|
||||
const sidebarHomeIndicator = sidebarHome.children.item(0);
|
||||
|
||||
const sidebarAdd = document.getElementById("sidebar-add");
|
||||
const sidebarAddButton = sidebarAdd.children.item(1);
|
||||
const sidebarAddIndicator = sidebarAdd.children.item(0);
|
||||
|
||||
const roomDetailsBar = document.getElementById("roomdetailsbar");
|
||||
const roomContent = document.getElementsByTagName("roomcontent")[0];
|
||||
const roomsBar = document.getElementById("roomsbar");
|
||||
const sideBar = document.getElementsByTagName("sidebar")[0];
|
||||
|
||||
const roomContentMain = document.getElementsByTagName("roomcontent2")[0];
|
||||
|
||||
const roomContentBar = roomContent.children[0];
|
||||
try {
|
||||
|
||||
|
||||
var collapseDmsBtn = document.getElementById("collapse-dms");
|
||||
var collapseGroupsBtn = document.getElementById("collapse-groups");
|
||||
|
||||
var addDmBtn = document.getElementById("add-dm-btn");
|
||||
var addGroupBtn = document.getElementById("add-group-btn");
|
||||
|
||||
var sidebarHome = document.getElementById("sidebar-home");
|
||||
var sidebarHomeButton = sidebarHome.children.item(1);
|
||||
var sidebarHomeIndicator = sidebarHome.children.item(0);
|
||||
|
||||
var sidebarAdd = document.getElementById("sidebar-add");
|
||||
var sidebarAddButton = sidebarAdd.children.item(1);
|
||||
var sidebarAddIndicator = sidebarAdd.children.item(0);
|
||||
|
||||
var roomDetailsBar = document.getElementById("roomdetailsbar");
|
||||
var roomContent = document.getElementsByTagName("roomcontent")[0];
|
||||
var roomsBar = document.getElementById("roomsbar");
|
||||
var sideBar = document.getElementsByTagName("sidebar")[0];
|
||||
|
||||
var roomContentMain = document.getElementsByTagName("roomcontent2")[0];
|
||||
|
||||
var roomContentBar = roomContent.children[0];
|
||||
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
|
||||
function delay(time) {
|
||||
return new Promise(resolve => setTimeout(resolve, time));
|
||||
}
|
||||
|
||||
async function packetEncPass(pass, key, username) {
|
||||
return await encryptWithNonce(pass, key, getNonce(username, key));
|
||||
}
|
||||
|
||||
async function getNonce(username, key) {
|
||||
|
||||
|
||||
let nonce;
|
||||
let fetchRes = await (await fetch(`${url}/nextnonce?u=${username}`)).text();
|
||||
|
||||
try {
|
||||
nonce = await decryptString(fetchRes, key);
|
||||
}
|
||||
catch(err) {
|
||||
} catch (err) {
|
||||
nonce = await decryptString(fetchRes, "");
|
||||
}
|
||||
return nonce;
|
||||
|
|
@ -84,12 +108,13 @@ function keyDataFromServerJson(jsonFromServer) {
|
|||
return [p, g, pubServer, data.idKey]
|
||||
}
|
||||
|
||||
function base64ToUint8(base64) {
|
||||
function base64ToUint8(base64) {
|
||||
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
||||
}
|
||||
|
||||
function uint8ToBase64(uint8) {
|
||||
return fixBase64Padding(btoa(String.fromCharCode(...uint8)));
|
||||
}
|
||||
}
|
||||
|
||||
async function encrypt(plainText, keyBytes) {
|
||||
const iv = window.crypto.getRandomValues(new Uint8Array(16));
|
||||
|
|
@ -242,10 +267,10 @@ async function fetchPostEnc(url, value) {
|
|||
|
||||
async function fetchAsync(url) {
|
||||
let response = await fetch(url, {
|
||||
method: "GET",
|
||||
method: "GET",
|
||||
credentials: "omit"
|
||||
});
|
||||
|
||||
|
||||
let data = await response.text();
|
||||
return data;
|
||||
}
|
||||
|
|
@ -263,15 +288,13 @@ async function fetchAsyncWAuth(url) {
|
|||
return data;
|
||||
}
|
||||
|
||||
async function getServerInfo(host){
|
||||
console.log(`${window.location.protocol}//${host}/_larpix/serverinfo`)
|
||||
return JSON.parse(await fetchAsync(`${window.location.protocol}//${host}/_larpix/serverinfo`));
|
||||
async function getServerInfo(host) {
|
||||
console.log(`${prot}//${host}/_larpix/serverinfo`)
|
||||
return JSON.parse(await fetchAsync(`${prot}//${host}/_larpix/serverinfo`));
|
||||
}
|
||||
|
||||
async function Auth(username, password) {
|
||||
|
||||
|
||||
let passwordHash = await hashSHA3_512(password);
|
||||
let passwordHash = await hashSHA3_512(password);
|
||||
let response = await fetch(`${url}/auth?u=${username}`, {
|
||||
method: "GET",
|
||||
credentials: "omit",
|
||||
|
|
@ -286,16 +309,14 @@ async function Auth(username, password) {
|
|||
}
|
||||
|
||||
|
||||
async function fetchEncrypted(request, body)
|
||||
{
|
||||
async function fetchEncrypted(request, body) {
|
||||
|
||||
let nonce = await getNonce(username, passwordHash);
|
||||
|
||||
|
||||
let response = await fetch(`${url}/encryptedrequest?u=${username}`, {
|
||||
method: "POST",
|
||||
credentials: "omit",
|
||||
body: await encryptWithNonce(
|
||||
|
||||
JSON.stringify({
|
||||
string1: request,
|
||||
string2: body
|
||||
|
|
@ -335,6 +356,15 @@ function fixBase64Padding(base64String) {
|
|||
return str;
|
||||
}
|
||||
|
||||
function showBlahNotification(blahmessage, duration = 3500) {
|
||||
try {
|
||||
let split = blahmessage.split(":");
|
||||
showNotification(processBlah(blahmessage), split[0], duration);
|
||||
} catch (e) {
|
||||
showNotification(blahmessage, "info", duration);
|
||||
}
|
||||
}
|
||||
|
||||
function showNotification(message, type = 'info', duration = 3500) {
|
||||
let container = document.getElementById('notification-container');
|
||||
if (!container) {
|
||||
|
|
@ -386,40 +416,99 @@ function showAction(message, actionid) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
function clearAction(actionid) {
|
||||
const notifications = document.querySelectorAll(`[id="notification-${actionid}"]`);
|
||||
|
||||
let notif = document.getElementById(`notification-${actionid}`);
|
||||
notif.classList.remove('show');
|
||||
notifications.forEach(notif => {
|
||||
notif.classList.remove('show');
|
||||
|
||||
notif.addEventListener('transitionend', () => {
|
||||
notif.remove();
|
||||
notif.addEventListener('transitionend', () => {
|
||||
notif.remove();
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function hashSHA3_512(input) {
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(input);
|
||||
const data = encoder.encode(input);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-512', data); //-3 kiedys xddddddddddddddddd
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
return hashHex;
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
return hashHex;
|
||||
}
|
||||
|
||||
var blah;
|
||||
|
||||
async function initBlahs() {
|
||||
lang = lang.toLowerCase();
|
||||
let res;
|
||||
|
||||
let path = window.location.pathname.replace("/login/index.html", "/");
|
||||
|
||||
try { //try user lang first
|
||||
res = await fetchAsync(`${path}blah/${lang}.json`);
|
||||
} catch (e) { //fallback to en-us
|
||||
res = await fetchAsync(`${path}blah/en-us.json`);
|
||||
}
|
||||
blah = JSON.parse(res);
|
||||
}
|
||||
|
||||
function processBlah(blahmessage) {
|
||||
try {
|
||||
let split = blahmessage.split(":");
|
||||
let values = [];
|
||||
try {
|
||||
values = split[2].split(";");
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
let message = blah[split[1]];
|
||||
|
||||
let valueslist = "";
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
let value = values[i];
|
||||
valueslist+=`${values[i]}, `;
|
||||
processBlah(value);
|
||||
|
||||
message = message.replaceAll(`{${i}}`, value);
|
||||
}
|
||||
valueslist = valueslist.slice(0, -2);
|
||||
if (message.includes('{all}')) {
|
||||
|
||||
message = message.replaceAll('{all}', valueslist);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
return blahmessage;
|
||||
}
|
||||
}
|
||||
|
||||
function getLang() {
|
||||
return (navigator.language || navigator.languages[0]);
|
||||
}
|
||||
|
||||
var password = "";
|
||||
var username = "";
|
||||
var passwordHash = "";
|
||||
var host = "";
|
||||
async function mainJS()
|
||||
{
|
||||
username = localStorage.getItem('username');
|
||||
password = localStorage.getItem('password');
|
||||
host = localStorage.getItem('host');
|
||||
var lang = getLang();
|
||||
|
||||
async function mainJS() {
|
||||
await initBlahs();
|
||||
|
||||
passwordHash = await hashSHA3_512(password);
|
||||
url = `${window.location.protocol}//${host}/_larpix`;
|
||||
if (localStorage.getItem('lang') != null) {
|
||||
lang = localStorage.getItem('lang');
|
||||
}
|
||||
}
|
||||
username = localStorage.getItem('username');
|
||||
password = localStorage.getItem('password');
|
||||
host = localStorage.getItem('host');
|
||||
mainJS();
|
||||
|
||||
collapseDmsBtn.addEventListener("click", () => {
|
||||
|
|
@ -430,7 +519,7 @@ collapseGroupsBtn.addEventListener("click", () => {
|
|||
});
|
||||
|
||||
addDmBtn.addEventListener("click", () => {
|
||||
roomContentMain.innerHTML =
|
||||
roomContentMain.innerHTML =
|
||||
`
|
||||
<div style="display: flex;justify-content: center;align-items: center;height:100%;flex-direction: column;text-align: center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="3rem" viewBox="0 -960 960 960" fill="var(--text-color)"><path d="M120-160v-600q0-33 23.5-56.5T200-840h480q33 0 56.5 23.5T760-760v203q-10-2-20-2.5t-20-.5q-10 0-20 .5t-20 2.5v-203H200v400h283q-2 10-2.5 20t-.5 20q0 10 .5 20t2.5 20H240L120-160Zm160-440h320v-80H280v80Zm0 160h200v-80H280v80Zm400 280v-120H560v-80h120v-120h80v120h120v80H760v120h-80ZM200-360v-400 400Z"/></svg>
|
||||
|
|
@ -450,9 +539,8 @@ addDmBtn.addEventListener("click", () => {
|
|||
`
|
||||
});
|
||||
addGroupBtn.addEventListener("click", () => {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
sidebarHomeButton.addEventListener("mouseenter", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue