Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
World of Trucks Xmas 2020 Community Event addon (advanced stats, sorting, and more)
// ==UserScript==
// @id worldoftrucksxmas20
// @name Xmas Event 2020 Advanced Stats
// @namespace worldoftrucks
//
// @version 1.0
//
// @description Shows more stats on the World of Trucks homepage for the Xmas 2020 Community Event
// @author LyraGhost
// @homepage https://gist.github.com/LyraGhost
// @supportURL https://forum.scssoft.com/viewtopic.php?f=134&t=293309
//
// @icon https://www.worldoftrucks.com/img/favicon32.ico
//
// @include https://www.worldoftrucks.com/en/
// @include https://worldoftrucks.com/en/
//
// @grant none
// @run-at document-end
// ==/UserScript==
(function($) {
'use strict';
function Xmas20(options) {
this.options = $.extend({},this.defaults,options);
this.init();
}
Xmas20.prototype = {
styleData: '.xmas-stats-container{width:913px}.xmas-stats-container .button-wrap,.xmas-stats-container .xmas-loading-msg{text-align:right;padding-bottom:8px}.xmas-stats-container .button-wrap a+a{margin-left:12px}.global-events .global-event .advanced-community-progress-bar{width:913px;height:35px;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;margin-bottom:10px;background:rgb(20, 26, 28)}.global-event .games .game-name .xmas-sort-wrap{float:right}.global-event .games .game-name .xmas-sort-wrap span{padding-right:12px}.global-event .games .game-name .xmas-sort-wrap a{padding:7px 12px;margin:-7px 0;color:#fff;border-left:3px solid #252c2e}.global-event .games .game-name a.active{background-color:#904d06}.global-event .games .game-name a:hover{background-color:#a45707}.global-events .global-event .games .advanced-community-progress-bar{width:calc(100% - 5px);margin-right:5px;height:28px}.global-events .global-event .games .community-progress-value{font-size:13px}body.xmas-stats-ready .xmas-stats-container .xmas-loading-msg,body.completed-cities-hidden .global-events .event-xmas20 .games .game-column .game-scoll .component-row-completed,body:not(.advanced-stats-shown) .global-events .games .advanced-community-progress-bar,body:not(.advanced-stats-shown) .xmas-stats-container .advanced-community-progress-bar,body:not(.xmas-stats-ready) .global-events .games .game-name .xmas-sort-wrap,body:not(.xmas-stats-ready) .xmas-stats-container .button-wrap{display:none}body.expand-city-lists .global-events .event-xmas20 .games .game-column .game-scoll{height:auto}',
statsReady: false,
statsShown: false,
completedHidden: false,
expandLists: false,
sortModes: ['default', 'hearts', 'cities'],
europeSortMode: 'default',
americaSortMode: 'default',
defaults: {
baseSelector: '.global-event.event-xmas20 .header-extension',
gamesSelector: '.global-event.event-xmas20 .games .game-column',
classes: {
statsReady: 'xmas-stats-ready',
statsShown: 'advanced-stats-shown',
completedHidden: 'completed-cities-hidden',
expandLists: 'expand-city-lists',
statsContainer: 'xmas-stats-container',
buttonWrap: 'button-wrap',
sortButtonWrap: 'xmas-sort-wrap',
loading: 'xmas-loading-msg',
btn: {
advanced: 'xmas-advanced-stats-btn',
completed: 'xmas-completed-cities-btn',
expandLists: 'xmas-expand-lists-btn',
sort: 'xmas-sort-btn',
sortActive: 'active'
},
progressBar: {
container: 'advanced-community-progress-bar',
inner: 'community-progress-value',
current: 'advanced-current-value',
max: 'advanced-max-value',
percent: 'advanced-percent-value'
},
listCitiesSortedDefault: 'cities-sorted-default',
listCitiesSortedHearts: 'cities-sorted-hearts',
listCitiesSortedGifts: 'cities-sorted-gifts'
},
texts: {
loading: 'loading data...',
sortBy: 'Sort by:',
btn: {
advancedShow: 'Show Advanced Stats',
advancedHide: 'Hide Advanced Stats',
completedShow: 'Show Completed Cities',
completedHide: 'Hide Completed Cities',
expandLists: 'Expand City Lists',
collapseLists: 'Collapse City Lists',
sortDefault: 'City',
sortHearts: 'Hearts',
sortGifts: 'Gifts'
}
}
},
cityMap: {
europe:{"graz":{dlc:"base",region:"austria"},"innsbruck":{dlc:"base",region:"austria"},"klagenfurt":{dlc:"base",region:"austria"},"linz":{dlc:"base",region:"austria"},"salzburg":{dlc:"base",region:"austria"},"wien":{dlc:"base",region:"austria"},"brussel":{dlc:"base",region:"belgium"},"liege":{dlc:"base",region:"belgium"},"burgas":{dlc:"blacksea",region:"bulgaria"},"karlovo":{dlc:"blacksea",region:"bulgaria"},"kozloduy":{dlc:"blacksea",region:"bulgaria"},"pernik":{dlc:"blacksea",region:"bulgaria"},"pirdop":{dlc:"blacksea",region:"bulgaria"},"pleven":{dlc:"blacksea",region:"bulgaria"},"plovdiv":{dlc:"blacksea",region:"bulgaria"},"ruse":{dlc:"blacksea",region:"bulgaria"},"sofia":{dlc:"blacksea",region:"bulgaria"},"varna":{dlc:"blacksea",region:"bulgaria"},"veli_tarnovo":{dlc:"blacksea",region:"bulgaria"},"brno":{dlc:"base",region:"czech"},"ostrava":{dlc:"east",region:"czech"},"prague":{dlc:"base",region:"czech"},"aalborg":{dlc:"north",region:"denmark"},"kobenhavn":{dlc:"north",region:"denmark"},"esbjerg":{dlc:"north",region:"denmark"},"frederikshv":{dlc:"north",region:"denmark"},"gedser":{dlc:"north",region:"denmark"},"hirtshals":{dlc:"north",region:"denmark"},"odense":{dlc:"north",region:"denmark"},"kunda":{dlc:"baltic",region:"estonia"},"narva":{dlc:"baltic",region:"estonia"},"paldiski":{dlc:"baltic",region:"estonia"},"parnu":{dlc:"baltic",region:"estonia"},"tallinn":{dlc:"baltic",region:"estonia"},"tartu":{dlc:"baltic",region:"estonia"},"helsinki":{dlc:"baltic",region:"finland"},"kotka":{dlc:"baltic",region:"finland"},"kouvola":{dlc:"baltic",region:"finland"},"lahti":{dlc:"baltic",region:"finland"},"loviisa":{dlc:"baltic",region:"finland"},"naantali":{dlc:"baltic",region:"finland"},"olkiluoto":{dlc:"baltic",region:"finland"},"pori":{dlc:"baltic",region:"finland"},"tampere":{dlc:"baltic",region:"finland"},"turku":{dlc:"baltic",region:"finland"},"ajaccio":{dlc:"france",region:"france"},"bastia":{dlc:"france",region:"france"},"bonifacio":{dlc:"france",region:"france"},"bordeaux":{dlc:"france",region:"france"},"bourges":{dlc:"france",region:"france"},"brest":{dlc:"france",region:"france"},"calais":{dlc:"base",region:"france"},"calvi":{dlc:"france",region:"france"},"civaux":{dlc:"france",region:"france"},"clermont":{dlc:"france",region:"france"},"dijon":{dlc:"base",region:"france"},"golfech":{dlc:"france",region:"france"},"lile_rousse":{dlc:"france",region:"france"},"larochelle":{dlc:"france",region:"france"},"lehavre":{dlc:"france",region:"france"},"lemans":{dlc:"france",region:"france"},"lille":{dlc:"base",region:"france"},"limoges":{dlc:"france",region:"france"},"lyon":{dlc:"base",region:"france"},"marseille":{dlc:"france",region:"france"},"metz":{dlc:"base",region:"france"},"montpellier":{dlc:"france",region:"france"},"nantes":{dlc:"france",region:"france"},"nice":{dlc:"france",region:"france"},"paluel":{dlc:"france",region:"france"},"paris":{dlc:"base",region:"france"},"porto_vecchi":{dlc:"france",region:"france"},"reims":{dlc:"base",region:"france"},"rennes":{dlc:"france",region:"france"},"roscoff":{dlc:"france",region:"france"},"alban":{dlc:"france",region:"france"},"laurent":{dlc:"france",region:"france"},"strasbourg":{dlc:"base",region:"france"},"toulouse":{dlc:"france",region:"france"},"berlin":{dlc:"base",region:"germany"},"bremen":{dlc:"base",region:"germany"},"koln":{dlc:"base",region:"germany"},"dortmund":{dlc:"base",region:"germany"},"dresden":{dlc:"base",region:"germany"},"duisburg":{dlc:"base",region:"germany"},"dusseldorf":{dlc:"base",region:"germany"},"erfurt":{dlc:"base",region:"germany"},"frankfurt":{dlc:"base",region:"germany"},"hamburg":{dlc:"base",region:"germany"},"hannover":{dlc:"base",region:"germany"},"kassel":{dlc:"base",region:"germany"},"kiel":{dlc:"base",region:"germany"},"leipzig":{dlc:"base",region:"germany"},"magdeburg":{dlc:"base",region:"germany"},"mannheim":{dlc:"base",region:"germany"},"munchen":{dlc:"base",region:"germany"},"nurnberg":{dlc:"base",region:"germany"},"osnabruck":{dlc:"base",region:"germany"},"rostock":{dlc:"base",region:"germany"},"stuttgart":{dlc:"base",region:"germany"},"travemunde":{dlc:"base",region:"germany"},"budapest":{dlc:"east",region:"hungary"},"debrecen":{dlc:"east",region:"hungary"},"pecs":{dlc:"east",region:"hungary"},"szeged":{dlc:"east",region:"hungary"},"ancona":{dlc:"italy",region:"italy"},"bari":{dlc:"italy",region:"italy"},"bologna":{dlc:"italy",region:"italy"},"cagliari":{dlc:"italy",region:"italy"},"cassino":{dlc:"italy",region:"italy"},"catania":{dlc:"italy",region:"italy"},"catanzaro":{dlc:"italy",region:"italy"},"firenze":{dlc:"italy",region:"italy"},"genova":{dlc:"italy",region:"italy"},"livorno":{dlc:"italy",region:"italy"},"messina":{dlc:"italy",region:"italy"},"milano":{dlc:"base",region:"italy"},"napoli":{dlc:"italy",region:"italy"},"olbia":{dlc:"italy",region:"italy"},"palermo":{dlc:"italy",region:"italy"},"parma":{dlc:"italy",region:"italy"},"pescara":{dlc:"italy",region:"italy"},"roma":{dlc:"italy",region:"italy"},"sassari":{dlc:"italy",region:"italy"},"suzzara":{dlc:"italy",region:"italy"},"taranto":{dlc:"italy",region:"italy"},"terni":{dlc:"italy",region:"italy"},"torino":{dlc:"base",region:"italy"},"venezia":{dlc:"base",region:"italy"},"verona":{dlc:"base",region:"italy"},"sangiovanni":{dlc:"italy",region:"italy"},"daugavpils":{dlc:"baltic",region:"latvia"},"liepaja":{dlc:"baltic",region:"latvia"},"riga":{dlc:"baltic",region:"latvia"},"rezekne":{dlc:"baltic",region:"latvia"},"valmiera":{dlc:"baltic",region:"latvia"},"ventspils":{dlc:"baltic",region:"latvia"},"kaunas":{dlc:"baltic",region:"lithuania"},"klaipeda":{dlc:"baltic",region:"lithuania"},"mazeikiai":{dlc:"baltic",region:"lithuania"},"panevezys":{dlc:"baltic",region:"lithuania"},"siauliai":{dlc:"baltic",region:"lithuania"},"utena":{dlc:"baltic",region:"lithuania"},"vilnius":{dlc:"baltic",region:"lithuania"},"luxembourg":{dlc:"base",region:"luxembourg"},"amsterdam":{dlc:"base",region:"netherlands"},"groningen":{dlc:"base",region:"netherlands"},"rotterdam":{dlc:"base",region:"netherlands"},"bergen":{dlc:"north",region:"norway"},"kristiansand":{dlc:"north",region:"norway"},"oslo":{dlc:"north",region:"norway"},"stavanger":{dlc:"north",region:"norway"},"bialystok":{dlc:"east",region:"poland"},"gdansk":{dlc:"east",region:"poland"},"katowice":{dlc:"east",region:"poland"},"krakow":{dlc:"east",region:"poland"},"lublin":{dlc:"east",region:"poland"},"lodz":{dlc:"east",region:"poland"},"olsztyn":{dlc:"east",region:"poland"},"poznan":{dlc:"base",region:"poland"},"szczecin":{dlc:"base",region:"poland"},"warszawa":{dlc:"east",region:"poland"},"wroclaw":{dlc:"base",region:"poland"},"bacau":{dlc:"blacksea",region:"romania"},"brasov":{dlc:"blacksea",region:"romania"},"bucuresti":{dlc:"blacksea",region:"romania"},"cernavoda":{dlc:"blacksea",region:"romania"},"cluj_napoca":{dlc:"blacksea",region:"romania"},"constanta":{dlc:"blacksea",region:"romania"},"craiova":{dlc:"blacksea",region:"romania"},"calarasi":{dlc:"blacksea",region:"romania"},"galati":{dlc:"blacksea",region:"romania"},"hunedoara":{dlc:"blacksea",region:"romania"},"iasi":{dlc:"blacksea",region:"romania"},"mangalia":{dlc:"blacksea",region:"romania"},"pitesti":{dlc:"blacksea",region:"romania"},"resita":{dlc:"blacksea",region:"romania"},"timisoara":{dlc:"blacksea",region:"romania"},"targu_mures":{dlc:"blacksea",region:"romania"},"kaliningrad":{dlc:"baltic",region:"russia"},"luga":{dlc:"baltic",region:"russia"},"pskov":{dlc:"baltic",region:"russia"},"sosnovy_bor":{dlc:"baltic",region:"russia"},"petersburg":{dlc:"baltic",region:"russia"},"vyborg":{dlc:"baltic",region:"russia"},"bystrica":{dlc:"east",region:"slovakia"},"bratislava":{dlc:"base",region:"slovakia"},"kosice":{dlc:"east",region:"slovakia"},"goteborg":{dlc:"north",region:"sweden"},"helsingborg":{dlc:"north",region:"sweden"},"jonkoping":{dlc:"north",region:"sweden"},"kalmar":{dlc:"north",region:"sweden"},"kapellskar":{dlc:"north",region:"sweden"},"karlskrona":{dlc:"north",region:"sweden"},"linkoping":{dlc:"north",region:"sweden"},"malmo":{dlc:"north",region:"sweden"},"nynashamn":{dlc:"north",region:"sweden"},"orebro":{dlc:"north",region:"sweden"},"stockholm":{dlc:"north",region:"sweden"},"sodertalje":{dlc:"north",region:"sweden"},"trelleborg":{dlc:"north",region:"sweden"},"uppsala":{dlc:"north",region:"sweden"},"vasteraas":{dlc:"north",region:"sweden"},"vaxjo":{dlc:"north",region:"sweden"},"bern":{dlc:"base",region:"switzerland"},"geneve":{dlc:"base",region:"switzerland"},"zurich":{dlc:"base",region:"switzerland"},"edirne":{dlc:"blacksea",region:"turkey"},"istanbul":{dlc:"blacksea",region:"turkey"},"tekirdag":{dlc:"blacksea",region:"turkey"},"aberdeen":{dlc:"base",region:"uk"},"birmingham":{dlc:"base",region:"uk"},"cambridge":{dlc:"base",region:"uk"},"cardiff":{dlc:"base",region:"uk"},"carlisle":{dlc:"base",region:"uk"},"dover":{dlc:"base",region:"uk"},"edinburgh":{dlc:"base",region:"uk"},"felixstowe":{dlc:"base",region:"uk"},"glasgow":{dlc:"base",region:"uk"},"grimsby":{dlc:"base",region:"uk"},"liverpool":{dlc:"base",region:"uk"},"london":{dlc:"base",region:"uk"},"manchester":{dlc:"base",region:"uk"},"newcastle":{dlc:"base",region:"uk"},"plymouth":{dlc:"base",region:"uk"},"sheffield":{dlc:"base",region:"uk"},"southampton":{dlc:"base",region:"uk"},"swansea":{dlc:"base",region:"uk"}},
america:{"camp_verde":{dlc:"base",region:"arizona"},"clifton":{dlc:"base",region:"arizona"},"ehrenberg":{dlc:"base",region:"arizona"},"flagstaff":{dlc:"base",region:"arizona"},"g_canyon_vlg":{dlc:"base",region:"arizona"},"holbrook":{dlc:"base",region:"arizona"},"kayenta":{dlc:"base",region:"arizona"},"kingman":{dlc:"base",region:"arizona"},"nogales":{dlc:"base",region:"arizona"},"page":{dlc:"base",region:"arizona"},"phoenix":{dlc:"base",region:"arizona"},"san_simon":{dlc:"base",region:"arizona"},"show_low":{dlc:"base",region:"arizona"},"sierra_vista":{dlc:"base",region:"arizona"},"tucson":{dlc:"base",region:"arizona"},"yuma":{dlc:"base",region:"arizona"},"bakersfield":{dlc:"base",region:"california"},"barstow":{dlc:"base",region:"california"},"carlsbad":{dlc:"base",region:"california"},"el_centro":{dlc:"base",region:"california"},"eureka":{dlc:"base",region:"california"},"fresno":{dlc:"base",region:"california"},"huron":{dlc:"base",region:"california"},"los_angeles":{dlc:"base",region:"california"},"oakdale":{dlc:"base",region:"california"},"oakland":{dlc:"base",region:"california"},"oxnard":{dlc:"base",region:"california"},"redding":{dlc:"base",region:"california"},"sacramento":{dlc:"base",region:"california"},"san_diego":{dlc:"base",region:"california"},"san_francisc":{dlc:"base",region:"california"},"san_rafael":{dlc:"base",region:"california"},"santa_cruz":{dlc:"base",region:"california"},"santa_maria":{dlc:"base",region:"california"},"stockton":{dlc:"base",region:"california"},"truckee":{dlc:"base",region:"california"},"ukiah":{dlc:"base",region:"california"},"alamosa":{dlc:"colorado",region:"colorado"},"burlington":{dlc:"colorado",region:"colorado"},"colorado_spr":{dlc:"colorado",region:"colorado"},"denver":{dlc:"colorado",region:"colorado"},"durango":{dlc:"colorado",region:"colorado"},"fort_collins":{dlc:"colorado",region:"colorado"},"grand_juncti":{dlc:"colorado",region:"colorado"},"lamar":{dlc:"colorado",region:"colorado"},"montrose":{dlc:"colorado",region:"colorado"},"pueblo":{dlc:"colorado",region:"colorado"},"rangely":{dlc:"colorado",region:"colorado"},"steamboat_sp":{dlc:"colorado",region:"colorado"},"sterling":{dlc:"colorado",region:"colorado"},"boise":{dlc:"idaho",region:"idaho"},"coeur_dalene":{dlc:"idaho",region:"idaho"},"grangeville":{dlc:"idaho",region:"idaho"},"idaho_falls":{dlc:"idaho",region:"idaho"},"ketchum":{dlc:"idaho",region:"idaho"},"lewiston":{dlc:"idaho",region:"idaho"},"nampa":{dlc:"idaho",region:"idaho"},"pocatello":{dlc:"idaho",region:"idaho"},"salmon":{dlc:"idaho",region:"idaho"},"sandpoint":{dlc:"idaho",region:"idaho"},"twin_falls":{dlc:"idaho",region:"idaho"},"carson_city":{dlc:"base",region:"nevada"},"elko":{dlc:"base",region:"nevada"},"ely":{dlc:"base",region:"nevada"},"jackpot":{dlc:"base",region:"nevada"},"las_vegas":{dlc:"base",region:"nevada"},"pioche":{dlc:"base",region:"nevada"},"primm":{dlc:"base",region:"nevada"},"reno":{dlc:"base",region:"nevada"},"tonopah":{dlc:"base",region:"nevada"},"winnemucca":{dlc:"base",region:"nevada"},"alamogordo":{dlc:"new_mexico",region:"new_mexico"},"albuquerque":{dlc:"new_mexico",region:"new_mexico"},"artesia":{dlc:"new_mexico",region:"new_mexico"},"carlsbad_nm":{dlc:"new_mexico",region:"new_mexico"},"clovis":{dlc:"new_mexico",region:"new_mexico"},"farmington":{dlc:"new_mexico",region:"new_mexico"},"gallup":{dlc:"new_mexico",region:"new_mexico"},"hobbs":{dlc:"new_mexico",region:"new_mexico"},"las_cruces":{dlc:"new_mexico",region:"new_mexico"},"raton":{dlc:"new_mexico",region:"new_mexico"},"roswell":{dlc:"new_mexico",region:"new_mexico"},"santa_fe":{dlc:"new_mexico",region:"new_mexico"},"socorro":{dlc:"new_mexico",region:"new_mexico"},"tucumcari":{dlc:"new_mexico",region:"new_mexico"},"astoria":{dlc:"oregon",region:"oregon"},"bend":{dlc:"oregon",region:"oregon"},"burns":{dlc:"oregon",region:"oregon"},"coos_bay":{dlc:"oregon",region:"oregon"},"eugene":{dlc:"oregon",region:"oregon"},"klamath_f":{dlc:"oregon",region:"oregon"},"lakeview":{dlc:"oregon",region:"oregon"},"medford":{dlc:"oregon",region:"oregon"},"newport":{dlc:"oregon",region:"oregon"},"ontario":{dlc:"oregon",region:"oregon"},"pendleton":{dlc:"oregon",region:"oregon"},"portland":{dlc:"oregon",region:"oregon"},"salem":{dlc:"oregon",region:"oregon"},"the_dalles":{dlc:"oregon",region:"oregon"},"cedar_city":{dlc:"utah",region:"utah"},"logan":{dlc:"utah",region:"utah"},"moab":{dlc:"utah",region:"utah"},"ogden":{dlc:"utah",region:"utah"},"price":{dlc:"utah",region:"utah"},"provo":{dlc:"utah",region:"utah"},"salina":{dlc:"utah",region:"utah"},"salt_lake":{dlc:"utah",region:"utah"},"st_george":{dlc:"utah",region:"utah"},"vernal":{dlc:"utah",region:"utah"},"aberdeen_wa":{dlc:"washington",region:"washington"},"bellingham":{dlc:"washington",region:"washington"},"colville":{dlc:"washington",region:"washington"},"everett":{dlc:"washington",region:"washington"},"grand_coulee":{dlc:"washington",region:"washington"},"kennewick":{dlc:"washington",region:"washington"},"longview":{dlc:"washington",region:"washington"},"olympia":{dlc:"washington",region:"washington"},"omak":{dlc:"washington",region:"washington"},"port_angeles":{dlc:"washington",region:"washington"},"seattle":{dlc:"washington",region:"washington"},"spokane":{dlc:"washington",region:"washington"},"tacoma":{dlc:"washington",region:"washington"},"vancouver":{dlc:"washington",region:"washington"},"wenatchee":{dlc:"washington",region:"washington"},"yakima":{dlc:"washington",region:"washington"}}
},
cityKeys: {},
nameMap: {
dlc_eu:{'base':{title:'Base Game'},'east':{title:'Going East'},'north':{title:'Scandinavia'},'france':{title:'Vive la France!'},'italy':{title:'Italia'},'baltic':{title:'Beyond the Baltic Sea'},'blacksea':{title:'Road to the Black Sea'},'iberia':{title:'Iberia'}},
dlc_usa:{'base':{title:'Base Game'},'new_mexico':{title:'New Mexico'},'oregon':{title:'Oregon'},'utah':{title:'Utah'},'washington':{title:'Washington'},'idaho':{title:'Idaho'},'colorado':{title:'Colorado'}},
region_eu:{'austria':{title:'Austria',abbr:'AT'},'belgium':{title:'Belgium',abbr:'BE'},'bulgaria':{title:'Bulgaria',abbr:'BG'},'czech':{title:'Czech Republic',abbr:'CZ'},'denmark':{title:'Denmark',abbr:'DK'},'estonia':{title:'Estonia',abbr:'EE'},'finland':{title:'Finland',abbr:'FI'},'france':{title:'France',abbr:'FR'},'germany':{title:'Germany',abbr:'DE'},'hungary':{title:'Hungary',abbr:'HU'},'italy':{title:'Italy',abbr:'IT'},'latvia':{title:'Latvia',abbr:'LV'},'lithuania':{title:'Lithuania',abbr:'LT'},'luxembourg':{title:'Luxembourg',abbr:'LU'},'netherlands':{title:'Netherlands',abbr:'NL'},'norway':{title:'Norway',abbr:'NO'},'poland':{title:'Poland',abbr:'PL'},'romania':{title:'Romania',abbr:'RO'},'russia':{title:'Russian Federation',abbr:'RU'},'slovakia':{title:'Slovakia',abbr:'SK'},'sweden':{title:'Sweden',abbr:'SE'},'switzerland':{title:'Switzerland',abbr:'CH'},'turkey':{title:'Turkey',abbr:'TR'},'uk':{title:'United Kingdom',abbr:'GB'}},
region_usa:{'arizona':{title:'Arizona',abbr:'AZ'},'california':{title:'California',abbr:'CA'},'colorado':{title:'Colorado',abbr:'CO'},'idaho':{title:'Idaho',abbr:'ID'},'nevada':{title:'Nevada',abbr:'NV'},'new_mexico':{title:'New Mexico',abbr:'NM'},'oregon':{title:'Oregon',abbr:'OR'},'utah':{title:'Utah',abbr:'UT'},'washington':{title:'Washington',abbr:'WA'}}
},
gameData: {},
/**
* Set up buttons and progress bars
*/
init: function() {
for (var game in this.cityMap) {
this.cityKeys[game] = Object.keys(this.cityMap[game]);
}
this.topContainer = $(this.options.baseSelector);
$('body').prepend('<style>'+this.styleData+'</style>');
this.statsContainer = $('<div>', {"class": this.options.classes.statsContainer});
this.topContainer.append(this.statsContainer);
this.buttonHolder = $('<div>', {"class": this.options.classes.buttonWrap});
this.statsContainer.append(this.buttonHolder);
this.loadingMsg = $('<div>', {"class": this.options.classes.loading, "text": this.options.texts.loading});
this.statsContainer.append(this.loadingMsg);
this.advancedBtn = $('<a>', {
"class": this.options.classes.btn.advanced,
"href": '#xmas20',
"text": this.options.texts.btn.advancedHide
});
this.buttonHolder.prepend(this.advancedBtn);
this.completedBtn = $('<a>', {
"class": this.options.classes.completedBtn,
"href": '#xmas20',
"text": this.options.texts.btn.completedHide
});
this.buttonHolder.prepend(this.completedBtn);
this.expandListsBtn = $('<a>', {
"class": this.options.classes.btn.expandLists,
"href": '#xmas20',
"text": this.options.texts.btn.expandLists
});
this.buttonHolder.prepend(this.expandListsBtn);
this.heartsProgress = $('<div class="'+this.options.classes.progressBar.container+'"><div class="'+this.options.classes.progressBar.inner+'"></div></div>');
this.heartsProgressCurrent = $('<span>', {"class": this.options.classes.progressBar.current});
this.heartsProgressMax = $('<span>', {"class": this.options.classes.progressBar.max});
this.heartsProgressPercent = $('<span>', {"class": this.options.classes.progressBar.percent});
this.heartsProgress.find('div').append('Hearts: ', this.heartsProgressCurrent, ' / ', this.heartsProgressMax, ' (', this.heartsProgressPercent, '%)');
this.statsContainer.append(this.heartsProgress);
this.giftsProgress = $('<div class="'+this.options.classes.progressBar.container+'"><div class="'+this.options.classes.progressBar.inner+'"></div></div>');
this.giftsProgressCurrent = $('<span>', {"class": this.options.classes.progressBar.current});
this.giftsProgressMax = $('<span>', {"class": this.options.classes.progressBar.max});
this.giftsProgressPercent = $('<span>', {"class": this.options.classes.progressBar.percent});
this.giftsProgress.find('div').append('Gifts: ', this.giftsProgressCurrent, ' / ', this.giftsProgressMax, ' (', this.giftsProgressPercent, '%)');
this.statsContainer.append(this.giftsProgress);
var gameColumns = $(this.options.gamesSelector);
this.europeContainer = $(gameColumns[0]).addClass('europe');
this.americaContainer = $(gameColumns[1]).addClass('america');
this.europeSortWrapper = $('<span>', {"class": this.options.classes.sortButtonWrap});
this.europeSortBtnDefault = $('<a>', {
"class": this.options.classes.btn.sort,
"href": '#xmas20',
"text": this.options.texts.btn.sortDefault
});
this.europeSortBtnDefault.addClass(this.options.classes.btn.sortActive);
this.europeSortBtnHearts = $('<a>', {
"class": this.options.classes.btn.sort,
"href": '#xmas20',
"text": this.options.texts.btn.sortHearts
});
this.europeSortBtnGifts = $('<a>', {
"class": this.options.classes.btn.sort,
"href": '#xmas20',
"text": this.options.texts.btn.sortGifts
});
this.europeSortWrapper.append(
'<span>'+this.options.texts.sortBy+'</span>',
this.europeSortBtnDefault,
this.europeSortBtnHearts,
this.europeSortBtnGifts
);
this.americaSortWrapper = $('<span>', {"class": this.options.classes.sortButtonWrap});
this.americaSortBtnDefault = $('<a>', {
"class": this.options.classes.btn.sort,
"href": '#xmas20',
"text": this.options.texts.btn.sortDefault
});
this.americaSortBtnDefault.addClass(this.options.classes.btn.sortActive);
this.americaSortBtnHearts = $('<a>', {
"class": this.options.classes.btn.sort,
"href": '#xmas20',
"text": this.options.texts.btn.sortHearts
});
this.americaSortBtnGifts = $('<a>', {
"class": this.options.classes.btn.sort,
"href": '#xmas20',
"text": this.options.texts.btn.sortGifts
});
this.americaSortWrapper.append(
'<span>'+this.options.texts.sortBy+'</span>',
this.americaSortBtnDefault,
this.americaSortBtnHearts,
this.americaSortBtnGifts
);
this.europeContainer.find('.game-name').append(this.europeSortWrapper);
this.americaContainer.find('.game-name').append(this.americaSortWrapper);
this.europeProgressOut = $('<div class="'+this.options.classes.progressBar.container+'"><div class="'+this.options.classes.progressBar.inner+'"></div></div>');
this.europeProgressOutCurrent = $('<span>', {"class": this.options.classes.progressBar.current});
this.europeProgressOutMax = $('<span>', {"class": this.options.classes.progressBar.max});
this.europeProgressOutPercent = $('<span>', {"class": this.options.classes.progressBar.percent});
this.europeProgressOut.find('div').append('Hearts: ', this.europeProgressOutCurrent, ' / ', this.europeProgressOutMax, ' (', this.europeProgressOutPercent, '%)');
this.europeProgressIn = $('<div class="'+this.options.classes.progressBar.container+'"><div class="'+this.options.classes.progressBar.inner+'"></div></div>');
this.europeProgressInCurrent = $('<span>', {"class": this.options.classes.progressBar.current});
this.europeProgressInMax = $('<span>', {"class": this.options.classes.progressBar.max});
this.europeProgressInPercent = $('<span>', {"class": this.options.classes.progressBar.percent});
this.europeProgressIn.find('div').append('Gifts: ', this.europeProgressInCurrent, ' / ', this.europeProgressInMax, ' (', this.europeProgressInPercent, '%)');
this.europeContainer.find('.game-name').after(this.europeProgressOut, this.europeProgressIn);
this.americaProgressOut = $('<div class="'+this.options.classes.progressBar.container+'"><div class="'+this.options.classes.progressBar.inner+'"></div></div>');
this.americaProgressOutCurrent = $('<span>', {"class": this.options.classes.progressBar.current});
this.americaProgressOutMax = $('<span>', {"class": this.options.classes.progressBar.max});
this.americaProgressOutPercent = $('<span>', {"class": this.options.classes.progressBar.percent});
this.americaProgressOut.find('div').append('Hearts: ', this.americaProgressOutCurrent, ' / ', this.americaProgressOutMax, ' (', this.americaProgressOutPercent, '%)');
this.americaProgressIn = $('<div class="'+this.options.classes.progressBar.container+'"><div class="'+this.options.classes.progressBar.inner+'"></div></div>');
this.americaProgressInCurrent = $('<span>', {"class": this.options.classes.progressBar.current});
this.americaProgressInMax = $('<span>', {"class": this.options.classes.progressBar.max});
this.americaProgressInPercent = $('<span>', {"class": this.options.classes.progressBar.percent});
this.americaProgressIn.find('div').append('Gifts: ', this.americaProgressInCurrent, ' / ', this.americaProgressInMax, ' (', this.americaProgressInPercent, '%)');
this.americaContainer.find('.game-name').after(this.americaProgressOut, this.americaProgressIn);
this.initCityTables();
this.setupHandlers();
},
/**
* Set up sorted tables and apply modifications to default tables
*/
initCityTables: function() {
var self = this,
europeTable = this.europeContainer.find('.game-scoll table'),
americaTable = this.americaContainer.find('.game-scoll table');
this.europeCitiesSortedDefault = europeTable.find('tbody');
this.americaCitiesSortedDefault = americaTable.find('tbody');
this.europeCitiesSortedDefault.find('td.data-event-component').each(function(index, element) {
var $el = $(element),
id = $el.attr('component-id'),
id_data = self.cityMap.europe[id];
$el.find('.city').attr('title', 'Country: ' + self.nameMap.region_eu[id_data.region].title + '\nDlc: ' + self.nameMap.dlc_eu[id_data.dlc].title);
});
this.americaCitiesSortedDefault.find('td.data-event-component').each(function(index, element) {
var $el = $(element),
id = $el.attr('component-id'),
id_data = self.cityMap.america[id];
$el.find('.city').attr('title', 'State: ' + self.nameMap.region_usa[id_data.region].title + '\nDlc: ' + self.nameMap.dlc_usa[id_data.dlc].title);
});
this.europeCitiesSortedHearts = this.europeCitiesSortedDefault.clone().hide().addClass(this.options.classes.listCitiesSortedHearts).appendTo(europeTable);
this.europeCitiesSortedGifts = this.europeCitiesSortedDefault.clone().hide().addClass(this.options.classes.listCitiesSortedGifts).appendTo(europeTable);
this.americaCitiesSortedHearts = this.americaCitiesSortedDefault.clone().hide().addClass(this.options.classes.listCitiesSortedHearts).appendTo(americaTable);
this.americaCitiesSortedGifts = this.americaCitiesSortedDefault.clone().hide().addClass(this.options.classes.listCitiesSortedGifts).appendTo(americaTable);
this.europeCitiesSortedHearts.find('tr > td.group').parent().remove();
this.europeCitiesSortedGifts.find('tr > td.group').parent().remove();
this.americaCitiesSortedHearts.find('tr > td.group').parent().remove();
this.americaCitiesSortedGifts.find('tr > td.group').parent().remove();
this.europeCitiesSortedDefault.addClass(this.options.classes.listCitiesSortedDefault);
this.americaCitiesSortedDefault.addClass(this.options.classes.listCitiesSortedDefault);
},
/**
* Make new buttons clickable
*/
setupHandlers: function() {
this.advancedBtn.on('click', this.toggleStats.bind(this));
this.completedBtn.on('click', this.toggleCompleteCities.bind(this));
this.expandListsBtn.on('click', this.toggleExpandLists.bind(this));
this.europeSortBtnDefault.on('click', {game: 'europe', sort: 'default'}, this.changeSortMode.bind(this));
this.europeSortBtnHearts.on('click', {game: 'europe', sort: 'hearts'}, this.changeSortMode.bind(this));
this.europeSortBtnGifts.on('click', {game: 'europe', sort: 'gifts'}, this.changeSortMode.bind(this));
this.americaSortBtnDefault.on('click', {game: 'america', sort: 'default'}, this.changeSortMode.bind(this));
this.americaSortBtnHearts.on('click', {game: 'america', sort: 'hearts'}, this.changeSortMode.bind(this));
this.americaSortBtnGifts.on('click', {game: 'america', sort: 'gifts'}, this.changeSortMode.bind(this));
},
/**
* Parse the data and make calculations
*
* @param {Object} data - The data received from the ajax event
*/
prepareData: function(data) {
var self = this,
parsed = {'europe':{},'america':{}},
results = {};
for (var citi in data.components) {
if (
citi.substring(citi.length - '_in'.length, citi.length) !== '_in' &&
citi.substring(citi.length - '_out'.length, citi.length) !== '_out'
) {
if (self.getGameForCity(citi) === 'america') {
parsed.america[citi] = {
'gifts': data.components[citi + '_in'],
'hearts': data.components[citi + '_out']
};
} else {
parsed.europe[citi] = {
'gifts': data.components[citi + '_in'],
'hearts': data.components[citi + '_out']
};
}
}
}
results.color = data.color;
results.currentIn = 0;
results.currentOut = 0;
results.maxIn = 0;
results.maxOut = 0;
results.percentIn = 0;
results.percentOut = 0;
for (var game in parsed) {
results[game] = {};
results[game].cities = {};
results[game].currentIn = 0;
results[game].currentOut = 0;
results[game].maxIn = Object.keys(parsed[game]).length * 5;
results[game].maxOut = Object.keys(parsed[game]).length * 5;
results.maxIn += results[game].maxIn;
results.maxOut += results[game].maxOut;
for (var city in parsed[game]) {
var currentIn = parsed[game][city].gifts.graphics * 1000,
currentOut = parsed[game][city].hearts.graphics * 1000;
results[game].cities[city] = {};
results[game].currentIn += Number.parseInt(parsed[game][city].gifts.graphics, 10);
results[game].currentOut += Number.parseInt(parsed[game][city].hearts.graphics, 10);
if (currentIn < 5000) currentIn += Number.parseInt(parsed[game][city].gifts.current, 10);
if (currentOut < 5000) currentOut += Number.parseInt(parsed[game][city].hearts.current, 10);
results[game].cities[city].gifts = currentIn;
results[game].cities[city].hearts = currentOut;
}
results[game].remainsIn = results[game].maxIn - results[game].currentIn;
results[game].remainsOut = results[game].maxOut - results[game].currentOut;
results[game].percentInComplete = Number.parseFloat(((100 * results[game].currentIn) / results[game].maxIn).toFixed(2));
results[game].percentOutComplete = Number.parseFloat(((100 * results[game].currentOut) / results[game].maxOut).toFixed(2));
results[game].percentInRemain = Number.parseFloat(((100 * results[game].remainsIn) / results[game].maxIn).toFixed(2));
results[game].percentOutRemain = Number.parseFloat(((100 * results[game].remainsOut) / results[game].maxOut).toFixed(2));
results.currentIn += results[game].currentIn;
results.currentOut += results[game].currentOut;
}
results.percentIn = Number.parseFloat(((100 * results.currentIn) / results.maxIn).toFixed(2));
results.percentOut = Number.parseFloat(((100 * results.currentOut) / results.maxOut).toFixed(2));
this.gameData = results;
this.updateData();
},
/**
* Update the data being displayed
*/
updateData: function() {
var self = this;
this.heartsProgress.css("background", "linear-gradient(to right, #" + this.gameData.color + " " + this.gameData.percentOut + "%, #141a1c 0%)");
this.heartsProgressCurrent.text(this.gameData.currentOut);
this.heartsProgressMax.text(this.gameData.maxOut);
this.heartsProgressPercent.text(this.gameData.percentOut);
this.giftsProgress.css("background", "linear-gradient(to right, #" + this.gameData.color + " " + this.gameData.percentIn + "%, #141a1c 0%)");
this.giftsProgressCurrent.text(this.gameData.currentIn);
this.giftsProgressMax.text(this.gameData.maxIn);
this.giftsProgressPercent.text(this.gameData.percentIn);
this.europeProgressIn.css("background", "linear-gradient(to right, #" + this.gameData.color + " " + this.gameData.europe.percentInComplete + "%, #141a1c 0%)");
this.europeProgressInCurrent.text(this.gameData.europe.currentIn);
this.europeProgressInMax.text(this.gameData.europe.maxIn);
this.europeProgressInPercent.text(this.gameData.europe.percentInComplete);
this.europeProgressOut.css("background", "linear-gradient(to right, #" + this.gameData.color + " " + this.gameData.europe.percentOutComplete + "%, #141a1c 0%)");
this.europeProgressOutCurrent.text(this.gameData.europe.currentOut);
this.europeProgressOutMax.text(this.gameData.europe.maxOut);
this.europeProgressOutPercent.text(this.gameData.europe.percentOutComplete);
this.americaProgressIn.css("background", "linear-gradient(to right, #" + this.gameData.color + " " + this.gameData.america.percentInComplete + "%, #141a1c 0%)");
this.americaProgressInCurrent.text(this.gameData.america.currentIn);
this.americaProgressInMax.text(this.gameData.america.maxIn);
this.americaProgressInPercent.text(this.gameData.america.percentInComplete);
this.americaProgressOut.css("background", "linear-gradient(to right, #" + this.gameData.color + " " + this.gameData.america.percentOutComplete + "%, #141a1c 0%)");
this.americaProgressOutCurrent.text(this.gameData.america.currentOut);
this.americaProgressOutMax.text(this.gameData.america.maxOut);
this.americaProgressOutPercent.text(this.gameData.america.percentOutComplete);
this.europeCitiesSortedDefault
.add(this.europeCitiesSortedHearts)
.add(this.europeCitiesSortedGifts)
.add(this.americaCitiesSortedDefault)
.add(this.americaCitiesSortedHearts)
.add(this.americaCitiesSortedGifts)
.find('td.data-event-component.component-completed').each(function (index, el) {
$(el).parent().addClass('component-row-completed');
});
this.europeCitiesSortedHearts.find('td.data-event-component').each(function(index, el) {
var id;
if ((id = $(el).attr('component-id')) in self.gameData.europe.cities) {
$(el).attr('component-hearts', self.gameData.europe.cities[id].hearts);
}
});
this.europeCitiesSortedGifts.find('td.data-event-component').each(function(index, el) {
var id;
if ((id = $(el).attr('component-id')) in self.gameData.europe.cities) {
$(el).attr('component-gifts', self.gameData.europe.cities[id].gifts);
}
});
this.americaCitiesSortedHearts.find('td.data-event-component').each(function(index, el) {
var id;
if ((id = $(el).attr('component-id')) in self.gameData.america.cities) {
$(el).attr('component-hearts', self.gameData.america.cities[id].hearts);
}
});
this.americaCitiesSortedGifts.find('td.data-event-component').each(function(index, el) {
var id;
if ((id = $(el).attr('component-id')) in self.gameData.america.cities) {
$(el).attr('component-gifts', self.gameData.america.cities[id].gifts);
}
});
this.sortCities();
},
/**
* Sort cities in the sorted lists based on remaining deliveries
* (closest to completion at the top)
*/
sortCities: function() {
var i,
rows,
compare = function(sortType) {
return function(a, b) {
var valA = Number.parseInt($(a).find('td.data-event-component').attr('component-'+sortType), 10),
valB = Number.parseInt($(b).find('td.data-event-component').attr('component-'+sortType), 10);
return $.isNumeric(valA) && $.isNumeric(valB) ? valB - valA : valB.toString().localeCompare(valA);
}
};
rows = this.europeCitiesSortedHearts.find('tr').toArray().sort(compare('hearts'));
for (i = 0; i < rows.length; i++) {
this.europeCitiesSortedHearts.append(rows[i]);
}
rows = this.europeCitiesSortedGifts.find('tr').toArray().sort(compare('gifts'));
for (i = 0; i < rows.length; i++) {
this.europeCitiesSortedGifts.append(rows[i]);
}
rows = this.americaCitiesSortedHearts.find('tr').toArray().sort(compare('hearts'));
for (i = 0; i < rows.length; i++) {
this.americaCitiesSortedHearts.append(rows[i]);
}
rows = this.americaCitiesSortedGifts.find('tr').toArray().sort(compare('gifts'));
for (i = 0; i < rows.length; i++) {
this.americaCitiesSortedGifts.append(rows[i]);
}
},
/**
* Data received, show buttons and advanced stats
*/
loadingComplete: function() {
this.statsReady = true;
$('body').addClass(this.options.classes.statsReady);
this.toggleStats();
},
/**
* Determine which game city is from
*
* @param {String} city
* @return {String}
*/
getGameForCity: function (city) {
if (this.cityKeys.america.indexOf(city) !== -1) {
return "america";
}
return "europe";
},
/**
* Show or hide completed cities
*/
toggleCompleteCities: function() {
if (this.completedHidden) {
this.completedHidden = false;
$('body').removeClass(this.options.classes.completedHidden);
this.completedBtn.text(this.options.texts.btn.completedHide);
} else {
this.completedHidden = true;
$('body').addClass(this.options.classes.completedHidden);
this.completedBtn.text(this.options.texts.btn.completedShow);
}
},
/**
* Show or hide advanced stats
*/
toggleStats: function() {
if (this.statsShown) {
this.statsShown = false;
$('body').removeClass(this.options.classes.statsShown);
this.advancedBtn.text(this.options.texts.btn.advancedShow);
} else {
this.statsShown = true;
$('body').addClass(this.options.classes.statsShown);
this.advancedBtn.text(this.options.texts.btn.advancedHide);
}
},
/**
* Expand or collapse the city lists
*/
toggleExpandLists: function() {
if (this.expandLists) {
this.expandLists = false;
$('body').removeClass(this.options.classes.expandLists);
this.expandListsBtn.text(this.options.texts.btn.expandLists);
} else {
this.expandLists = true;
$('body').addClass(this.options.classes.expandLists);
this.expandListsBtn.text(this.options.texts.btn.collapseLists);
}
},
/**
* Change sorting method shown (default or by remaining)
*/
changeSortMode: function(event) {
var $btn = $(event.target),
prop = event.data.game + "SortMode",
sortUpper = event.data.sort.charAt(0).toUpperCase() + event.data.sort.slice(1),
list = event.data.game + "CitiesSorted" + sortUpper;
if (this[prop] === event.data.sort) {
return;
}
this[prop] = event.data.sort;
$btn.addClass(this.options.classes.btn.sortActive)
.siblings().removeClass(this.options.classes.btn.sortActive);
this[list].siblings().hide();
this[list].show();
}
}
var xmas20obj = new Xmas20();
/**
* Hook into main script to get data
*/
$(document).ajaxComplete(function(e, xhr){
if (xhr.responseJSON !== undefined) {
xmas20obj.prepareData(xhr.responseJSON.data.xmas20);
if(!xmas20obj.statsReady) {
xmas20obj.loadingComplete();
}
}
});
})(jQuery);
@LyraGhost

This comment has been minimized.

Copy link
Owner Author

@LyraGhost LyraGhost commented Dec 19, 2020

Features:

Advanced Stats

More progress bars to show total amount of hearts/gifts for each game, and how close they are from being completed.

City Sorting

Buttons added to both game columns to sort all the cities by:

  • City name
  • Remaining hearts needed (closest to completion on top)
  • Remaining gifts needed (closest to completion on top)

Other Options

  • Button to toggle visibility of advanced stats.
  • Button to show/hide all completed cities from both games.
  • Button to expand/collapse the size of the game city lists (makes them really long so theres no scrollbar)
  • Additional data shown when hovering over city names (DLC, Country/State)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment