This commit is contained in:
choelzl 2022-02-08 15:59:11 +01:00
parent ca25cd55fd
commit 2a5eadc8cf
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
5 changed files with 46 additions and 53 deletions

View File

@ -16,7 +16,7 @@
function DBAddG(user,position) {
if(guesses[user] && guesses[user].length > 0){
}else{
}else if(isCoordinates(position)){
guesses[user] = position;
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
sendData('guesses',guesses);
@ -31,6 +31,11 @@
}));
}
function isCoordinates(coordinates) {
const regex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g;
return regex.test(coordinates);
};
$.bind('command', function(event) {
const sender = "" + event.getSender().toLowerCase(),

View File

@ -28,7 +28,7 @@ class GameHandler {
// Browser Listening
this.win.webContents.on("did-navigate-in-page", (e, url) => {
if (GameHelper.isGameURL(url)) {
if (isGameURL(url)) {
game.start(url, settings.isMultiGuess).then(() => {
this.win.webContents.send("game-started", game.isMultiGuess);
TMI.action(`${game.round == 1 ? "🌎 A new seed of " + game.mapName : "🌎 Round " + game.round} has started`);
@ -111,7 +111,11 @@ window.addEventListener("DOMContentLoaded", () => {
const head = document.getElementsByTagName("head")[0];
const styles = document.createElement("link");
styles.rel = "stylesheet";
styles.type = "text/css";
styles.href = `${path.join(__dirname, "./public/styles.css")}`;
head.appendChild(styles);
const scoreboardContainer = document.createElement("div");
scoreboardContainer.setAttribute("id", "scoreboardContainer");
@ -140,7 +144,25 @@ window.addEventListener("DOMContentLoaded", () => {
</div>`;
document.body.appendChild(scoreboardContainer);
const flagIcon = document.createElement("link");
flagIcon.rel = "stylesheet";
flagIcon.type = "text/css";
flagIcon.href = `${path.join(__dirname, "./public/flag-icon.min.css")}`;
head.appendChild(flagIcon);
const jqueryUI = document.createElement("script");
jqueryUI.type = "text/javascript";
jqueryUI.src = `${path.join(__dirname, "./public/jquery-ui.min.js")}`;
jqueryUI.addEventListener("load", () => loadDatatables());
document.body.appendChild(jqueryUI);
const loadDatatables = () => {
const datatables = document.createElement("script");
datatables.type = "text/javascript";
datatables.src = `${path.join(__dirname, "./public/datatables.bundle.min.js")}`;
datatables.addEventListener("load", () => init());
document.body.appendChild(datatables);
};
const init = () => {
const markerRemover = document.createElement("style");

View File

@ -13,13 +13,13 @@
<!-- Main body -->
<body>
<div class="main">
<div class="main fit">
<div id="all" class="card">
<div class="heading p-1">
<div class="btn-primary btn p-1" id="showhide"><span class="ui-icon ui-icon-transferthick-e-w"></span></div>
<!-- <div class="btn-primary btn p-1" id="settings"><span class="ui-icon ui-icon-transferthick-e-w"></span></div> -->
</div>
<div class="containing px-4 py-2 w-100">
<div class="containing px-4 py-2" style="width:500px">
<table class="table table-dark table-auto w-100 no-overflow">
<thead><tr><th>#</th><th>User</th><th>Distance</th><th>Score</th></tr></thead>
<tbody id="datatab">

View File

@ -43,26 +43,6 @@ $(function () {
}
const refreshUI = () => {
// if(queryMap.getOrElse('single',false)){
// $('#all').show(); $('#timer').hide(); $('#goal').hide();
// $('#follow').parent().closest('div').hide(); $('#subscribe').parent().closest('div').hide(); $('#donate').parent().closest('div').hide();
// if(queryMap.getOrElse('follow',false)) $('#follow').parent().closest('div').show();
// if(queryMap.getOrElse('subscribe',false)) $('#subscribe').parent().closest('div').show();
// if(queryMap.getOrElse('donate',false)) $('#donate').parent().closest('div').show();
// }else if(queryMap.getOrElse('goal',false)){
// $('#all').hide(); $('#timer').hide(); $('#goal').show();
// $('#cfollow').parent().closest('div').hide(); $('#csubscribe').parent().closest('div').hide();
// if(queryMap.getOrElse('follow',false)) $('#cfollow').parent().closest('div').show();
// if(queryMap.getOrElse('subscribe',false)) $('#csubscribe').parent().closest('div').show();
// }
// $('#follow').text(lastFollow);
// $('#subscribe').text(lastSub);
// $('#donate').text(lastDonator);
// $('#cfollow').parent().closest('div').progressbar({ value : countFollow/parseInt(queryMap.getOrElse('follow',9999))*100 });
// $('#csubscribe').parent().closest('div').progressbar({ value : countSub/parseInt(queryMap.getOrElse('subscribe',9999))*100});
// $('#cfollow').text(`${countFollow} / ${queryMap.getOrElse('follow',9999)}`);
// $('#csubscribe').text(`${countSub} / ${queryMap.getOrElse('subscribe',9999)}`);
}
const handleSocketMessage = (e)=>{
@ -76,15 +56,7 @@ $(function () {
console.log(message.eventType, message.data)
if(message.eventType == 'follow') {
lastFollow = message.data || lastFollow;
countFollow++;
} else if(message.eventType == 'subscribe') {
lastSub = message.data || lastSub;
countSub++;
} else if(message.eventType == 'donation') {
lastDonator = message.data || lastDonator;
} else if(message.eventType == 'timer') {
console.log("New timer !! ", message.data)
}
refreshUI();
} catch (ex) {
@ -101,26 +73,20 @@ $(function () {
while(socket.getReadyState() === 0){
await new Promise(r => setTimeout(r, 500));
}
// socket.getDBValue("get_current_stream_info_lastFollow", 'streamInfo', 'lastFollow', (response)=>{
// if(response.streamInfo) lastFollow = response.streamInfo || lastFollow;
// refreshUI();
// })
// socket.getDBValue("get_current_stream_info_lastSub", 'streamInfo', 'lastSub', (response)=>{
// if(response.streamInfo) lastSub = response.streamInfo || lastSub;
// refreshUI();
// })
// socket.getDBValue("get_current_stream_info_lastDonator", 'streamInfo', 'lastDonator', (response)=>{
// if(response.streamInfo) lastDonator = response.streamInfo || lastDonator;
// refreshUI();
// })
// socket.getDBValue('get_current_stream_info_counts', 'panelData', 'stream', (e)=>{
// let data = JSON.parse(e.panelData);
// countFollow = data.followers || countFollow;
// countSub = 0;
// refreshUI();
// })
}
}catch(e) {console.log(e)}
})
});
});
const calculateScale = (bounds) => haversineDistance({ lat: bounds.min.lat, lng: bounds.min.lng }, { lat: bounds.max.lat, lng: bounds.max.lng }) / 7.458421;
const haversineDistance = (mk1, mk2) => {
const R = 6371.071;
const rlat1 = mk1.lat * (Math.PI / 180);
const rlat2 = mk2.lat * (Math.PI / 180);
const difflat = rlat2 - rlat1;
const difflon = (mk2.lng - mk1.lng) * (Math.PI / 180);
const km = 2 * R * Math.asin(Math.sqrt(Math.sin(difflat / 2) * Math.sin(difflat / 2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon / 2) * Math.sin(difflon / 2)));
return km;
};
const calculateScore = (distance, scale) => Math.round(5000 * Math.pow(0.99866017, (distance * 1000) / scale));

View File

@ -58,7 +58,7 @@ $(function() {
var webSocket = new ReconnectingWebSocket((getProtocol() === 'https://' || window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + '/ws/panel', null, { reconnectInterval: 500 }),
var webSocket = new ReconnectingWebSocket((getProtocol() === 'https://' || window.location.protocol === 'https:' ? 'wss://' : 'ws://') + 'twitchbot.helcel.net' + '/ws/panel', null, { reconnectInterval: 500 }),
callbacks = [],
listeners = [],
familyHandlers = {},