Add connection to public scoreboard

This commit is contained in:
sto
2025-06-13 19:37:02 +02:00
parent 376dd1c3a9
commit 452a57970f
3 changed files with 98 additions and 5 deletions

View File

@@ -1,7 +1,9 @@
let startTime = 0;
let endTime = 0;
let messagesCount = 0;
let puzzleScoreboard = null;
let showMessages = false;
let showConnect = false;
async function init() {
const data = await chrome.storage.local.get(['startTime', 'endTime']);
@@ -22,6 +24,11 @@ async function init() {
resetButton.onclick = resetData;
const messagesButton = document.getElementById('messages-button');
messagesButton.onclick = switchMessages;
const connectButton = document.getElementById('connect-button');
connectButton.onclick = switchConnectForm;
const connectSubmitButton = document.getElementById('connect-submit-button');
connectSubmitButton.onclick = connectToPuzzleScoreboard;
initConnect();
update();
}
@@ -79,14 +86,59 @@ function switchMessages() {
const messagesButtonEl = document.getElementById('messages-button');
if (showMessages) {
messagesEl.style.display = 'none';
messagesButtonEl.innerHTML = 'show messages';
messagesButtonEl.innerHTML = 'Show messages';
} else {
messagesEl.style.display = 'block';
messagesButtonEl.innerHTML = 'hide messages';
messagesButtonEl.innerHTML = 'Hide messages';
}
showMessages = !showMessages;
}
function switchConnectForm() {
const connectFormEl = document.getElementById('connect-form')
if (showConnect) {
connectFormEl.style.display = 'none';
} else {
connectFormEl.style.display = 'flex';
}
showConnect = !showConnect;
}
async function initConnect() {
const data = await chrome.storage.local.get(['puzzleScoreboard']);
if (data?.puzzleScoreboard) {
puzzleScoreboard = data.puzzleScoreboard;
const connectButtonEl = document.getElementById('connect-button')
connectButtonEl.innerHTML = `Connected: ${puzzleScoreboard.split('/message')?.at(0)}`;
const connectTextEl = document.getElementById('connect-text')
connectTextEl.style.display = 'none';
const connectSubmitButtonEl = document.getElementById('connect-submit-button')
connectSubmitButtonEl.innerHTML = 'disconnect';
}
}
function connectToPuzzleScoreboard() {
const connectButtonEl = document.getElementById('connect-button')
const connectTextEl = document.getElementById('connect-text')
const connectSubmitButtonEl = document.getElementById('connect-submit-button')
if (puzzleScoreboard) {
puzzleScoreboard = null;
chrome.storage.local.remove('puzzleScoreboard');
connectButtonEl.innerHTML = `Connect to a puzzle scoreboard`;
connectTextEl.style.display = 'block';
connectSubmitButtonEl.innerHTML = 'connect';
} else {
puzzleScoreboard = connectTextEl.value;
chrome.storage.local.set({ puzzleScoreboard: puzzleScoreboard });
const connectFormEl = document.getElementById('connect-form')
connectFormEl.style.display = 'none';
showConnect = false;
connectButtonEl.innerHTML = `Connected: ${puzzleScoreboard.split('/message')?.at(0)}`;
connectTextEl.style.display = 'none';
connectSubmitButtonEl.innerHTML = 'disconnect';
}
}
function dis(n) {
if (n < 10) return "0" + n;
return n.toString();