Skip to content

Instantly share code, notes, and snippets.

@Karmalakas
Last active February 11, 2025 18:11
Show Gist options
  • Save Karmalakas/45c11a30a38c0a32e1e299e8c2e041de to your computer and use it in GitHub Desktop.
Save Karmalakas/45c11a30a38c0a32e1e299e8c2e041de to your computer and use it in GitHub Desktop.
GuruShots team points
// ==UserScript==
// @name GuruShots team points
// @description Show team points based on current vote count in a team battle
// @namespace http://karmalakas.lt/
// @version 1.0.2
// @author Karmalakas
// @updateURL https://github.com/Karmalakas/gurushots-user-scripts/raw/refs/heads/main/script/team-points/script.user.js
// @downloadURL https://github.com/Karmalakas/gurushots-user-scripts/raw/refs/heads/main/script/team-points/script.user.js
// @supportURL https://github.com/Karmalakas/gurushots-user-scripts/issues
// @match https://gurushots.com/teams/match
// @run-at document-idle
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
GM_addStyle('' +
'.match-active-header__item-content__badge-wrapper__total-votes {' +
' padding: 0 8px;' +
' width: auto;' +
' left: 50%;' +
' transform: translate(-50%);' +
'}' +
'.match-active-header__item-content__badge-wrapper__total-votes div.GS__team_result {' +
' margin-left: 8px;' +
' font-weight: 600;' +
' font-size: 12px;' +
'}' +
'.match-state-CLOSED.match-myteam-won .match-active-header__my-team .match-active-header__item-content__badge-wrapper__total-votes,' +
'.match-state-CLOSED.match-opponent-won .match-active-header__opponent .match-active-header__item-content__badge-wrapper__total-votes {' +
' background-color: #e9b009;' +
'}'
);
const mutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
const observerOptions = {'childList': true, 'subtree': true};
const observeTarget = document.querySelector('body');
function process(matchHeader) {
var voteHolders = matchHeader.querySelectorAll('.match-active-header__item-content__badge-wrapper__total-votes');
if (voteHolders.length !== 2) {
return;
}
let data = [];
for (var i = 0; i < voteHolders.length; i++) {
data.push(
{
holder: voteHolders[i],
votes: parseInt(voteHolders[i].querySelector(':scope > div:first-child').innerText)
}
);
}
processData(data);
}
function processData(data) {
data.sort((a, b) => Math.sign(b.votes - a.votes));
addResult(data[0].holder, calcWinner(data[0].votes, data[1].votes));
addResult(data[1].holder, calcLoser(data[0].votes, data[1].votes));
}
function calcWinner(winnerVotes, loserVotes)
{
return Math.round(winnerVotes * 1000 / loserVotes);
}
function calcLoser(winnerVotes, loserVotes)
{
return Math.round(loserVotes * 500 / winnerVotes);
}
function addResult(holder, result)
{
const el = document.createElement('div');
el.className = 'GS__team_result';
el.innerText = result;
holder.appendChild(el);
}
mutationObserver && new MutationObserver(function(mut, observer) {
for (const mutation of mut) {
if (Array.from(mutation.target.classList).includes('match-active-header')) {
observer.disconnect();
process(mutation.target);
observer.observe(observeTarget, observerOptions);
return;
}
}
}).observe(observeTarget, observerOptions);
})();
@Karmalakas
Copy link
Author

Karmalakas commented Jul 21, 2024

Caution

This gist was moved to a separate repo and will no longer be updated
Please visit the new update URL to re-install to the latest version or wait for updates to appear on TamperMonkey


This script shows how many points each team gets in the battle, based on current vote count.

See images bellow.


This only works with TamperMonkey (or similar) extension. Supported browsers are Chrome, Firefox, Edge (maybe others too).

TamperMonkey for:

Once you have TamperMonkey installed, just go to the @downloadURL you see in a script.
If later TM fails to update script, just go to @updateURL you see in a script. This should trigger the update in a new window with TM open.

Any questions or suggestions are welcome.


If you like this script, please consider keeping me scripting Keep me scripting 😄

@Karmalakas
Copy link
Author

Mid battle:
image

Battle over:
image

@Karmalakas
Copy link
Author

Caution

This gist was moved to a separate repo and will no longer be updated
Please visit the new update URL to re-install to the latest version or wait for updates to appear on TamperMonkey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment