-
-
Save Sitethief/936d3fab6d41eaba3fc043c8b13d2de9 to your computer and use it in GitHub Desktop.
Counts NS badges and display the counts
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 NSCountBadges | |
// @namespace sitethiefs-ns-scripts | |
// @version 0.3 | |
// @description Counts NS badges and display the counts | |
// @author Sitethief of Vylixan | |
// @copyright MIT https://opensource.org/licenses/MIT | |
// @match *.nationstates.net/nation=* | |
// @match *.nationstates.net/*/nation=* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=nationstates.net | |
// @grant none | |
// ==/UserScript== | |
/* | |
* Copyright (c) 2023 Sitethief <sitethief at gmail.com> | |
* This file is licensed under the MIT license. | |
* https://opensource.org/licenses/MIT for more details. | |
*/ | |
(function () { | |
'use strict'; | |
const trophyrack = document.querySelector('.trophyrack'); | |
if (trophyrack) { | |
const images = trophyrack.querySelectorAll('img.trophy'); | |
const trophySections = trophyrack.querySelectorAll('.trophysection'); | |
let count_1 = 0; | |
let count_5 = 0; | |
let count_10 = 0; | |
// Count badges per type | |
for (let i = 0; i < images.length; i++) { | |
const image = images[i]; | |
if (image.src.includes('-1.png') || image.src.includes('-1t.png')) { | |
count_1++; | |
} | |
if (image.src.includes('-5.png')) { | |
count_5++; | |
} | |
if (image.src.includes('-10.png')) { | |
count_10++; | |
} | |
} | |
// Match sections with their counts. | |
trophySections.forEach(section => { | |
if (section.innerHTML.includes('Top<br>1%') && count_1 > 0) { | |
section.innerHTML = ' #' + count_1 + ' ' + section.innerHTML; | |
} else if (section.innerHTML.includes('Top<br>5%') && count_5 > 0) { | |
section.innerHTML = ' #' + count_5 + ' ' + section.innerHTML; | |
} else if (section.innerHTML.includes('Top<br>10%') && count_10 > 0) { | |
section.innerHTML = ' #' + count_10 + ' ' + section.innerHTML; | |
} | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment