Created
July 21, 2024 10:20
-
-
Save Karmalakas/45c11a30a38c0a32e1e299e8c2e041de to your computer and use it in GitHub Desktop.
GuruShots team points
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 GuruShots team points | |
// @description Show team points based on current vote count in a team battle | |
// @namespace http://karmalakas.lt/ | |
// @version 1.0.0 | |
// @author Karmalakas | |
// @updateURL https://gist.github.com/Karmalakas/45c11a30a38c0a32e1e299e8c2e041de/raw/GS_Team_Points.user.js | |
// @downloadURL https://gist.github.com/Karmalakas/45c11a30a38c0a32e1e299e8c2e041de/raw/GS_Team_Points.user.js | |
// @supportURL https://gist.github.com/Karmalakas/45c11a30a38c0a32e1e299e8c2e041de | |
// @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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 😄