minor: KDR great divide user stats tooltip

This commit is contained in:
Index 2024-06-28 10:41:09 -05:00
parent 0f7aea03b2
commit 57e4130ede
2 changed files with 92 additions and 85 deletions

View file

@ -160,7 +160,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
Kill Death Ratio Kill Death Ratio
</b> </b>
<span class="float-end"> <span class="float-end">
${KDR} ${KDR} <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="KDR is a user's kills divided by the amount of times they have died. If their KDR is above 1, they are making a positive contribution. If their KDR is less than 1, that means they die more than they kill."></i>
</span> </span>
</div> </div>
<div class="mb-1"> <div class="mb-1">
@ -204,6 +204,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
document.getElementById('p+greatdivide_stats').innerHTML = "<div class=\"mb-3\">This user hasn't participated in The Great Divide.</div>" document.getElementById('p+greatdivide_stats').innerHTML = "<div class=\"mb-3\">This user hasn't participated in The Great Divide.</div>"
} }
} }
return true
} }
}); });

View file

@ -1,90 +1,96 @@
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { (async () => {
Settings = result.PolyPlus_Settings || {}; Utilities = await import(chrome.runtime.getURL('resources/utils.js'))
.default
if (Settings.TheGreatDivide.Enabled !== true) { chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
return Settings = result.PolyPlus_Settings || {};
}
if (Settings.TheGreatDivide.Enabled !== true) {
let EventOngoing = true return
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 } let EventOngoing = true
let HasTeam = true
if (Settings.TheGreatDivide.UnbalancedIndicatorOn === true && window.location.pathname.split('/')[1] === 'places' && window.location.pathname.split('/')[2] === '9656') { if (document.querySelector('#user-avatar-card a[href="/event/the-great-divide"]') === null) { HasTeam = false }
UnbalancedServerMarkers() 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') {
console.log('ongoing|has team', EventOngoing, HasTeam) UnbalancedServerMarkers()
if (Settings.TheGreatDivide.UserStatsOn === true && window.location.pathname.split('/')[1] === 'u') { }
if (HasTeam === true) {
UserStatsTab() console.log('ongoing|has team', EventOngoing, HasTeam)
} else { if (Settings.TheGreatDivide.UserStatsOn === true && window.location.pathname.split('/')[1] === 'u') {
if (EventOngoing === true) { if (HasTeam === true) {
UserStatsTab() 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 <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="${TeamCounts.cobras} Cobras and ${TeamCounts.phantoms} Phantoms" data-bs-placement="right"></i>`
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() {
async function UnbalancedServerMarkers() { const EventSection = document.createElement('div')
const Team = (await (await fetch('https://api.polytoria.com/v1/users/' + JSON.parse(window.localStorage.getItem('p+account_info')).ID + '/greatdivide')).json()).team EventSection.innerHTML = `
if (Team !== undefined) { <div class="d-grid mt-2 mb-4"></div>
const Servers = Array.from(document.getElementById('servers-tabpane').children) <h6 class="section-title px-3 px-lg-0">
<i class="fas fa-swords me-1"></i> Great Divide
Servers.forEach(server => { </h6>
const TeamCounts = { <div class="card mcard card-themed mb-4">
phantoms: server.getElementsByClassName('border-phantoms').length, <div class="card-body" id="p+greatdivide_card">
cobras: server.getElementsByClassName('border-cobras').length <button class="btn btn-primary btn-sm w-100">Load Statistics</button>
} </div>
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 <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="${TeamCounts.cobras} Cobras and ${TeamCounts.phantoms} Phantoms" data-bs-placement="right"></i>`
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 = `
<div class="d-grid mt-2 mb-4"></div>
<h6 class="section-title px-3 px-lg-0">
<i class="fas fa-swords me-1"></i> Great Divide
</h6>
<div class="card mcard card-themed mb-4">
<div class="card-body" id="p+greatdivide_card">
<button class="btn btn-primary btn-sm w-100">Load Statistics</button>
</div> </div>
</div> `
` document.getElementsByClassName('user-right')[0].appendChild(EventSection)
document.getElementsByClassName('user-right')[0].appendChild(EventSection)
const EventCard = document.getElementById('p+greatdivide_card')
const EventCard = document.getElementById('p+greatdivide_card') EventCard.innerHTML = `
EventCard.innerHTML = ` <small class="d-block text-center text-muted" style="font-size: 0.8rem;">
<small class="d-block text-center text-muted" style="font-size: 0.8rem;"> loading...
loading... </small>
</small> <lottie-player id="avatar-loading" src="https://c0.ptacdn.com/static/images/lottie/poly-brick-loading.2b51aa85.json" background="transparent" speed="1" style="width: 20%;height: auto;margin: -16px auto 50px;margin-top: 0px;" loop="" autoplay=""></lottie-player>
<lottie-player id="avatar-loading" src="https://c0.ptacdn.com/static/images/lottie/poly-brick-loading.2b51aa85.json" background="transparent" speed="1" style="width: 20%;height: auto;margin: -16px auto 50px;margin-top: 0px;" loop="" autoplay=""></lottie-player> `
` await chrome.runtime.sendMessage({
chrome.runtime.sendMessage({ action: "greatdivide_stats",
action: "greatdivide_stats", userID: document.querySelector('.dropdown-item.text-danger[href^="/report"]').getAttribute('href').split('?')[0].split('/')[3]
userID: document.querySelector('.dropdown-item.text-danger[href^="/report"]').getAttribute('href').split('?')[0].split('/')[3] });
}); Utilities.InjectResource("registerTooltips")
} }
})();