`;
scriptForMap.textContent = `
{
let countries = ['AF','AX','AL','DZ','AS','AD','AO','AI','AQ','AG','AR','AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY','BE','BZ','BJ','BM','BT','BO','BQ','BA','BW','BV','BR','IO','BN','BG','BF','BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','CX','CC','CO','KM','CG','CD','CK','CR','CI','HR','CU','CW','CY','CZ','DK','DJ','DM','DO','EC','EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','GF','PF','TF','GA','GM','GE','DE','GH','GI','GR','GL','GD','GP','GU','GT','GG','GN','GW','GY','HT','HM','VA','HN','HK','HU','IS','IN','ID','IR','IQ','IE','IM','IL','IT','JM','JP','JE','JO','KZ','KE','KI','KP','KR','XK','KW','KG','LA','LV','LB','LS','LR','LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH','MQ','MR','MU','YT','MX','FM','MD','MC','MN','ME','MS','MA','MZ','MM','NA','NR','NP','NL','NC','NZ','NI','NE','NG','NU','NF','MP','NO','OM','PK','PW','PS','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','RS','RE','RO','RU','RW','BL','SH','KN','LC','MF','VC','WS','ST','SA','SN','SC','SL','SG','SX','SK','SI','SB','SO','ZA','GS','SS','ES','LK','SD','SR','SJ','SZ','SE','CH','SY','TW','TJ','TZ','TH','TL','TG','TK','TO','TT','TN','TR','TM','TC','TV','UG','UA','AE','GB','US','UM','UY','UZ','VU','VE','VN','VG','VI','WF','EH','YE','ZM','ZW','SM'];
//UNIT SELECTION
if(window.localStorage.getItem('units-svg-map') === 'mi'){
document.getElementById('unit-selector-mi').checked = true;
}
else if(window.localStorage.getItem('units-svg-map') === 'km'){
document.getElementById('unit-selector-km').checked = true;
}
document.getElementById('unit-selector-mi').addEventListener('click', function(){
window.localStorage.setItem('units-svg-map', 'mi');
});
document.getElementById('unit-selector-km').addEventListener('click', function(){
window.localStorage.setItem('units-svg-map', 'km');
});
//DUELS MAP SETUP
function setAllDuelsStats(){
//Percentage Bar
let correct_total = parseInt(window.localStorage.getItem('overall-correct-${USER_ID}'));
let total_total = parseInt(window.localStorage.getItem('overall-total-${USER_ID}'));
let percentage_total = Math.floor((correct_total / total_total) * 100);
document.getElementById('total-percentage-bar').style.width = percentage_total + '%';
document.getElementById('total-percentage-text').innerHTML = 'Overall Score: ' + correct_total + ' / ' + total_total + ' (' + percentage_total +'%) ';
if(percentage_total >= 100*${green_range}){
document.getElementById('total-percentage-bar').style.backgroundColor = 'green';
}
else if(percentage_total >= 100*${yellow_range}){
document.getElementById('total-percentage-bar').style.backgroundColor = 'yellow';
}
else if(percentage_total >= 100*${red_range}){
document.getElementById('total-percentage-bar').style.backgroundColor = 'red';
}
//Country colors
countries.forEach(function(country){
let correct = 0;
let total = 0;
if(window.localStorage.getItem(country + '-number-correct-${USER_ID}') !== null){
correct = window.localStorage.getItem(country + '-number-correct-${USER_ID}');
}
if(window.localStorage.getItem(country + '-number-total-${USER_ID}') !== null){
total = window.localStorage.getItem(country + '-number-total-${USER_ID}');
}
let percentage = parseInt(correct) / parseInt(total);
if(correct === 0 && total === 0){
percentage = 'none';
}
let targetCountry = document.getElementById(country);
if(!targetCountry){
return;
}
//Setting the countries to a color based on their percentage
if(percentage >= ${green_range}){
targetCountry.setAttribute('style', 'fill: lightgreen'); //green
}
else if(percentage >= ${yellow_range}){
targetCountry.setAttribute('style', 'fill: rgb(233, 233, 84)'); //yellow
}
else if(percentage >= ${red_range}){
targetCountry.setAttribute('style', 'fill: lightcoral'); //red
}
else{
targetCountry.setAttribute('style', 'fill: black');
}
});
//OVERALL STATS SETUP
let overallStats = JSON.parse(window.localStorage.getItem('overall-country-stats-${USER_ID}'));
let percentage;
let percentageColor;
let totalCount = overallStats.totalCount;
let totalWin = overallStats.totalWin;
let totalLoss = overallStats.totalLoss;
let total5ks = overallStats.total5ks;
let totalGames = overallStats.totalGames;
let averageScore = Math.floor(overallStats.averageScore);
let averageDistance = Math.floor(overallStats.averageDistance/1000);
let gameLengthWin = overallStats.averageGameLengthWin;
let gameLengthLoss = overallStats.averageGameLengthLoss;
let averageTime = Math.floor(overallStats.averageTime);
let guessedFirst = overallStats.guessedFirst;
let closerThanOpponent = overallStats.closerThanOpponent;
let correctStreak = overallStats.countryCorrectStreak;
let correctMax = overallStats.countryCorrectMax;
let wrongStreak = overallStats.countryWrongStreak;
let wrongMax = overallStats.countryWrongMax;
let opponentRating = Math.floor(overallStats.opponentRating);
//Find correct percentage to color the outside circle
function findPercentage(stat, max){
percentage = (stat/max);
if(percentage >= ${green_range}){
percentageColor = 'green';
}
else if(percentage >= ${yellow_range}){
percentageColor = 'yellow';
}
else{
percentageColor = 'red';
}
percentage = 100 * percentage;
if(percentage <= 0){
percentage = 2;
}
};
//Average Score
findPercentage(averageScore, 5000);
document.getElementById('overall-stat-average-score-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-average-score-value').innerText = averageScore;
//Average Distance
findPercentage(2500-averageDistance, 2500);
document.getElementById('overall-stat-average-distance-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
if(window.localStorage.getItem('units-svg-map') == 'mi'){
document.getElementById('overall-stat-average-distance-title').innerText = 'Average Distance (mi)';
averageDistance = Math.floor(averageDistance / 1.609);
}
else{
document.getElementById('overall-stat-average-distance-title').innerText = 'Average Distance (km)';
}
document.getElementById('overall-stat-average-distance-value').innerText = averageDistance;
//Closer Than Opponent
findPercentage(closerThanOpponent, totalCount);
document.getElementById('overall-stat-closer-than-opponent-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-closer-than-opponent-value').innerText = Math.floor((100 * (closerThanOpponent/totalCount))) + '%';
//Average Time
findPercentage(120-averageTime, 120);
document.getElementById('overall-stat-average-time-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-average-time-value').innerText = averageTime;
//Guessed First
findPercentage(guessedFirst, totalCount);
document.getElementById('overall-stat-guessed-first-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-guessed-first-value').innerText = Math.floor((100 * (guessedFirst/totalCount))) + '%';
//Total 5ks
findPercentage(total5ks, 100);
document.getElementById('overall-stat-total-5ks-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-total-5ks-value').innerText = total5ks;
//Game Length (Win)
findPercentage(15-gameLengthWin, 15);
document.getElementById('overall-stat-average-game-length-win-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-average-game-length-win-value').innerText = Math.round(10 * gameLengthWin) / 10;
//Game Length (Loss)
findPercentage(gameLengthLoss, 15);
document.getElementById('overall-stat-average-game-length-loss-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-average-game-length-loss-value').innerText = Math.round(10 * gameLengthLoss) / 10;
//Opponent Rating
findPercentage(opponentRating, 1200);
document.getElementById('overall-stat-opponent-rating-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('overall-stat-opponent-rating-value').innerText = opponentRating;
//BOTTOM STATS SETUP
//Distance From Opponent
let distanceFromOpponent = [Math.round(overallStats.distanceFromOpponent[1] / 1000),'km','+','green'];
if(window.localStorage.getItem('units-svg-map') == 'mi'){
distanceFromOpponent[0] = Math.round(distanceFromOpponent[0] / 1.609);
distanceFromOpponent[1] = 'mi';
}
if(distanceFromOpponent[0] < 0){
distanceFromOpponent[0] *= -1;
distanceFromOpponent[2] = '-';
distanceFromOpponent[3] = 'red';
}
document.getElementById('overall-stats-distance-from-opponent-title').innerText = 'AVERAGE DISTANCE FROM OPPONENT';
document.getElementById('overall-stats-distance-from-opponent-value').style.color = distanceFromOpponent[3];
document.getElementById('overall-stats-distance-from-opponent-value').innerText = distanceFromOpponent[2] + distanceFromOpponent[0] + ' ' + distanceFromOpponent[1];
//Country Streaks
if(overallStats.countryCorrectStreak > 0){
document.getElementById('overall-stats-country-streaks-value-current-value').innerText = overallStats.countryCorrectStreak + ' Correct';
document.getElementById('overall-stats-country-streaks-value-current-value').style.color = 'green';
}
else if(overallStats.countryWrongStreak > 0){
document.getElementById('overall-stats-country-streaks-value-current-value').innerText = overallStats.countryWrongStreak + ' Incorrect';
document.getElementById('overall-stats-country-streaks-value-current-value').style.color = 'red';
}
document.getElementById('overall-stats-country-streaks-value-max-correct-value').innerText = overallStats.countryCorrectMax;
document.getElementById('overall-stats-country-streaks-value-max-wrong-value').innerText = overallStats.countryWrongMax;
//Time Played
let minutesPlayed = Math.floor(Math.floor(overallStats.totalSeconds / 60) % 60);
let hoursPlayed = Math.floor(overallStats.totalSeconds / 3600);
document.getElementById('overall-stats-total-play-time-value').innerText = hoursPlayed + 'h ' + minutesPlayed + 'm ';
//Make All Stats Visible
document.getElementById('overall-stat-average-score-wrapper').style.display = 'flex';
document.getElementById('overall-stat-average-distance-wrapper').style.display = 'flex';
document.getElementById('overall-stat-closer-than-opponent-wrapper').style.display = 'flex';
document.getElementById('overall-stat-average-time-wrapper').style.display = 'flex';
document.getElementById('overall-stat-guessed-first-wrapper').style.display = 'flex';
document.getElementById('overall-stat-total-5ks-wrapper').style.display = 'flex';
document.getElementById('overall-stat-average-game-length-win-wrapper').style.display = 'flex';
document.getElementById('overall-stat-average-game-length-loss-wrapper').style.display = 'flex';
document.getElementById('overall-stat-opponent-rating-wrapper').style.display = 'flex';
document.getElementById('duels-stats-spacing-wrapper-1').style.display = 'flex'
document.getElementById('duels-stats-spacing-wrapper-2').style.display = 'flex'
document.getElementById('overall-stats-values-bottom').style.marginTop = '360px';
};
//Set All Classic Stats
function setAllClassicStats(){
//Total Percentage Bar
let totalCount = 'none';
let totalCorrect = 'none'
let percentage_total = 'none';
if(window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}')){
totalCount = JSON.parse(window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}')).totalCount;
totalCorrect = JSON.parse(window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}')).totalCorrect;
percentage_total = Math.floor((totalCorrect / totalCount) * 100);
}
if(percentage_total >= 100*${green_range}){
document.getElementById('total-percentage-bar').style.backgroundColor = 'green';
}
else if(percentage_total >= 100*${yellow_range}){
document.getElementById('total-percentage-bar').style.backgroundColor = 'yellow';
}
else if(percentage_total >= 100*${red_range}){
document.getElementById('total-percentage-bar').style.backgroundColor = 'red';
}
if(percentage_total != 'none'){
document.getElementById('total-percentage-bar').style.width = percentage_total + '%';
document.getElementById('total-percentage-text').innerHTML = 'Overall Score: ' + totalCorrect + ' / ' + totalCount + ' (' + percentage_total +'%) ';
}
//Country colors
countries.forEach(function(countryId){
let countryStats = null;
let percentage = 'none';
if(window.localStorage.getItem('geostats-' + countryId + '-all-standard-stats-${USER_ID}')){
countryStats = JSON.parse(window.localStorage.getItem('geostats-' + countryId + '-all-standard-stats-${USER_ID}'));
percentage = countryStats.totalCorrect / countryStats.totalCount;
}
let targetCountry = document.getElementById(countryId);
if(!targetCountry){
return;
}
//Setting the countries to a color based on their percentage
if(percentage >= ${green_range}){
targetCountry.setAttribute('style', 'fill: lightgreen'); //green
}
else if(percentage >= ${yellow_range}){
targetCountry.setAttribute('style', 'fill: rgb(233, 233, 84)'); //yellow
}
else if(percentage >= ${red_range}){
targetCountry.setAttribute('style', 'fill: lightcoral'); //red
}
else{
targetCountry.setAttribute('style', 'fill: black');
}
});
//Find correct percentage to color the outside circle
function findPercentage(stat, max){
percentage = (stat/max);
if(percentage >= ${green_range}){
percentageColor = 'green';
}
else if(percentage >= ${yellow_range}){
percentageColor = 'yellow';
}
else{
percentageColor = 'red';
}
percentage = 100 * percentage;
if(percentage <= 0){
percentage = 2;
}
};
//OVERALL STATS
let overallStats = JSON.parse(window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}'));
let percentage;
let percentageColor;
let averageScore = Math.floor(overallStats.averageScore);
let averageDistance = Math.floor(overallStats.averageDistance/1000);
let averageRoundTime = Math.floor(overallStats.averageRoundTime);
let averageGameTime = overallStats.averageGameTime/60;
let total5ks = overallStats.total5ks;
//Average Score
findPercentage(averageScore, 5000);
document.getElementById('standard-overall-stat-average-score-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-overall-stat-average-score-value').innerText = averageScore;
//Average Distance
findPercentage(2500-averageDistance, 2500);
document.getElementById('standard-overall-stat-average-distance-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
if(window.localStorage.getItem('units-svg-map') == 'mi'){
document.getElementById('standard-overall-stat-average-distance-title').innerText = 'Average Distance (mi)';
averageDistance = Math.floor(averageDistance / 1.609);
}
else{
document.getElementById('standard-overall-stat-average-distance-title').innerText = 'Average Distance (km)';
}
document.getElementById('standard-overall-stat-average-distance-value').innerText = averageDistance;
//Average Round Time
findPercentage(120-averageRoundTime, 120);
document.getElementById('standard-overall-stat-average-round-time-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-overall-stat-average-round-time-value').innerText = averageRoundTime;
//Average Game Time
findPercentage(10-averageGameTime, 10);
document.getElementById('standard-overall-stat-average-game-time-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-overall-stat-average-game-time-value').innerText = round(averageGameTime,1);
//Total 5ks
findPercentage(total5ks, 100);
document.getElementById('standard-overall-stat-total5ks-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-overall-stat-total5ks-value').innerText = total5ks;
//BOTTOM STATS SETUP
//Commonly Guessed Incorrectly
document.getElementById('overall-stats-distance-from-opponent-title').innerText = 'TOP INCORRECT COUNTRIES';
let textColor = 'green';
let innerText = '';
if(Object.keys(overallStats.incorrectCountry).length != 0){
let incorrectGuesses = Object.entries(overallStats.incorrectCountry).sort((a,b) => b[1]-a[1]);
for(let i = 0; i < 3; i++){
let tempText = '';
if(i < incorrectGuesses.length){
tempText = document.getElementById(incorrectGuesses[i][0]).dataset.name + ' - ' + incorrectGuesses[i][1];
}
innerText += tempText + '\\n';
}
textColor = 'red';
}
else{
innerText = 'N/A';
}
document.getElementById('overall-stats-distance-from-opponent-value').style.color = textColor;
document.getElementById('overall-stats-distance-from-opponent-value').innerText = innerText;
//Country Streaks
if(overallStats.countryCorrectStreak > 0){
document.getElementById('overall-stats-country-streaks-value-current-value').innerText = overallStats.countryCorrectStreak + ' Correct';
document.getElementById('overall-stats-country-streaks-value-current-value').style.color = 'green';
}
else if(overallStats.countryWrongStreak > 0){
document.getElementById('overall-stats-country-streaks-value-current-value').innerText = overallStats.countryWrongStreak + ' Incorrect';
document.getElementById('overall-stats-country-streaks-value-current-value').style.color = 'red';
}
document.getElementById('overall-stats-country-streaks-value-max-correct-value').innerText = overallStats.countryCorrectMax;
document.getElementById('overall-stats-country-streaks-value-max-wrong-value').innerText = overallStats.countryWrongMax;
//Time Played
let minutesPlayed = Math.floor(Math.floor(overallStats.totalSeconds / 60) % 60);
let hoursPlayed = Math.floor(overallStats.totalSeconds / 3600);
document.getElementById('overall-stats-total-play-time-value').innerText = hoursPlayed + 'h ' + minutesPlayed + 'm ';
//Make All Stats Visible
document.getElementById('standard-overall-stat-average-score-wrapper').style.display = 'flex';
document.getElementById('standard-overall-stat-average-distance-wrapper').style.display = 'flex';
document.getElementById('standard-overall-stat-average-round-time-wrapper').style.display = 'flex';
document.getElementById('standard-overall-stat-average-game-time-wrapper').style.display = 'flex';
document.getElementById('standard-overall-stat-total5ks-wrapper').style.display = 'flex';
document.getElementById('standard-stats-spacing-wrapper-1').style.display = 'flex'
document.getElementById('overall-stats-values-bottom').style.marginTop = '160px';
};
//Clear All Overall Stats On Gamemode Change
function clearAllOverallStats(){
//Duels
document.getElementById('overall-stat-average-score-wrapper').style.display = 'none';
document.getElementById('overall-stat-average-distance-wrapper').style.display = 'none';
document.getElementById('overall-stat-closer-than-opponent-wrapper').style.display = 'none';
document.getElementById('overall-stat-average-time-wrapper').style.display = 'none';
document.getElementById('overall-stat-guessed-first-wrapper').style.display = 'none';
document.getElementById('overall-stat-total-5ks-wrapper').style.display = 'none';
document.getElementById('overall-stat-average-game-length-win-wrapper').style.display = 'none';
document.getElementById('overall-stat-average-game-length-loss-wrapper').style.display = 'none';
document.getElementById('overall-stat-opponent-rating-wrapper').style.display = 'none';
document.getElementById('duels-stats-spacing-wrapper-1').style.display = 'none';
document.getElementById('duels-stats-spacing-wrapper-2').style.display = 'none';
//Standard
document.getElementById('standard-overall-stat-average-score-wrapper').style.display = 'none';
document.getElementById('standard-overall-stat-average-distance-wrapper').style.display = 'none';
document.getElementById('standard-overall-stat-average-round-time-wrapper').style.display = 'none';
document.getElementById('standard-overall-stat-average-game-time-wrapper').style.display = 'none';
document.getElementById('standard-overall-stat-total5ks-wrapper').style.display = 'none';
document.getElementById('standard-stats-spacing-wrapper-1').style.display = 'none';
}
//If Current Gamemode Is Not Set
if(!window.localStorage.getItem('geostats-current-gamemode-${USER_ID}')){
window.localStorage.setItem('geostats-current-gamemode-${USER_ID}', 'duels');
}
//Event Listener For Gamemode Menu
document.getElementById('geostats-gamemodes-menu').addEventListener('click', (e) => {
let gameMode = e.path[0].id;
if(!(gameMode.includes('duels') || gameMode.includes('classic'))){
return;
}
//Make all gray
function menuItemsGray(){
let menuItems = document.getElementsByClassName('geostats-gamemodes-menu-item');
for(let i in menuItems){
if(i < menuItems.length){
menuItems[i].style.color = 'var(--ds-color-white-60)';
}
}
}
//If duels - set the stats and make it white
if(gameMode.includes('duels') && window.localStorage.getItem('overall-country-stats-${USER_ID}')){
//Clear All Current Overall Stats
clearAllOverallStats();
//Set Stats
setAllDuelsStats();
window.localStorage.setItem('geostats-current-gamemode-${USER_ID}', 'duels');
//Change Menu Color
menuItemsGray();
document.getElementById('geostats-gamemodes-menu-item-duels').style.color = 'white';
//If country stats are open, change to duels
if(document.getElementById('country-stats-page-wrapper').style.display == 'block'){
setupCountryStatsDuels('switch', window.localStorage.getItem('select-country-stats-id'));
}
}
//If classic - set the stats and make it white
else if(gameMode.includes('classic') && window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}')){
//Clear All Current Overall Stats
clearAllOverallStats();
//Set stats
setAllClassicStats();
window.localStorage.setItem('geostats-current-gamemode-${USER_ID}', 'classic');
//Change Menu Color
menuItemsGray();
document.getElementById('geostats-gamemodes-menu-item-classic').style.color = 'white';
//If country stats are open, change to classic
if(document.getElementById('country-stats-page-wrapper').style.display == 'block'){
setupCountryStatsClassic('switch', window.localStorage.getItem('select-country-stats-id'));
}
}
});
//First Time
clearAllOverallStats();
switch(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}')){
case 'duels':
if(window.localStorage.getItem('overall-country-stats-${USER_ID}')){
setAllDuelsStats();
}
document.getElementById('geostats-gamemodes-menu-item-duels').style.color = 'white';
break;
case 'classic':
if(window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}')){
setAllClassicStats();
}
document.getElementById('geostats-gamemodes-menu-item-classic').style.color = 'white';
break;
}
function mouseOverCountry(country){
if(typeof country.target !== 'undefined'){
country = country.target;
}
if (country.tagName == 'path'){
let content = country.dataset.name;
//Changing the color when you hover over a country
if(country.style.fill == 'lightcoral'){
country.setAttribute('style', 'fill:red');
}
else if(country.style.fill == 'lightgreen'){
country.setAttribute('style', 'fill:green');
}
else if(country.style.fill == 'rgb(233, 233, 84)'){
country.setAttribute('style', 'fill:yellow');
}
else if(country.style.fill == 'black'){
country.setAttribute('style', 'fill:rgb(175, 175, 175)');
}
//Displaying the country and the stats at the top of the page
let countryName = country.dataset.name;
let countryCorrect = 0;
let countryTotal = 0;
let countryPercentage = 0;
let countryDistance = 0.0;
let distanceUnit = 'km';
let target = country.id;
//IF DUELS
if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'duels'){
if(window.localStorage.getItem(target + '-number-correct-${USER_ID}') !== null){
countryCorrect = window.localStorage.getItem(target + '-number-correct-${USER_ID}');
}
if(window.localStorage.getItem(target + '-number-total-${USER_ID}') !== null){
countryTotal = window.localStorage.getItem(target + '-number-total-${USER_ID}');
}
if((countryCorrect !== 0) && (countryTotal !== 0)){
countryPercentage = Math.floor(100 * (parseInt(countryCorrect) / parseInt(countryTotal)));
}
if(window.localStorage.getItem(target + '-distance-average-${USER_ID}') !== null){
countryDistance = parseInt(window.localStorage.getItem(target + '-distance-average-${USER_ID}')) / 1000;
if(document.getElementById('unit-selector-mi').checked){
countryDistance = countryDistance / 1.609;
}
countryDistance = round(countryDistance,1);
}
if(document.getElementById('unit-selector-mi').checked){
distanceUnit = 'mi';
}
}
//IF CLASSIC
else if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'classic'){
if(window.localStorage.getItem('geostats-' + target +'-all-standard-stats-${USER_ID}')){
let stats = JSON.parse(window.localStorage.getItem('geostats-' + target +'-all-standard-stats-${USER_ID}'));
countryCorrect = stats.totalCorrect;
countryTotal = stats.totalCount;
countryPercentage = Math.floor(100 * (countryCorrect / countryTotal));
countryDistance = stats.averageDistance / 1000;
if(document.getElementById('unit-selector-mi').checked){
countryDistance = countryDistance / 1.609;
}
countryDistance = round(countryDistance,1);
}
if(document.getElementById('unit-selector-mi').checked){
distanceUnit = 'mi';
}
}
document.getElementById("display-country-details").textContent = countryName + ": " + countryCorrect + " / " + countryTotal + " (" + countryPercentage + "%)";
document.getElementById("display-country-details").style.visibility = "visible";
document.getElementById("display-country-distance").textContent = 'Average Distance: ' + countryDistance + ' ' + distanceUnit;
document.getElementById("display-country-distance").style.visibility = "visible";
}
};
function mouseOutCountry(country){
if(typeof country.target !== 'undefined'){
country = country.target;
}
if (country.tagName == 'path'){
//Changing the color when you stop hovering over a country
if(country.style.fill == 'red'){
country.setAttribute('style', 'fill:lightcoral');
}
if(country.style.fill == 'green'){
country.setAttribute('style', 'fill:lightgreen');
}
if(country.style.fill == 'yellow'){
country.setAttribute('style', 'fill:rgb(233, 233, 84)');
}
if(country.style.fill == 'rgb(175, 175, 175)'){
country.setAttribute('style', 'fill:black');
}
//Hiding the display at the top when no country is hovering
document.getElementById("display-country-details").style.visibility = "hidden";
document.getElementById("display-country-distance").style.visibility = "hidden";
}
};
function round(value, precision) {
let multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
};
//REGULAR LISTENERS
document.getElementById('map-wrapper-element').addEventListener('mouseover', mouseOverCountry);
document.getElementById('map-wrapper-element').addEventListener('mouseout', mouseOutCountry);
//SEARCH LIST
function mouseOverList(e){
let temp = e.target.id.toUpperCase();
let target_country = document.getElementById(temp);
mouseOverCountry(target_country);
}
function mouseOutList(e){
let temp = e.target.id.toUpperCase();
let target_country = document.getElementById(temp);
mouseOutCountry(target_country);
}
document.getElementById('search-bar').addEventListener('click', () => {
let search_bar = document.getElementById('search-bar');
let list = document.querySelectorAll('#search-bar-list li');
list.forEach(item => item.addEventListener('mouseover', mouseOverList));
list.forEach(item => item.addEventListener('mouseout', mouseOutList));
search_bar.onkeyup = () => {
let search = search_bar.value.toLowerCase();
let count = 0;
if(search_bar.value !== ''){
document.getElementById('search-bar-list').style.display = 'inline';
}
else{
document.getElementById('search-bar-list').style.display = 'none';
}
//Showing the results that match and hiding those that dont (max 6 items)
for(let i of list){
let item = i.innerHTML.toLowerCase();
if(item.indexOf(search) == -1){
i.style.display = 'none';
}
else{
if(count < 6){
count = count + 1;
i.style.display = 'block';
}
else{
i.style.display = 'none';
}
}
};
};
});
//OPEN AND CLOSE SETTINGS (and get back to homepage from country stats)
document.getElementById('map-settings-btn').addEventListener('click', () => {
if(document.getElementById('map-settings-btn').innerText == 'Back to Map'){
document.getElementById('map-settings-wrapper').style.display = 'none';
document.getElementById("country-stats-page-wrapper").style.display = 'none';
document.getElementById('map-settings-btn').innerText = 'Settings';
document.getElementsByClassName('display-wrapper')[0].style.display = 'block';
document.getElementById('search-bar-wrapper').style.display = 'block';
document.getElementsByClassName('map-wrapper')[0].style.display = 'block';
document.getElementById('overall-stats-page-wrapper').style.display = 'block';
}
else{
document.getElementById('map-settings-wrapper').style.display = 'block';
document.getElementById('map-settings-btn').innerText = 'Back to Map';
document.getElementsByClassName('display-wrapper')[0].style.display = 'none';
document.getElementById('search-bar-wrapper').style.display = 'none';
document.getElementsByClassName('map-wrapper')[0].style.display = 'none';
document.getElementById('overall-stats-page-wrapper').style.display = 'none';
//Reset button text
if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'duels'){
document.getElementById('reset-scores-btn').textContent = 'Reset All Duels Stats';
}
else if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'classic'){
document.getElementById('reset-scores-btn').textContent = 'Reset All Classic Stats';
}
}
});
//SET HEALING ROUNDS TOGGLE IN SETTINGS
let healing = JSON.parse(window.localStorage.getItem('allow-healing-rounds'));
if(healing.include){
document.getElementById('settings-allow-healing-rounds').checked = true;
}
else{
document.getElementById('settings-allow-healing-rounds').checked = false;
}
document.getElementById('settings-allow-healing-rounds').addEventListener('click', () => {
if(document.getElementById('settings-allow-healing-rounds').checked){
window.localStorage.setItem('allow-healing-rounds', JSON.stringify({include: true}));
}
else{
window.localStorage.setItem('allow-healing-rounds', JSON.stringify({include: false}));
}
});
//SET COMPETITIVE ONLY TOGGLE IN SETTINGS
let competitive = JSON.parse(window.localStorage.getItem('competitive-only-mode'));
if(competitive.include){
document.getElementById('settings-competitive-only-mode').checked = true;
}
else{
document.getElementById('settings-competitive-only-mode').checked = false;
}
document.getElementById('settings-competitive-only-mode').addEventListener('click', () => {
if(document.getElementById('settings-competitive-only-mode').checked){
window.localStorage.setItem('competitive-only-mode', JSON.stringify({include: true}));
}
else{
window.localStorage.setItem('competitive-only-mode', JSON.stringify({include: false}));
}
});
//RESET ALL SCORES
document.getElementById('reset-scores-btn').addEventListener('click', () => {
if(confirm('Are you sure you want to reset your stats? This cannot be undone.')){
if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'duels'){
resetDuelsScores();
}
else if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'classic'){
resetClassicScores();
}
//Reload the page
location.reload();
}
});
//Reset Duels Scores
function resetDuelsScores(){
//Remove country scores
countries.forEach(function(country){
window.localStorage.removeItem(country + '-number-correct-${USER_ID}');
window.localStorage.removeItem(country + '-number-total-${USER_ID}');
window.localStorage.removeItem(country + '-distance-average-${USER_ID}');
window.localStorage.removeItem(country + '-distance-number-${USER_ID}');
window.localStorage.removeItem(country + '-all-country-stats-${USER_ID}');
});
//Remove overall scores
window.localStorage.removeItem('overall-total-${USER_ID}');
window.localStorage.removeItem('overall-correct-${USER_ID}');
window.localStorage.removeItem('overall-country-stats-${USER_ID}');
};
//Reset Classic Scores
function resetClassicScores(){
//Country
countries.forEach(function(country){
window.localStorage.removeItem('geostats-' + country + '-all-standard-stats-${USER_ID}');
});
//Overall
window.localStorage.removeItem('geostats-overall-standard-stats-${USER_ID}');
};
//OPEN COUNTRY STATS PAGE
document.getElementById('map-wrapper-element').addEventListener('dblclick', (e) => {
let countryId = (e.path[0].id).toUpperCase();
if(countryId.length != 2){
return;
}
//Setup
window.localStorage.setItem('select-country-stats-id', countryId);
//IF DUELS
if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'duels'){
if(!window.localStorage.getItem(countryId + '-all-country-stats-${USER_ID}')){
return;
}
setupCountryStatsDuels(e,countryId);
}
//IF CLASSIC
else if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'classic'){
if(!window.localStorage.getItem('geostats-' + countryId + '-all-standard-stats-${USER_ID}')){
return;
}
setupCountryStatsClassic(e,countryId);
}
//HIDE EVERYTHING
document.getElementById('search-bar-wrapper').style.display = 'none';
document.getElementById('overall-stats-page-wrapper').style.display = 'none';
document.getElementsByClassName('map-wrapper')[0].style.display = 'none';
document.getElementsByClassName('display-wrapper')[0].style.display = 'none';
//SHOW CORRECT STUFF
document.getElementById("country-stats-page-wrapper").style.display = 'block';
document.getElementById('map-settings-btn').innerText = 'Back to Map';
});
//Setup For Country Stats (Duels)
function setupCountryStatsDuels(type,countryId){
//Set the stats to the correct values for the country (IF THE COUNTRY HAS STATS)
if(!window.localStorage.getItem(countryId + '-all-country-stats-${USER_ID}')){
return;
}
clearAllCountryStats();
setCountryStatsDuels(countryId);
let countryName;
//If Switching Gamemodes
if(type == 'switch'){
countryName = document.getElementById(countryId).dataset.name
}
else{
countryName = type.path[0].dataset.name;
}
let countryCorrect = 0;
let countryTotal = 0;
let countryPercentage = 0;
if(typeof countryName == 'undefined'){
countryName = type.path[0].textContent;
}
if(window.localStorage.getItem(countryId + '-number-correct-${USER_ID}') !== null){
countryCorrect = window.localStorage.getItem(countryId + '-number-correct-${USER_ID}');
}
if(window.localStorage.getItem(countryId + '-number-total-${USER_ID}') !== null){
countryTotal = window.localStorage.getItem(countryId + '-number-total-${USER_ID}');
}
if((countryCorrect !== 0) && (countryTotal !== 0)){
countryPercentage = Math.floor(100 * (parseInt(countryCorrect) / parseInt(countryTotal)));
}
document.getElementById('country-stats-display-details').textContent = countryName + ": " + countryCorrect + " / " + countryTotal + " (" + countryPercentage + "%)";
document.getElementById('country-stats-reset-btn').textContent = 'Reset All ' + countryName + ' Duels Stats';
};
//Setup For Country Stats (Classic)
function setupCountryStatsClassic(type,countryId){
//Set the stats to the correct values for the country (IF THE COUNTRY HAS STATS)
if(!window.localStorage.getItem('geostats-' + countryId + '-all-standard-stats-${USER_ID}')){
return;
}
clearAllCountryStats();
setCountryStatsClassic(countryId);
let countryName;
//If Switching Gamemodes
if(type == 'switch'){
countryName = document.getElementById(countryId).dataset.name
}
else{
countryName = type.path[0].dataset.name;
}
let countryCorrect = 0;
let countryTotal = 0;
let countryPercentage = 0;
if(typeof countryName == 'undefined'){
countryName = type.path[0].textContent;
}
let stats = JSON.parse(window.localStorage.getItem('geostats-' + countryId + '-all-standard-stats-${USER_ID}'));
countryCorrect = stats.totalCorrect;
countryTotal = stats.totalCount;
countryPercentage = Math.floor(100 * (countryCorrect / countryTotal));
document.getElementById('country-stats-display-details').textContent = countryName + ": " + countryCorrect + " / " + countryTotal + " (" + countryPercentage + "%)";
document.getElementById('country-stats-reset-btn').textContent = 'Reset All ' + countryName + ' Classic Stats';
};
//Clear All Country Stats On Gamemode Change
function clearAllCountryStats(){
//Duels
document.getElementById('country-stat-average-score-wrapper').style.display = 'none';
document.getElementById('country-stat-average-distance-wrapper').style.display = 'none';
document.getElementById('country-stat-closer-than-opponent-wrapper').style.display = 'none';
document.getElementById('country-stat-average-time-wrapper').style.display = 'none';
document.getElementById('country-stat-guessed-first-wrapper').style.display = 'none';
document.getElementById('country-stat-total-5ks-wrapper').style.display = 'none';
document.getElementById('duels-country-stats-spacing-wrapper-1').style.display = 'none';
//Standard
document.getElementById('standard-country-stat-average-score-wrapper').style.display = 'none';
document.getElementById('standard-country-stat-average-distance-wrapper').style.display = 'none';
document.getElementById('standard-country-stat-average-round-time-wrapper').style.display = 'none';
document.getElementById('standard-country-stat-total-5ks-wrapper').style.display = 'none';
document.getElementById('standard-country-stats-total-time-spent').style.display = 'none';
document.getElementById('standard-country-stats-spacing-wrapper-1').style.display = 'none';
};
//SET COUNTRY STATS FOR DUELS(ON DOUBLE CLICK)
function setCountryStatsDuels(countryCode){
let countryObject = JSON.parse(window.localStorage.getItem(countryCode + '-all-country-stats-${USER_ID}'));
let percentage;
let percentageColor;
//Country Stats
let totalCount = countryObject.totalCount;
let averageScore = Math.floor(countryObject.averageScore);
let averageDistance = Math.floor(countryObject.averageDistance/1000);
let closerThanOpponent = countryObject.closerThanOpponent;
let averageTime = Math.floor(countryObject.averageTime);
let guessedFirst = countryObject.guessedFirst;
let total5ks = countryObject.total5ks;
//Find correct percentage to color the outside circle
function findPercentage(stat, max){
percentage = (stat/max);
if(percentage >= ${green_range}){
percentageColor = 'green';
}
else if(percentage >= ${yellow_range}){
percentageColor = 'yellow';
}
else{
percentageColor = 'red';
}
percentage = 100 * percentage;
if(percentage <= 0){
percentage = 2;
}
};
//Average Score
findPercentage(averageScore, 5000);
document.getElementById('country-stat-average-score-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('country-stat-average-score-value').innerText = averageScore;
//Average Distance
findPercentage(2500-averageDistance, 2500);
document.getElementById('country-stat-average-distance-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
if(window.localStorage.getItem('units-svg-map') == 'mi'){
document.getElementById('country-stat-average-distance-title').innerText = 'Average Distance (mi)';
averageDistance = Math.floor(averageDistance / 1.609);
}
else{
document.getElementById('country-stat-average-distance-title').innerText = 'Average Distance (km)';
}
document.getElementById('country-stat-average-distance-value').innerText = averageDistance;
//Closer Than Opponent
findPercentage(closerThanOpponent, totalCount);
document.getElementById('country-stat-closer-than-opponent-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('country-stat-closer-than-opponent-value').innerText = Math.floor((100 * (closerThanOpponent/totalCount))) + '%';
//Average Time
findPercentage(120-averageTime, 120);
document.getElementById('country-stat-average-time-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('country-stat-average-time-value').innerText = averageTime;
//Guessed First
findPercentage(guessedFirst, totalCount);
document.getElementById('country-stat-guessed-first-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('country-stat-guessed-first-value').innerText = Math.floor((100 * (guessedFirst/totalCount))) + '%';
//Total 5ks
findPercentage(total5ks, 10);
document.getElementById('country-stat-total-5ks-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('country-stat-total-5ks-value').innerText = total5ks;
//BOTTOM STATS SETUP
document.getElementById('country-stats-distance-from-opponent-title').innerText = 'AVERAGE DISTANCE FROM OPPONENT';
//Distance From Opponent
let distanceFromOpponent = [Math.round(countryObject.distanceFromOpponent[1] / 1000),'km','+','green'];
if(window.localStorage.getItem('units-svg-map') == 'mi'){
distanceFromOpponent[0] = Math.round(distanceFromOpponent[0] / 1.609);
distanceFromOpponent[1] = 'mi';
}
if(distanceFromOpponent[0] < 0){
distanceFromOpponent[0] *= -1;
distanceFromOpponent[2] = '-';
distanceFromOpponent[3] = 'red';
}
document.getElementById('country-stats-distance-from-opponent-value').style.color = distanceFromOpponent[3];
document.getElementById('country-stats-distance-from-opponent-value').innerText = distanceFromOpponent[2] + distanceFromOpponent[0] + ' ' + distanceFromOpponent[1];
//Country Streaks
if(countryObject.countryCorrectStreak > 0){
document.getElementById('country-stats-country-streaks-value-current-value').innerText = countryObject.countryCorrectStreak + ' Correct';
document.getElementById('country-stats-country-streaks-value-current-value').style.color = 'green';
}
else if(countryObject.countryWrongStreak > 0){
document.getElementById('country-stats-country-streaks-value-current-value').innerText = countryObject.countryWrongStreak + ' Incorrect';
document.getElementById('country-stats-country-streaks-value-current-value').style.color = 'red';
}
document.getElementById('country-stats-country-streaks-value-max-correct-value').innerText = countryObject.countryCorrectMax;
document.getElementById('country-stats-country-streaks-value-max-wrong-value').innerText = countryObject.countryWrongMax;
//SHOW CORRECT VALUES
document.getElementById('country-stat-average-score-wrapper').style.display = 'flex';
document.getElementById('country-stat-average-distance-wrapper').style.display = 'flex';
document.getElementById('country-stat-closer-than-opponent-wrapper').style.display = 'flex';
document.getElementById('country-stat-average-time-wrapper').style.display = 'flex';
document.getElementById('country-stat-guessed-first-wrapper').style.display = 'flex';
document.getElementById('country-stat-total-5ks-wrapper').style.display = 'flex';
document.getElementById('duels-country-stats-spacing-wrapper-1').style.display = 'flex';
//CORRECT WIDTH FOR BOTTOM STATS
document.getElementById('country-stats-distance-from-opponent').style.width = '50%';
document.getElementById('country-stats-country-streaks').style.width = '50%';
document.getElementById('standard-country-stats-total-time-spent').style.width = '50%';
//CORRECT TEXT FOR RESET BUTTON
};
//SET COUNTRY STATS FOR CLASSIC (ON DOUBLE CLICK)
function setCountryStatsClassic(countryCode){
//Find correct percentage to color the outside circle
function findPercentage(stat, max){
percentage = (stat/max);
if(percentage >= ${green_range}){
percentageColor = 'green';
}
else if(percentage >= ${yellow_range}){
percentageColor = 'yellow';
}
else{
percentageColor = 'red';
}
percentage = 100 * percentage;
if(percentage <= 0){
percentage = 2;
}
};
//OVERALL STATS
let overallStats = JSON.parse(window.localStorage.getItem('geostats-' + countryCode + '-all-standard-stats-${USER_ID}'));
let percentage;
let percentageColor;
let averageScore = Math.floor(overallStats.averageScore);
let averageDistance = Math.floor(overallStats.averageDistance/1000);
let averageRoundTime = Math.floor(overallStats.averageRoundTime);
let total5ks = overallStats.total5ks;
//Average Score
findPercentage(averageScore, 5000);
document.getElementById('standard-country-stat-average-score-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-country-stat-average-score-value').innerText = averageScore;
//Average Distance
findPercentage(2500-averageDistance, 2500);
document.getElementById('standard-country-stat-average-distance-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
if(window.localStorage.getItem('units-svg-map') == 'mi'){
document.getElementById('standard-country-stat-average-distance-title').innerText = 'Average Distance (mi)';
averageDistance = Math.floor(averageDistance / 1.609);
}
else{
document.getElementById('standard-country-stat-average-distance-title').innerText = 'Average Distance (km)';
}
document.getElementById('standard-country-stat-average-distance-value').innerText = averageDistance;
//Average Round Time
findPercentage(120-averageRoundTime, 120);
document.getElementById('standard-country-stat-average-round-time-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-country-stat-average-round-time-value').innerText = averageRoundTime;
//Total 5ks
findPercentage(total5ks, 10);
document.getElementById('standard-country-stat-total-5ks-outer-circle').style.background = 'conic-gradient(' + percentageColor + ', ' + percentageColor + ' ' + percentage + '%, #808080 ' + percentage + '%, #808080)';
document.getElementById('standard-country-stat-total-5ks-value').innerText = total5ks;
//BOTTOM STATS SETUP
//Commonly Guessed Incorrectly
document.getElementById('country-stats-distance-from-opponent-title').innerText = 'COMMONLY GUESSED INSTEAD';
let textColor = 'green';
let innerText = '';
if(Object.keys(overallStats.incorrectCountry).length != 0){
let incorrectGuesses = Object.entries(overallStats.incorrectCountry).sort((a,b) => b[1]-a[1]);
for(let i = 0; i < 3; i++){
let tempText = '';
if(i < incorrectGuesses.length){
tempText = document.getElementById(incorrectGuesses[i][0]).dataset.name + ' - ' + incorrectGuesses[i][1];
}
innerText += tempText + '\\n';
}
textColor = 'red';
}
else{
innerText = 'N/A';
}
document.getElementById('country-stats-distance-from-opponent-value').style.color = textColor;
document.getElementById('country-stats-distance-from-opponent-value').innerText = innerText;
//Country Streaks
if(overallStats.countryCorrectStreak > 0){
document.getElementById('country-stats-country-streaks-value-current-value').innerText = overallStats.countryCorrectStreak + ' Correct';
document.getElementById('country-stats-country-streaks-value-current-value').style.color = 'green';
}
else if(overallStats.countryWrongStreak > 0){
document.getElementById('country-stats-country-streaks-value-current-value').innerText = overallStats.countryWrongStreak + ' Incorrect';
document.getElementById('country-stats-country-streaks-value-current-value').style.color = 'red';
}
document.getElementById('country-stats-country-streaks-value-max-correct-value').innerText = overallStats.countryCorrectMax;
document.getElementById('country-stats-country-streaks-value-max-wrong-value').innerText = overallStats.countryWrongMax;
//Time Spent
let minutesPlayed = Math.floor(Math.floor(overallStats.totalSeconds / 60) % 60);
let hoursPlayed = Math.floor(overallStats.totalSeconds / 3600);
document.getElementById('standard-country-stats-total-time-spent-value').innerText = hoursPlayed + 'h ' + minutesPlayed + 'm ';
//SHOW CORRECT VALUES
document.getElementById('standard-country-stat-average-score-wrapper').style.display = 'flex';
document.getElementById('standard-country-stat-average-distance-wrapper').style.display = 'flex';
document.getElementById('standard-country-stat-average-round-time-wrapper').style.display = 'flex';
document.getElementById('standard-country-stat-total-5ks-wrapper').style.display = 'flex';
document.getElementById('standard-country-stats-total-time-spent').style.display = 'flex';
document.getElementById('standard-country-stats-spacing-wrapper-1').style.display = 'flex';
//CORRECT WIDTH FOR BOTTOM STATS
document.getElementById('country-stats-distance-from-opponent').style.width = '33.333%';
document.getElementById('country-stats-country-streaks').style.width = '33.333%';
document.getElementById('standard-country-stats-total-time-spent').style.width = '33.333%';
};
//RESET SCORES FOR SELECTED COUNTRY
document.getElementById('country-stats-reset-btn').addEventListener('click', () => {
let resetId = window.localStorage.getItem('select-country-stats-id');
//Reset all scores for country
if(confirm('Are you sure you want to reset your stats? This cannot be undone.')){
if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'duels'){
resetDuelsCountryScores(resetId);
}
else if(window.localStorage.getItem('geostats-current-gamemode-${USER_ID}') == 'classic'){
resetClassicCountryScores(resetId);
}
//Reload the page
location.reload();
}
});
//Reset Duels Country Scores
function resetDuelsCountryScores(resetId){
let countryCorrect = parseInt(window.localStorage.getItem(resetId + '-number-correct-${USER_ID}'));
let countryTotal = parseInt(window.localStorage.getItem(resetId + '-number-total-${USER_ID}'));
let countryStats = JSON.parse(window.localStorage.getItem(resetId + '-all-country-stats-${USER_ID}'));
let overallStats = JSON.parse(window.localStorage.getItem('overall-country-stats-${USER_ID}'));
if(isNaN(countryCorrect)){
countryCorrect = 0;
}
if(isNaN(countryTotal)){
countryTotal = 0;
}
//Remove country scores from overall scores
countryCorrect = (parseInt(window.localStorage.getItem('overall-correct-${USER_ID}')) - countryCorrect);
countryTotal = (parseInt(window.localStorage.getItem('overall-total-${USER_ID}')) - countryTotal);
overallStats.totalCount = overallStats.totalCount - countryStats.totalCount;
overallStats.closerThanOpponent = overallStats.closerThanOpponent - countryStats.closerThanOpponent;
overallStats.guessedFirst = overallStats.guessedFirst - countryStats.guessedFirst;
overallStats.total5ks = overallStats.total5ks - countryStats.total5ks;
//Set Stats To New Values
window.localStorage.setItem('overall-correct-${USER_ID}', countryCorrect);
window.localStorage.setItem('overall-total-${USER_ID}', countryTotal);
window.localStorage.setItem('overall-country-stats-${USER_ID}',JSON.stringify(overallStats));
//Remove Country Scores
window.localStorage.removeItem(resetId + '-number-correct-${USER_ID}');
window.localStorage.removeItem(resetId + '-number-total-${USER_ID}');
window.localStorage.removeItem(resetId + '-distance-average-${USER_ID}');
window.localStorage.removeItem(resetId + '-distance-number-${USER_ID}');
window.localStorage.removeItem(resetId + '-all-country-stats-${USER_ID}');
}
//Reset Classic Country Scores
function resetClassicCountryScores(resetId){
let country = JSON.parse(window.localStorage.getItem('geostats-' + resetId + '-all-standard-stats-${USER_ID}'));
let overall = JSON.parse(window.localStorage.getItem('geostats-overall-standard-stats-${USER_ID}'));
//Remove from overall
overall.totalCount -= country.totalCount;
overall.totalCorrect -= country.totalCorrect;
overall.total5ks -= country.total5ks;
// Remove country
window.localStorage.removeItem('geostats-' + resetId + '-all-standard-stats-${USER_ID}');
//Save overall
window.localStorage.setItem('geostats-overall-standard-stats-${USER_ID}',JSON.stringify(overall));
}
//MAP SLIDER RANGES
let leftSlider = document.getElementById("left-slider");
let rightSlider = document.getElementById("right-slider");
let sliderTrack = document.getElementById("slider-track");
let minGap = 5;
leftSlider.value = window.localStorage.getItem('duels-map-color-left-range-${USER_ID}');
rightSlider.value = window.localStorage.getItem('duels-map-color-right-range-${USER_ID}');
//Change Left Slider Value
function calcLeftSlider(){
if(parseInt(rightSlider.value) - parseInt(leftSlider.value) <= minGap){
leftSlider.value = parseInt(rightSlider.value) - minGap;
}
else if(leftSlider.value < 5){
leftSlider.value = 5;
}
document.getElementById('left-slider-output').innerText = leftSlider.value + '%';
document.getElementById('left-slider-output').style.left = findValue(leftSlider.value);
fillColor();
window.localStorage.setItem('duels-map-color-left-range-${USER_ID}', leftSlider.value);
}
//Change Right Slider Value
function calcRightSlider(){
if(parseInt(rightSlider.value) - parseInt(leftSlider.value) <= minGap){
rightSlider.value = parseInt(leftSlider.value) + minGap;
}
else if(rightSlider.value > 95){
rightSlider.value = 95;
}
document.getElementById('right-slider-output').innerText = rightSlider.value + '%';
document.getElementById('right-slider-output').style.left = findValue(rightSlider.value);
fillColor();
window.localStorage.setItem('duels-map-color-right-range-${USER_ID}', rightSlider.value);
}
//Fill The Slider With Colors
function fillColor(){
let percent1 = parseInt(leftSlider.value);
let percent2 = parseInt(rightSlider.value);
sliderTrack.style.background = 'linear-gradient(to right, red 0%, red ' + percent1 + '%, yellow ' + percent1 + '%, yellow ' + percent2 +'%, green ' + percent2 + '%, green 100%)';
}
//Put Value Above Slider Thumb
function findValue(val){
let valueOne = parseInt(val);
let valueTwo = valueOne * 0.2;
let final = 'calc(' + valueOne + '% - ' + valueTwo + 'px)';
return final;
}
//Add Event Listeners
document.getElementById("left-slider").addEventListener('input', calcLeftSlider);
document.getElementById("right-slider").addEventListener('input', calcRightSlider);
calcLeftSlider();
calcRightSlider();
//UPLOAD AND DOWNLOAD STATS FILE
let downloadFile = null;
let uploadFileData = {};
let readyToUpload = false;
let uploadData = null;
function getAllDuelsStats(downloadData){
downloadData.gameMode = 'duels';
//Get All Scores
for(let key in window.localStorage){
let newValue = [];
if(key.includes('${USER_ID}')){
if(key.includes('-number-correct-') || key.includes('-number-total-') || key.includes('-distance-average-') || key.includes('-distance-number-') || key.includes('-all-country-stats-') || key.includes('overall-total-') || key.includes('overall-correct-') || key.includes('overall-country-stats-')){
newValue.push(key);
if(isJson(window.localStorage[key])){
newValue.push(JSON.parse(window.localStorage[key]));
}
else{
newValue.push(window.localStorage[key]);
}
downloadData.userInfo.push(newValue);
}
}
}
};
function getAllClassicStats(downloadData){
downloadData.gameMode = 'classic';
//Country
countries.forEach(function(country){
let key = 'geostats-' + country + '-all-standard-stats-${USER_ID}';
if(window.localStorage.getItem(key)){
downloadData.userInfo.push([key, JSON.parse(window.localStorage.getItem(key))]);
}
});
//Overall
key = 'geostats-overall-standard-stats-${USER_ID}';
if(window.localStorage.getItem(key)){
downloadData.userInfo.push([key , JSON.parse(window.localStorage.getItem(key))]);
}
//Included Maps
key = 'geostats-classic-included-maps-${USER_ID}';
if(window.localStorage.getItem(key)){
downloadData.userInfo.push([key , JSON.parse(window.localStorage.getItem(key))]);
}
//Unfinished Classic Games
key = 'geostats-unfinished-classic-games-${USER_ID}';
if(window.localStorage.getItem(key)){
downloadData.userInfo.push([key , JSON.parse(window.localStorage.getItem(key))]);
}
};
function getAllGamemodeStats(downloadData){
downloadData.gameMode = 'all';
for(let key in window.localStorage){
let newValue = [];
if(key.includes('${USER_ID}')){
newValue.push(key);
if(isJson(window.localStorage[key])){
newValue.push(JSON.parse(window.localStorage[key]));
}
else{
newValue.push(window.localStorage[key]);
}
downloadData.userInfo.push(newValue);
}
}
};
function isJson(string){
try{
JSON.parse(string);
}
catch(e){
return false;
}
return true;
};
//DOWNLOAD
function getFileContent(){
let downloadData = {
type: 'GeoStats_Object',
id: '${USER_ID}',
gameMode: '',
userInfo: []
};
//Get Settings Values
if(window.localStorage.getItem('units-svg-map')){
downloadData.userInfo.push(['units-svg-map', window.localStorage.getItem('units-svg-map')]);
}
if(window.localStorage.getItem('allow-healing-rounds')){
downloadData.userInfo.push(['allow-healing-rounds', JSON.parse(window.localStorage.getItem('allow-healing-rounds'))]);
}
if(window.localStorage.getItem('competitive-only-mode')){
downloadData.userInfo.push(['competitive-only-mode', JSON.parse(window.localStorage.getItem('competitive-only-mode'))]);
}
let baseInfoCount = downloadData.userInfo.length + 4; //+4 is for: "update, setup, left range, right range" in localstorage
let userOption = prompt("Which Stats Would You Like To Download?\\nEnter 'd' for Duels, 'c' for Classic, or 'a' for All");
switch(userOption){
case 'd':
getAllDuelsStats(downloadData);
break;
case'c':
getAllClassicStats(downloadData);
break;
case 'a':
getAllGamemodeStats(downloadData);
break;
case null:
return 'NO OPTION SELECTED';
break;
default:
return 'INVALID INPUT';
}
//If There Are No Stats To Download
if(downloadData.userInfo.length <= baseInfoCount){
return 'NO EXISTING STATS TO DOWNLOAD';
}
return JSON.stringify(downloadData);
};
function makeTextFile(text){
let data = new Blob([text], {type: 'text/plain'});
if(downloadFile != null){
window.URL.revokeObjectURL(downloadFile);
}
downloadFile = window.URL.createObjectURL(data);
return downloadFile;
};
function downloadAllStats(e){
if(!e.isTrusted){
return;
}
let link = document.getElementById('download-link');
let fileContent = getFileContent();
if(fileContent == 'NO EXISTING STATS TO DOWNLOAD'){
document.getElementById('download-file-status').style.color = 'red';
document.getElementById('download-file-status').textContent = 'No Existing Stats To Download';
}
else if(fileContent == 'NO OPTION SELECTED'){
document.getElementById('download-file-status').style.color = 'red';
document.getElementById('download-file-status').textContent = 'No option selected';
}
else if(fileContent == 'INVALID INPUT'){
document.getElementById('download-file-status').style.color = 'red';
document.getElementById('download-file-status').textContent = 'Invalid Input';
}
else{
link.href = makeTextFile(fileContent);
link.click();
document.getElementById('download-file-status').style.color = 'green';
document.getElementById('download-file-status').textContent = 'Successfully Downloaded Existing Stats';
}
};
//UPLOAD
function deleteOldStats(gameMode){
switch(gameMode){
case 'duels':
resetDuelsScores();
break;
case 'classic':
resetClassicScores();
break;
case 'all':
for(let key in window.localStorage){
if(key.includes('${USER_ID}')){
window.localStorage.removeItem(key);
}
}
break;
default:
}
};
function addNewStats(){
uploadFileData.userInfo.forEach((value) => {
if(typeof value[1] === 'string'){
window.localStorage.setItem(value[0], value[1]);
}
else{
window.localStorage.setItem(value[0], JSON.stringify(value[1]));
}
});
};
function getFileData(event){
let reader = new FileReader();
reader.readAsText(event.target.files[0]);
reader.addEventListener('load', (event) => {
try{
//Check if file content is JSON
if(!isJson(event.target.result)){
throw "File Content Is Not Json";
}
uploadFileData = JSON.parse(event.target.result);
//Check if the object is the right one
if(uploadFileData.type != 'GeoStats_Object'){
throw "File Content Is The Wrong Type";
}
//Check if the file stats have the same user id
if(uploadFileData.id != '${USER_ID}'){
throw "File Contains Different User Id";
}
let gameMode = uploadFileData.gameMode;
if(confirm('Are you sure you want to upload new stats? This will erase ' + gameMode + ' exisiting stats.')){
//Delete existing stats
deleteOldStats(gameMode);
//Add new stats
addNewStats();
//If all good
document.getElementById('upload-file-status').style.color = 'green';
document.getElementById('upload-file-status').textContent = 'Successfully Uploaded New Stats - Reload Page';
}
}
catch(message){
//If error exists
document.getElementById('upload-file-status').style.color = 'red';
document.getElementById('upload-file-status').textContent = message;
}
});
};
function checkFile(event){
readyToUpload = false;
uploadData = null;
document.getElementById('select-file-status').style.color = 'red';
document.getElementById('select-file-status').textContent = event.target.files[0].name;
//Check if the file is the right type to upload
if(event.target.files.length != 1){
return;
}
if(event.target.files[0].type != 'text/plain'){
return;
}
//If all good
readyToUpload = true;
uploadData = event;
document.getElementById('select-file-status').style.color = 'green';
};
//Add Event Listeners For Upload and Download
document.getElementById('download-file-button').addEventListener('click', downloadAllStats);
document.getElementById('select-file-button').addEventListener('change', checkFile);
document.getElementById('upload-file-button').addEventListener('click', () => {
if(readyToUpload){
getFileData(uploadData);
}
else{
document.getElementById('upload-file-status').style.color = 'red';
document.getElementById('upload-file-status').textContent = 'Please Select A File To Upload';
}
});
//PANNING AND ZOOMING ON THE MAP
let worldMap = document.getElementById('world-map');
let viewbox = worldMap.viewBox.baseVal;
let pointerDown = false;
let mousePoint;
//Return x and y values from pointer event
function getPointFromEvent(event){
let point = worldMap.createSVGPoint();
point.x = event.clientX;
point.y = event.clientY;
//Get current transformation matrix and inverse it
let invertedSVGMatrix = worldMap.getScreenCTM().inverse();
return point.matrixTransform(invertedSVGMatrix);
}
//When user clicks map to start panning
function onPointerDown(event){
event.preventDefault();
pointerDown = true;
mousePoint = getPointFromEvent(event);
}
//When user drags mouse
function onPointerMove(event){
if (!pointerDown){
return;
}
event.preventDefault();
document.getElementById('world-map').style = 'cursor: grabbing';
let pointerPosition = getPointFromEvent(event);
viewbox.x = (viewbox.x - (pointerPosition.x - mousePoint.x));
viewbox.y = (viewbox.y - (pointerPosition.y - mousePoint.y));
checkBounds();
}
//When user lifts mouse up
function onPointerUp(){
event.preventDefault();
pointerDown = false;
document.getElementById('world-map').style = 'cursor: auto';
}
//When user scrolls mouse
function onMouseWheel(event){
if(!event.shiftKey){
return;
}
event.preventDefault();
let delta = (event.wheelDelta ? event.wheelDelta : -event.deltaY);
mousePoint = getPointFromEvent(event);
//If mouse wheel moves forward
if(delta > 0){
//Zoom In Limit
if(viewbox.width > 325 && viewbox.height > 140){
//Make the viewbox smaller
viewbox.width /= 1.1;
viewbox.height /= 1.1;
//Position the top left accordingly
viewbox.x = (((mousePoint.x - viewbox.x) * viewbox.width) - ((mousePoint.x - viewbox.x) * mousePoint.x) - ((viewbox.x + (viewbox.width * 1.1) - mousePoint.x) * mousePoint.x) ) / ( -((mousePoint.x - viewbox.x) + (viewbox.x + (viewbox.width * 1.1) - mousePoint.x)) );
viewbox.y = (((mousePoint.y - viewbox.y) * viewbox.height) - ((mousePoint.y - viewbox.y) * mousePoint.y) - ((viewbox.y + (viewbox.height * 1.1) - mousePoint.y) * mousePoint.y) ) / ( -((mousePoint.y - viewbox.y) + (viewbox.y + (viewbox.height * 1.1) - mousePoint.y)) );
}
}
//If mouse wheel moves backward
else{
//Zoom Out Limit
if(viewbox.width < 2000 && viewbox.height < 857){
//Make the viewbox bigger
viewbox.width *= 1.1;
viewbox.height *= 1.1;
//Position the top left accordingly
viewbox.x = (((viewbox.x + (viewbox.width / 1.1) - mousePoint.x) * mousePoint.x) - ((mousePoint.x - viewbox.x) * viewbox.width) + ((mousePoint.x - viewbox.x) * mousePoint.x)) / ((mousePoint.x - viewbox.x) + (viewbox.x + (viewbox.width / 1.1) - mousePoint.x));
viewbox.y = (((viewbox.y + (viewbox.height / 1.1) - mousePoint.y) * mousePoint.y) - ((mousePoint.y - viewbox.y) * viewbox.height) + ((mousePoint.y - viewbox.y) * mousePoint.y)) / ((mousePoint.y - viewbox.y) + (viewbox.y + (viewbox.height / 1.1) - mousePoint.y));
}
}
checkBounds();
}
//Check if the map is out of bounds
function checkBounds(){
//Left
if(viewbox.x < 0){
viewbox.x = 0;
}
//Top
if(viewbox.y < 0){
viewbox.y = 0;
}
//Right
if((viewbox.x + viewbox.width) > 2000){
viewbox.x = 2000 - viewbox.width;
}
//Bottom
if((viewbox.y + viewbox.height) > 857){
viewbox.y = 857 - viewbox.height;
}
}
//Add event listeners
worldMap.addEventListener('pointerdown', onPointerDown);
worldMap.addEventListener('pointerup', onPointerUp);
worldMap.addEventListener('pointerleave', onPointerUp);
worldMap.addEventListener('pointermove', onPointerMove);
worldMap.addEventListener('wheel', onMouseWheel);
}`;
let referenceNode = document.getElementsByClassName('version3_main__xNkED')[0];
let siblingNode = document.getElementsByClassName('footer_footer__NmtmJ')[0];
referenceNode.parentNode.insertBefore(svgMap, siblingNode);
document.head.appendChild(cssForMap);
document.getElementById('map-wrapper-element').appendChild(scriptForMap);
};
/************************************************** START PAGE STUFF HERE **************************************************/
function addToggleToStartPage(){
toggleToStartPage = true;
//Create The Html
const htmlForToggle = `
GeoStats Settings
Track Stats For This Map
`;
//Create The Script
const scriptForToggle = document.createElement('script');
scriptForToggle.setAttribute('id','geostats-standard-game-start-page-toggle-script');
scriptForToggle.textContent = `{
//Check If Toggle Should Be Checked
let maps = JSON.parse(window.localStorage.getItem('geostats-classic-included-maps-${USER_ID}'));
let currentMapId = window.location.href.replace('https://www.geoguessr.com/maps/', '');
currentMapId = currentMapId.replace('/play', '');
if(maps.ids.includes(currentMapId)){
document.getElementById('geostats-track-stats-for-this-map-toggle').checked = true;
}
//When The Toggle Changes
function toggleChange(toggle){
let currentMapId = window.location.href.replace('https://www.geoguessr.com/maps/', '');
currentMapId = currentMapId.replace('/play', '');
let maps = JSON.parse(window.localStorage.getItem('geostats-classic-included-maps-${USER_ID}'));
if(toggle.path[0].checked){
//Add The Map Id
if(!maps.ids.includes(currentMapId)){
maps.ids.push(currentMapId);
}
}
else{
//Remove The Map Id
if(maps.ids.includes(currentMapId)){
const index = maps.ids.indexOf(currentMapId);
maps.ids.splice(index,1);
}
}
//Save Updated Maps List
window.localStorage.setItem('geostats-classic-included-maps-${USER_ID}', JSON.stringify(maps));
}
document.getElementById('geostats-track-stats-for-this-map-toggle').addEventListener('click', toggleChange);
}`;
//Add Everything To The Page
document.querySelector('.section_sectionMedium__yXgE6').insertAdjacentHTML('beforeend', htmlForToggle);
document.getElementById('geostats-standard-game-start-page-toggle-html').appendChild(scriptForToggle);
};
/* Credit to macca#8949 for these lines */
let observer = new MutationObserver((mutations) => {
startpageCheck();
});
observer.observe(document.body, {
characterDataOldValue: false,
subtree: true,
childList: true,
characterData: false
});
/* Credit to macca#8949 for these lines */
//************************************************************** END OF SCRIPT **************************************************************//