forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PreMiD#3069 from Snazzah/update/bonk-io/1
Rename and rewrite Bonk.io (formerly Bonk2.io)
- Loading branch information
Showing
6 changed files
with
162 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const iframe = new iFrame(), | ||
menuIDs = [ | ||
// Login/Guest | ||
"guestOrAccountContainer", | ||
"guestContainer", | ||
"accountContainer", | ||
"autoLoginContainer", | ||
|
||
// Lobby | ||
"newbonklobby", | ||
"mapeditorcontainer", | ||
|
||
// MainMenu | ||
"classic_mid", | ||
"friendsContainer", | ||
"skinmanager", | ||
"skineditorcontainer", | ||
"quickPlayWindow", | ||
"roomListContainer", | ||
|
||
// Game Canvas | ||
"sm_connectingContainer", | ||
"gamerenderer" | ||
], | ||
selector = menuIDs | ||
.map( | ||
(id) => | ||
"#" + | ||
id + | ||
'[style*="visibility: inherit"]' + | ||
"," + | ||
("#" + id + '[style*="display: block"]') | ||
) | ||
.join(","); | ||
|
||
let lastGameMode: string = null; | ||
|
||
// Add event listeners to buttons to set game mode | ||
document | ||
.querySelector("#quickPlayWindow_ClassicButton") | ||
.addEventListener("click", () => lastGameMode = "Classic"); | ||
document | ||
.querySelector("#quickPlayWindow_ArrowsButton") | ||
.addEventListener("click", () => lastGameMode = "Arrows"); | ||
document | ||
.querySelector("#quickPlayWindow_GrappleButton") | ||
.addEventListener("click", () => lastGameMode = "Grapple"); | ||
|
||
document.querySelector("#roomlistjoinbutton").addEventListener("click", () => { | ||
const selectedMode = document.querySelector("tr.SELECTED > td:nth-child(3)"); | ||
if (selectedMode) lastGameMode = selectedMode.textContent; | ||
}); | ||
|
||
iframe.on("UpdateData", async () => { | ||
const element = document.querySelector(selector), | ||
lobbyGameMode = document.querySelector("#newbonklobby_modetext")?.textContent, | ||
state = document.querySelector("#pretty_top_name").textContent + | ||
" - " + | ||
document.querySelector("#pretty_top_level").textContent, | ||
playerCount = document.querySelectorAll(".newbonklobby_playerentry") | ||
.length; | ||
|
||
if (element?.id === "newbonklobby") | ||
lastGameMode = lobbyGameMode; | ||
|
||
iframe.send({ lastGameMode, id: element?.id, state, playerCount }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const presence = new Presence({ | ||
clientId: "778092541836656712" | ||
}), | ||
modePair: { [key: string]: string } = { | ||
Arrows: "arrows2", | ||
"Death Arrows": "arrows2", | ||
Grapple: "grapple2" | ||
}; | ||
|
||
interface IFrameData { | ||
lastGameMode?: string, | ||
id?: string; | ||
state: string; | ||
playerCount: number; | ||
} | ||
|
||
let gameStartTimestamp: number = null, | ||
ifd: IFrameData = null; | ||
|
||
presence.on("UpdateData", async () => { | ||
const data: PresenceData = { | ||
largeImageKey: "bonk" | ||
}; | ||
|
||
if (ifd?.id) { | ||
data.state = ifd.state; | ||
switch (ifd.id) { | ||
case "guestOrAccountContainer": | ||
case "guestContainer": | ||
case "accountContainer": | ||
case "autoLoginContainer": | ||
data.details = "Logging In"; | ||
delete data.state; | ||
break; | ||
case "classic_mid": | ||
data.details = "Main Menu"; | ||
break; | ||
case "friendsContainer": | ||
data.details = "Friends List"; | ||
break; | ||
case "skinmanager": | ||
data.details = "Skin Manager"; | ||
break; | ||
case "skineditorcontainer": | ||
data.details = "Editing a skin"; | ||
break; | ||
case "quickPlayWindow": | ||
data.details = "Quick Play Menu"; | ||
break; | ||
case "roomListContainer": | ||
data.details = "Viewing Room List"; | ||
break; | ||
case "newbonklobby": | ||
data.details = `In a lobby - ${ifd.lastGameMode} (${ifd.playerCount} player${ | ||
ifd.playerCount === 1 ? "" : "s" | ||
})`; | ||
data.smallImageKey = modePair[ifd.lastGameMode] || "classic2"; | ||
data.smallImageText = ifd.lastGameMode; | ||
break; | ||
case "mapeditorcontainer": | ||
data.details = "Editing a map"; | ||
break; | ||
case "sm_connectingContainer": | ||
data.details = "Connecting to a game..."; | ||
break; | ||
case "gamerenderer": | ||
data.details = "In Game"; | ||
if (ifd.lastGameMode) { | ||
data.details += ` - ${ifd.lastGameMode}`; | ||
data.smallImageKey = modePair[ifd.lastGameMode] || "classic2"; | ||
data.smallImageText = ifd.lastGameMode; | ||
} | ||
break; | ||
} | ||
|
||
if (ifd.id === "gamerenderer" && !gameStartTimestamp) | ||
gameStartTimestamp = Date.now(); | ||
else if (ifd.id !== "gamerenderer") gameStartTimestamp = null; | ||
|
||
if (gameStartTimestamp) data.startTimestamp = gameStartTimestamp; | ||
} | ||
|
||
if (!(await presence.getSetting("showName"))) delete data.state; | ||
|
||
// If data doesn't exist clear else set activity to the presence data | ||
if (!data.details) { | ||
presence.setTrayTitle(); // Clear tray | ||
presence.setActivity(); // Clear activity | ||
} else presence.setActivity(data); | ||
}); | ||
|
||
presence.on("iFrameData", (data: IFrameData) => (ifd = data)); |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.