-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybtn.js
74 lines (68 loc) · 2.62 KB
/
playbtn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
console.log("[RoAdditions] Injected play button adder script")
// Define a function to add the button to each game card container
function createButton(parent, label, onClick, classes, style) {
const button = document.createElement("button");
button.innerHTML = label;
button.addEventListener("click", onClick);
if (classes) {
// If classes are specified, add them to the button element
classes.split(" ").forEach(function (className) {
button.classList.add(className);
});
}
if (style) {
for (var prop in style) {
button.style[prop] = style[prop];
}
}
parent.appendChild(button);
}
function dothebuttonthing() {
const parents = document.querySelectorAll(".game-card-container");
parents.forEach(function (parent) {
if (!parent.querySelector(".playBtnRoAdd")) {
if (
parent.parentElement.parentElement.classList.contains(
"games"
) ||
parent.parentElement.classList.contains("game-carousel") ||
parent.parentElement.parentElement.parentElement.classList.contains(
"group-games"
)
) {
createButton(
parent,
"Play",
function () {
const url = parent
.querySelector("a")
.getAttribute("href");
const startIndex = url.indexOf("games/") + 6; // add 5 to skip "game/"
const endIndex = url.indexOf("/", startIndex);
const gameId = url.substring(startIndex, endIndex);
window.Roblox.GameLauncher.joinMultiplayerGame(
gameId
);
console.log(gameId);
},
"btn-growth-sm place-btn playBtnRoAdd",
{
position: "relative",
display: "block",
"margin-left": "auto",
"margin-right": "auto",
}
);
}
}
});
}
function addButtonToContainers() {
// Call the addButtonToContainers function when the window has finished loading
console.log("[RoAdditions] adding buttons");
// Find the parent elements where you want to add the button
// Loop through each parent element and add a button to it
dothebuttonthing();
setInterval(dothebuttonthing, 400);
}
addButtonToContainers();