Add connection to public scoreboard
This commit is contained in:
@@ -62,7 +62,8 @@ function checkNewMessages() {
|
||||
const name = rootNode.firstChild.firstChild.innerHTML;
|
||||
const dTime = displayTime(completionTime);
|
||||
if (startTime > 0) {
|
||||
messages.push({completionTime: completionTime, name: name, text: el.innerHTML, displayTime: dTime});
|
||||
const text = el.innerHTML;
|
||||
messages.push({completionTime: completionTime, name: name, text: text, displayTime: dTime});
|
||||
const messageContent = `(<span style="color: red;">${dTime}</span>) ${el.innerHTML}`;
|
||||
messageContents.set(el, messageContent);
|
||||
|
||||
@@ -73,9 +74,12 @@ function checkNewMessages() {
|
||||
setTimeout(updateMessageContents, 120);
|
||||
setTimeout(updateMessageContents, 150);
|
||||
setTimeout(updateMessageContents, 180);
|
||||
|
||||
// Upload the message to the puzzle scoreboard, if connected.
|
||||
uploadMessage(name, text, completionTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (newElements) {
|
||||
chrome.storage.local.set({ messages: messages });
|
||||
}
|
||||
@@ -87,6 +91,24 @@ function checkNewMessages() {
|
||||
setTimeout(checkNewMessages, 100);
|
||||
}
|
||||
|
||||
async function uploadMessage(author, text, time_seconds) {
|
||||
data = await chrome.storage.local.get(['puzzleScoreboard']);
|
||||
if (data?.puzzleScoreboard) {
|
||||
fetch(data.puzzleScoreboard, {
|
||||
method: "post",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
author,
|
||||
text,
|
||||
time_seconds,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function update() {
|
||||
const data = await chrome.storage.local.get(['startTime', 'endTime']);
|
||||
if (data?.startTime >= 0 && data.startTime != startTime) {
|
||||
|
||||
Reference in New Issue
Block a user