From 57e4130ede4447ac152efb8e49115c2462eb7e95 Mon Sep 17 00:00:00 2001 From: Index Date: Fri, 28 Jun 2024 10:41:09 -0500 Subject: [PATCH] minor: KDR great divide user stats tooltip --- js/background.js | 3 +- the-great-divide.js | 174 +++++++++++++++++++++++--------------------- 2 files changed, 92 insertions(+), 85 deletions(-) diff --git a/js/background.js b/js/background.js index 35f8883..ab8b1a9 100755 --- a/js/background.js +++ b/js/background.js @@ -160,7 +160,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { Kill Death Ratio - ${KDR} + ${KDR}
@@ -204,6 +204,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { document.getElementById('p+greatdivide_stats').innerHTML = "
This user hasn't participated in The Great Divide.
" } } + return true } }); diff --git a/the-great-divide.js b/the-great-divide.js index eec7940..c87f118 100644 --- a/the-great-divide.js +++ b/the-great-divide.js @@ -1,90 +1,96 @@ -chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { - Settings = result.PolyPlus_Settings || {}; +(async () => { + Utilities = await import(chrome.runtime.getURL('resources/utils.js')) + .default - if (Settings.TheGreatDivide.Enabled !== true) { - return - } - - let EventOngoing = true - let HasTeam = true - if (document.querySelector('#user-avatar-card a[href="/event/the-great-divide"]') === null) { HasTeam = false } - if (new Date().getMonth().toString()+new Date().getDate().toString() >= 714) { EventOngoing = false } - - if (Settings.TheGreatDivide.UnbalancedIndicatorOn === true && window.location.pathname.split('/')[1] === 'places' && window.location.pathname.split('/')[2] === '9656') { - UnbalancedServerMarkers() - } - - console.log('ongoing|has team', EventOngoing, HasTeam) - if (Settings.TheGreatDivide.UserStatsOn === true && window.location.pathname.split('/')[1] === 'u') { - if (HasTeam === true) { - UserStatsTab() - } else { - if (EventOngoing === true) { + chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { + Settings = result.PolyPlus_Settings || {}; + + if (Settings.TheGreatDivide.Enabled !== true) { + return + } + + let EventOngoing = true + let HasTeam = true + if (document.querySelector('#user-avatar-card a[href="/event/the-great-divide"]') === null) { HasTeam = false } + if (new Date().getMonth().toString()+new Date().getDate().toString() >= 714) { EventOngoing = false } + + if (Settings.TheGreatDivide.UnbalancedIndicatorOn === true && window.location.pathname.split('/')[1] === 'places' && window.location.pathname.split('/')[2] === '9656') { + UnbalancedServerMarkers() + } + + console.log('ongoing|has team', EventOngoing, HasTeam) + if (Settings.TheGreatDivide.UserStatsOn === true && window.location.pathname.split('/')[1] === 'u') { + if (HasTeam === true) { UserStatsTab() + } else { + if (EventOngoing === true) { + UserStatsTab() + } } } + }) + + async function UnbalancedServerMarkers() { + const Team = (await (await fetch('https://api.polytoria.com/v1/users/' + JSON.parse(window.localStorage.getItem('p+account_info')).ID + '/greatdivide')).json()).team + if (Team !== undefined) { + const Servers = Array.from(document.getElementById('servers-tabpane').children) + + Servers.forEach(server => { + const TeamCounts = { + phantoms: server.getElementsByClassName('border-phantoms').length, + cobras: server.getElementsByClassName('border-cobras').length + } + + let Enemy = "cobras" + if (Team === "cobras") { Enemy = "phantoms" } + + if (new URLSearchParams(window.location.search).has('forceServerUnbalance')) { + TeamCounts[Enemy] = 1000 + } + + if (TeamCounts[Team] < TeamCounts[Enemy]) { + const UnbalancedText = document.createElement('p') + UnbalancedText.classList = 'mb-2' + UnbalancedText.style.fontSize = '0.7rem' + UnbalancedText.style.color = 'orange' + UnbalancedText.innerHTML = `*Potentially Unbalanced ` + + const ServerInfoColumn = server.getElementsByClassName('col-3')[0] + ServerInfoColumn.children[0].style.marginBottom = '0px' + ServerInfoColumn.insertBefore(UnbalancedText, ServerInfoColumn.children[1]) + + Utilities.InjectResource("registerTooltips") + } + }) + } } -}) - -async function UnbalancedServerMarkers() { - const Team = (await (await fetch('https://api.polytoria.com/v1/users/' + JSON.parse(window.localStorage.getItem('p+account_info')).ID + '/greatdivide')).json()).team - if (Team !== undefined) { - const Servers = Array.from(document.getElementById('servers-tabpane').children) - - Servers.forEach(server => { - const TeamCounts = { - phantoms: server.getElementsByClassName('border-phantoms').length, - cobras: server.getElementsByClassName('border-cobras').length - } - - let Enemy = "cobras" - if (Team === "cobras") { Enemy = "phantoms" } - - if (new URLSearchParams(window.location.search).has('forceServerUnbalance')) { - TeamCounts[Enemy] = 1000 - } - - if (TeamCounts[Team] < TeamCounts[Enemy]) { - const UnbalancedText = document.createElement('p') - UnbalancedText.classList = 'mb-2' - UnbalancedText.style.fontSize = '0.7rem' - UnbalancedText.style.color = 'orange' - UnbalancedText.innerHTML = `*Potentially Unbalanced ` - - const ServerInfoColumn = server.getElementsByClassName('col-3')[0] - ServerInfoColumn.children[0].style.marginBottom = '0px' - ServerInfoColumn.insertBefore(UnbalancedText, ServerInfoColumn.children[1]) - - Utilities.InjectResource("registerTooltips") - } - }) - } -} - -async function UserStatsTab() { - const EventSection = document.createElement('div') - EventSection.innerHTML = ` -
-
- Great Divide -
-
-
- + + async function UserStatsTab() { + const EventSection = document.createElement('div') + EventSection.innerHTML = ` +
+
+ Great Divide +
+
+
+ +
-
- ` - document.getElementsByClassName('user-right')[0].appendChild(EventSection) - - const EventCard = document.getElementById('p+greatdivide_card') - EventCard.innerHTML = ` - - loading... - - - ` - chrome.runtime.sendMessage({ - action: "greatdivide_stats", - userID: document.querySelector('.dropdown-item.text-danger[href^="/report"]').getAttribute('href').split('?')[0].split('/')[3] - }); -} \ No newline at end of file + ` + document.getElementsByClassName('user-right')[0].appendChild(EventSection) + + const EventCard = document.getElementById('p+greatdivide_card') + EventCard.innerHTML = ` + + loading... + + + ` + await chrome.runtime.sendMessage({ + action: "greatdivide_stats", + userID: document.querySelector('.dropdown-item.text-danger[href^="/report"]').getAttribute('href').split('?')[0].split('/')[3] + }); + Utilities.InjectResource("registerTooltips") + } +})(); \ No newline at end of file