Last active
May 14, 2023 22:07
-
-
Save asapcaplord/39ad0eb7d9b80a9f72ca0d51c3b65cd1 to your computer and use it in GitHub Desktop.
Eggball Settings
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
// ==UserScript== | |
// @name Eggball Settings | |
// @version 1.3 | |
// @description Automatically apply eggball settings for pubs or leagues | |
// @match *://*.koalabeast.com/groups/* | |
// @author ASAP | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_deleteValue | |
// @updateURL https://gist.github.com/asapcaplord/39ad0eb7d9b80a9f72ca0d51c3b65cd1/raw/Eggball-Settings.user.js | |
// @downloadURL https://gist.github.com/asapcaplord/39ad0eb7d9b80a9f72ca0d51c3b65cd1/raw/Eggball-Settings.user.js | |
// ==/UserScript== | |
// Log script in console | |
console.log(GM_info.script.name + ' active (Version: ' + GM_info.script.version + ')'); | |
// Start Script (Group functions) | |
(function(window) { | |
'use strict'; | |
// Group Functions, or the functions which run when user is on the group page | |
if (window.location.href.split(".com")[1].match(/^\/groups\/[a-z]{8}$/) && Array.apply(null, document.getElementsByClassName("js-leader")).length > 0) { | |
leaderReady(); // runs function to set up leader stuff | |
groupReady(true); // runs function to grab group info | |
} | |
else if (window.location.pathname.match(/^\/groups\/[a-z]{8}$/) && Array.apply(null, document.getElementsByClassName("js-leader")).length === 0) { // non-leader in group | |
GM_setValue("groupId", window.location.href.split("/")[4]); // the leader function already sets groupId, so there's no need to set it again | |
console.log("Spectator/Player detected, skipping group setup"); | |
groupReady(false); // runs function to grab group info | |
var redundantCount = 0; | |
var redundantLeadCheck = setInterval(function () { // Recheck for leader every half second for ten seconds in case leader functions didn't load | |
if (Array.apply(null, document.getElementsByClassName("js-leader")).length > 0) { | |
if (!document.getElementById("EggballButton")) { // if leader stuff wasn't activated by something else, start leader functions | |
changeLeader(true); | |
} | |
window.clearInterval(redundantLeadCheck); // clear interval since you're done checking | |
} | |
else if (redundantCount > 20) { // clear interval after ten seconds | |
window.clearInterval(redundantLeadCheck); | |
} | |
else { // increment up if it hasn't been ten seconds yet | |
redundantCount++; | |
} | |
}, 500); | |
} | |
})(unsafeWindow); | |
// Misc Functions, alphabetical order by name of function | |
function changeLeader(status) { | |
if (status) { // status returns whether or not the user is the leader of the group | |
if (!!document.getElementById("EggballButton")) { // unhide leader elements if the user already had them loaded | |
document.getElementById("EggballButton").style.display = "inline"; | |
} | |
else { // if the leader elements are not loaded, run the leaderReady function | |
leaderReady(); | |
} | |
} | |
else { // changeLeader(false) only happens when the leader elements already exist, so hide leader elements | |
if (!!document.getElementById("EggballButton")) { | |
document.getElementById("EggballButton").style.display = "none"; | |
} | |
} | |
} | |
function groupReady(isLeader) { // grab necessary info from the group | |
tagpro.ready(function() { | |
var group = tagpro.group = Object.assign(tagpro.group, { | |
self: GM_getValue("tpUserId", undefined), | |
players: {} | |
}); | |
var socket = group.socket; | |
socket.on("member", function(member) { | |
group.players[member.id] = Object.assign(group.players[member.id] || {}, member); | |
if (typeof tagpro.group.players[GM_getValue("tpUserId", undefined)] != "undefined") { | |
if (tagpro.group.players[GM_getValue("tpUserId")].leader != isLeader) { | |
isLeader = tagpro.group.players[GM_getValue("tpUserId")].leader; | |
changeLeader(isLeader); | |
} | |
} | |
}); | |
}); | |
} | |
function leaderReady() { | |
console.log("Group leader detected, setting up group"); | |
setTimeout(function(){ | |
document.getElementById("pug-btn").onclick = function() { // If group is private, turn the group into a comp game | |
if (!!document.getElementById("EggballButton")) { // unhide leader elements if the user already had them loaded | |
document.getElementById("EggballButton").style.display = "inline"; | |
i.style.display = 'block'; | |
} | |
checkhidden(); | |
} | |
},100); | |
GM_setValue("groupId", window.location.href.split("/")[4]); | |
var buttonSettings = document.getElementsByClassName("col-sm-12 js-leader-only customize-settings")[0]; | |
var EggballClick = document.createElement("button"); | |
EggballClick.id = "EggballButton"; | |
EggballClick.textContent="Enable Eggball Settings"; | |
buttonSettings.append(EggballClick); | |
EggballClick.className = "btn btn-default group-assignment group-setting"; | |
EggballClick.style="float: right; margin-bottom: 14px;"; | |
EggballClick.onclick=function(){ | |
if (EggballClick.textContent=="Enable Eggball Settings") | |
{ | |
console.log("setting Eggball values"); | |
console.log("setting default values"); | |
tagpro.group.socket.emit("setting", { name: "mode", value: "eggball"}); | |
tagpro.group.socket.emit("setting", { name: "server", value: "26611098815d"}); | |
tagpro.group.socket.emit("setting", { name: "overtime", value: "false"}); | |
tagpro.group.socket.emit("setting", { name: "overtimeRespawnIncrement", value: "0"}); | |
tagpro.group.socket.emit("setting", { name: "overtimeJukeJuice", value: "false"}); | |
tagpro.group.socket.emit("setting", { name: "time", value: "8"}); | |
tagpro.group.socket.emit("setting", { name: "mercyRule", value: "0"}); | |
tagpro.group.socket.emit("setting", { name: "respawnWarnings", value: "false"}); | |
tagpro.group.socket.emit("setting", { name: "eggballLosingTeamStarts", value: "false"}); | |
//"26611098815d" = Chicago, IL | |
//"fd140ca477c9" = Sydney, AU | |
//"af82be9af5aa" = Miami, FL | |
//"ab0118cf5df3" = Seattle, WA | |
//"bd408b384a78" = Paris, FR | |
//"c0ba0ac39a00" = Frankfurt, DE | |
//"41adffac6f58" = San Francisco, CA | |
//"fcdba9650e5e" = Toronto, CAN | |
//"bdbdad7602c4" = Dallas-2, TX | |
//"aef366ca693c" = Los Angeles, CA | |
//"040f9334d182" = Dallas, TX | |
//"01b011ac8116" = Atlanta, GA | |
//"f395d5bf706f" = Amsterdam, NL | |
//"abb1f9f7c95a" = London, UK | |
if (!!document.getElementsByClassName("col-sm-12 region-settings")[0]){ | |
if (document.getElementsByClassName("col-sm-12 region-settings")[0].style.display!="none"){ | |
document.getElementsByClassName("btn btn-primary btn-tiny pull-right js-toggle-server-select js-leader-only")[0].click(); | |
} | |
} | |
} | |
EggballClick.blur(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment