2020-07-11 10:08:26 +00:00
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = ( function ( modules , cache , entry , globalName ) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof parcelRequire === 'function' && parcelRequire ;
var nodeRequire = typeof require === 'function' && require ;
function newRequire ( name , jumped ) {
if ( ! cache [ name ] ) {
if ( ! modules [ name ] ) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire = typeof parcelRequire === 'function' && parcelRequire ;
if ( ! jumped && currentRequire ) {
return currentRequire ( name , true ) ;
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if ( previousRequire ) {
return previousRequire ( name , true ) ;
}
// Try the node require function if it exists.
if ( nodeRequire && typeof name === 'string' ) {
return nodeRequire ( name ) ;
}
var err = new Error ( 'Cannot find module \'' + name + '\'' ) ;
err . code = 'MODULE_NOT_FOUND' ;
throw err ;
}
localRequire . resolve = resolve ;
localRequire . cache = { } ;
var module = cache [ name ] = new newRequire . Module ( name ) ;
modules [ name ] [ 0 ] . call ( module . exports , localRequire , module , module . exports , this ) ;
}
return cache [ name ] . exports ;
function localRequire ( x ) {
return newRequire ( localRequire . resolve ( x ) ) ;
}
function resolve ( x ) {
return modules [ name ] [ 1 ] [ x ] || x ;
}
}
function Module ( moduleName ) {
this . id = moduleName ;
this . bundle = newRequire ;
this . exports = { } ;
}
newRequire . isParcelRequire = true ;
newRequire . Module = Module ;
newRequire . modules = modules ;
newRequire . cache = cache ;
newRequire . parent = previousRequire ;
newRequire . register = function ( id , exports ) {
modules [ id ] = [ function ( require , module ) {
module . exports = exports ;
} , { } ] ;
} ;
var error ;
for ( var i = 0 ; i < entry . length ; i ++ ) {
try {
newRequire ( entry [ i ] ) ;
} catch ( e ) {
// Save first error but execute all entries
if ( ! error ) {
error = e ;
}
}
}
if ( entry . length ) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire ( entry [ entry . length - 1 ] ) ;
// CommonJS
if ( typeof exports === "object" && typeof module !== "undefined" ) {
module . exports = mainExports ;
// RequireJS
} else if ( typeof define === "function" && define . amd ) {
define ( function ( ) {
return mainExports ;
} ) ;
// <script>
} else if ( globalName ) {
this [ globalName ] = mainExports ;
}
}
// Override the current require with this new one
parcelRequire = newRequire ;
if ( error ) {
// throw error from earlier, _after updating parcelRequire_
throw error ;
}
return newRequire ;
2020-07-15 18:55:24 +00:00
} ) ( { "VYL5" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = toInteger ;
function toInteger ( dirtyNumber ) {
if ( dirtyNumber === null || dirtyNumber === true || dirtyNumber === false ) {
return NaN ;
}
var number = Number ( dirtyNumber ) ;
if ( isNaN ( number ) ) {
return number ;
}
return number < 0 ? Math . ceil ( number ) : Math . floor ( number ) ;
}
} , { } ] , "kK6Q" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = requiredArgs ;
function requiredArgs ( required , args ) {
if ( args . length < required ) {
throw new TypeError ( required + ' argument' + ( required > 1 ? 's' : '' ) + ' required, but only ' + args . length + ' present' ) ;
}
}
} , { } ] , "KYJg" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = toDate ;
var _index = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
/ * *
* @ name toDate
* @ category Common Helpers
* @ summary Convert the given argument to an instance of Date .
*
* @ description
* Convert the given argument to an instance of Date .
*
* If the argument is an instance of Date , the function returns its clone .
*
* If the argument is a number , it is treated as a timestamp .
*
* If the argument is none of the above , the function returns Invalid Date .
*
* * * Note * * : * all * Date arguments passed to any * date - fns * function is processed by ` toDate ` .
*
* @ param { Date | Number } argument - the value to convert
* @ returns { Date } the parsed date in the local time zone
* @ throws { TypeError } 1 argument required
*
* @ example
* // Clone the date:
* const result = toDate ( new Date ( 2014 , 1 , 11 , 11 , 30 , 30 ) )
* //=> Tue Feb 11 2014 11:30:30
*
* @ example
* // Convert the timestamp to date:
* const result = toDate ( 1392098430000 )
* //=> Tue Feb 11 2014 11:30:30
* /
function toDate ( argument ) {
( 0 , _index . default ) ( 1 , arguments ) ;
var argStr = Object . prototype . toString . call ( argument ) ; // Clone the date
if ( argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]' ) {
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
return new Date ( argument . getTime ( ) ) ;
} else if ( typeof argument === 'number' || argStr === '[object Number]' ) {
return new Date ( argument ) ;
} else {
if ( ( typeof argument === 'string' || argStr === '[object String]' ) && typeof console !== 'undefined' ) {
// eslint-disable-next-line no-console
console . warn ( "Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule" ) ; // eslint-disable-next-line no-console
console . warn ( new Error ( ) . stack ) ;
}
return new Date ( NaN ) ;
}
}
} , { "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "lQIY" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = addDays ;
var _index = _interopRequireDefault ( require ( "../_lib/toInteger/index.js" ) ) ;
var _index2 = _interopRequireDefault ( require ( "../toDate/index.js" ) ) ;
var _index3 = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
/ * *
* @ name addDays
* @ category Day Helpers
* @ summary Add the specified number of days to the given date .
*
* @ description
* Add the specified number of days to the given date .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } date - the date to be changed
* @ param { Number } amount - the amount of days to be added . Positive decimals will be rounded using ` Math.floor ` , decimals less than zero will be rounded using ` Math.ceil ` .
* @ returns { Date } the new date with the days added
* @ throws { TypeError } 2 arguments required
*
* @ example
* // Add 10 days to 1 September 2014:
* var result = addDays ( new Date ( 2014 , 8 , 1 ) , 10 )
* //=> Thu Sep 11 2014 00:00:00
* /
function addDays ( dirtyDate , dirtyAmount ) {
( 0 , _index3 . default ) ( 2 , arguments ) ;
var date = ( 0 , _index2 . default ) ( dirtyDate ) ;
var amount = ( 0 , _index . default ) ( dirtyAmount ) ;
if ( isNaN ( amount ) ) {
return new Date ( NaN ) ;
}
if ( ! amount ) {
// If 0 days, no-op to avoid changing times in the hour before end of DST
return date ;
}
date . setDate ( date . getDate ( ) + amount ) ;
return date ;
}
} , { "../_lib/toInteger/index.js" : "VYL5" , "../toDate/index.js" : "KYJg" , "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "mRRL" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = subDays ;
var _index = _interopRequireDefault ( require ( "../_lib/toInteger/index.js" ) ) ;
var _index2 = _interopRequireDefault ( require ( "../addDays/index.js" ) ) ;
var _index3 = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
/ * *
* @ name subDays
* @ category Day Helpers
* @ summary Subtract the specified number of days from the given date .
*
* @ description
* Subtract the specified number of days from the given date .
*
* # # # v2 . 0.0 breaking changes :
*
* - [ Changes that are common for the whole library ] ( https : //github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @ param { Date | Number } date - the date to be changed
* @ param { Number } amount - the amount of days to be subtracted . Positive decimals will be rounded using ` Math.floor ` , decimals less than zero will be rounded using ` Math.ceil ` .
* @ returns { Date } the new date with the days subtracted
* @ throws { TypeError } 2 arguments required
*
* @ example
* // Subtract 10 days from 1 September 2014:
* var result = subDays ( new Date ( 2014 , 8 , 1 ) , 10 )
* //=> Fri Aug 22 2014 00:00:00
* /
function subDays ( dirtyDate , dirtyAmount ) {
( 0 , _index3 . default ) ( 2 , arguments ) ;
var amount = ( 0 , _index . default ) ( dirtyAmount ) ;
return ( 0 , _index2 . default ) ( dirtyDate , - amount ) ;
}
} , { "../_lib/toInteger/index.js" : "VYL5" , "../addDays/index.js" : "lQIY" , "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "Ph2E" : [ function ( require , module , exports ) {
2020-07-11 12:08:43 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = exports . API _URI = void 0 ;
const API _URI = 'https://api.tribalwarshelp.com/graphql' ;
exports . API _URI = API _URI ;
var _default = function _default ( ) {
let {
query ,
variables = { }
} = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
return fetch ( 'https://api.tribalwarshelp.com/graphql' , {
method : 'POST' ,
body : JSON . stringify ( {
query ,
variables
} ) ,
headers : {
'Content-Type' : 'application/json'
}
} ) . then ( res => {
return res . json ( ) ;
} ) . then ( ( _ref ) => {
let {
data ,
errors
} = _ref ;
if ( errors && Array . isArray ( errors ) && errors . length > 0 ) {
throw new Error ( errors [ 0 ] . message ) ;
}
return new Promise ( resolve => resolve ( data ) ) ;
} ) ;
} ;
exports . default = _default ;
2020-07-17 12:16:07 +00:00
} , { } ] , "yQib" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _default = v => v === undefined || v === null ;
exports . default = _default ;
} , { } ] , "dPMc" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _isNil = _interopRequireDefault ( require ( "./isNil" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
const getTodaysStatsTdStyle = value => {
const statIncreaseStyle = 'color: #000; background-color: #0f0' ;
const statDecreaseStyle = 'color: #000; background-color: #f00' ;
const defaultStyle = 'color: #000; background-color: #808080' ;
return value > 0 ? statIncreaseStyle : value < 0 ? statDecreaseStyle : defaultStyle ;
} ;
var _default = ( container , stats ) => {
let todaysStats = container . querySelector ( '#todaysStats' ) ;
if ( ! todaysStats ) {
todaysStats = document . createElement ( 'div' ) ;
todaysStats . id = 'todaysStats' ;
todaysStats . width = '100%' ;
container . prepend ( todaysStats ) ;
}
const renderODS = ! ( 0 , _isNil . default ) ( stats . rankSup ) ;
2020-07-17 13:10:56 +00:00
todaysStats . innerHTML = "\n <table width=\"100%\" class=\"vis\">\n <tbody>\n <tr>\n <th colspan=\"2\">\n Today's stat changes\n </th>\n </tr>\n <tr>\n <td>\n Points:\n </td>\n <td style=\"" . concat ( getTodaysStatsTdStyle ( stats . points ) , "\">\n " ) . concat ( Math . abs ( stats . points ) . toLocaleString ( ) , "\n </td>\n </tr>\n <tr>\n <td>\n Rank:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . rank ) , "\">\n " ) . concat ( Math . abs ( stats . rank ) , "\n </td>\n </tr>\n <tr>\n <td>\n Villages:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . villages ) , "\">\n " ) . concat ( Math . abs ( stats . villages ) . toLocaleString ( ) , "\n </td>\n </tr>\n <tr>\n <td>\n ODA:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . scoreAtt ) , "\">\n " ) . concat ( Math . abs ( stats . scoreAtt ) . toLocaleString ( ) , "\n </td>\n </tr>\n <tr>\n <td>\n ODA Rank:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . rankAtt ) , "\">\n " ) . concat ( Math . abs ( stats . rankAtt ) , "\n </td>\n </tr>\n <tr>\n <td>\n ODD:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . scoreDef ) , "\">\n " ) . concat ( Math . abs ( stats . scoreDef ) . toLocaleString ( ) , "\n </td>\n </tr>\n <tr>\n <td>\n ODD Rank:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . rankDef ) , "\">\n " ) . concat ( Math . abs ( stats . rankDef ) , "\n </td>\n </tr>\n " ) . concat ( renderODS ? "<tr>\n <td>\n ODS:\n </td>\n <td style=\"" . concat ( getTodaysStatsTdStyle ( stats . scoreSup ) , "\">\n " ) . concat ( Math . abs ( stats . scoreSup ) . toLocaleString ( ) , "\n </td>\n </tr>\n <tr>\n <td>\n ODS Rank:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . rankSup ) , "\">\n " ) . concat ( Math . abs ( stats . rankSup ) , "\n </td>\n </tr>" ) : '' , "\n <tr>\n <td>\n OD:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . scoreTotal ) , "\">\n " ) . concat ( Math . abs ( stats . scoreTotal ) . toLocaleString ( ) , "\n </td>\n </tr>\n <tr>\n <td>\n OD Rank:\n </td>\n <td style=\"" ) . concat ( getTodaysStatsTdStyle ( stats . rankTotal ) , "\">\n " ) . concat ( Math . abs ( stats . rankTotal ) , "\n </td>\n </tr>\n </tbody>\n </table>\n " ) ;
2020-07-17 12:16:07 +00:00
} ;
exports . default = _default ;
2020-07-17 13:43:28 +00:00
} , { "./isNil" : "yQib" } ] , "P4rL" : [ function ( require , module , exports ) {
2020-07-15 18:55:24 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2020-07-17 13:43:28 +00:00
exports . default = void 0 ;
const POPUP _WRAPPER _SELECTOR = '.popup_helper' ;
const POPUP _SELECTOR = '#inline_popup' ;
var _default = function _default ( ) {
let {
e ,
title ,
html ,
id
} = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
inlinePopup ( e , id , null , {
offset _x : 0 ,
offset _y : 0
} , html , title ) ;
const popup = document . querySelector ( POPUP _SELECTOR ) ;
if ( popup ) {
popup . style . width = 'auto' ;
popup . style . maxWidth = '800px' ;
}
const popupWrapper = document . querySelector ( POPUP _WRAPPER _SELECTOR ) ;
if ( popupWrapper ) {
popupWrapper . style . width = 'auto' ;
popupWrapper . style . position = 'fixed' ;
popupWrapper . style . zIndex = '50001' ;
}
} ;
exports . default = _default ;
} , { } ] , "fCHX" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . generatePaginationItems = exports . calcNumberOfPages = exports . getPage = exports . setPage = exports . getContainerStyles = void 0 ;
2020-07-15 18:55:24 +00:00
const ATTRIBUTE = 'data-page' ;
2020-07-17 13:43:28 +00:00
const getContainerStyles = ( ) => {
return 'display: flex; flex-direction: row; flex-wrap: wrap;' ;
} ;
exports . getContainerStyles = getContainerStyles ;
2020-07-15 18:55:24 +00:00
const setPage = function setPage ( el ) {
let page = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 1 ;
if ( ! el instanceof HTMLElement ) {
throw new Error ( 'Expected HTMLElement as the first argument' ) ;
}
page = parseInt ( page ) ;
if ( typeof page !== 'number' || isNaN ( page ) ) {
throw new Error ( 'Expected number or string as the second argument' ) ;
}
el . setAttribute ( ATTRIBUTE , page + '' ) ;
} ;
exports . setPage = setPage ;
const getPage = el => {
if ( ! el instanceof HTMLElement ) {
return 0 ;
}
return parseInt ( el . getAttribute ( ATTRIBUTE ) ) ;
} ;
exports . getPage = getPage ;
const calcNumberOfPages = ( total , limit ) => {
if ( typeof total !== 'number' ) {
throw new Error ( 'Expected number as the first argument' ) ;
}
if ( typeof limit !== 'number' ) {
throw new Error ( 'Expected number as the second argument' ) ;
}
return total > 0 ? Math . ceil ( total / limit ) : 1 ;
} ;
exports . calcNumberOfPages = calcNumberOfPages ;
const generatePaginationItems = function generatePaginationItems ( ) {
let {
total ,
limit ,
marginRight = 3 ,
currentPage = 0
} = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
const numberOfPages = calcNumberOfPages ( total , limit ) ;
const paginationItems = [ ] ;
for ( let i = 1 ; i <= numberOfPages ; i ++ ) {
if ( i === currentPage ) {
paginationItems . push ( "<strong style=\"margin-right: " . concat ( marginRight , "px\">>" ) . concat ( i , "<</strong>" ) ) ;
} else {
paginationItems . push ( "<a style=\"margin-right: " . concat ( marginRight , "px\" href=\"#\" " ) . concat ( ATTRIBUTE , "=\"" ) . concat ( i , "\">" ) . concat ( i , "</a>" ) ) ;
}
}
return paginationItems ;
} ;
exports . generatePaginationItems = generatePaginationItems ;
2020-07-11 12:08:43 +00:00
} , { } ] , "V6Mf" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
2020-07-11 13:14:29 +00:00
var _default = ( date , options ) => {
return new Date ( date ) . toLocaleDateString ( window . game _data . locale . replace ( '_' , '-' ) , options ? options : {
2020-07-11 12:08:43 +00:00
year : 'numeric' ,
2020-07-12 15:56:03 +00:00
month : '2-digit' ,
day : '2-digit' ,
hour : '2-digit' ,
minute : '2-digit' ,
second : '2-digit'
2020-07-11 13:14:29 +00:00
} ) ;
2020-07-11 12:08:43 +00:00
} ;
2020-07-11 18:44:52 +00:00
exports . default = _default ;
2020-07-17 13:43:28 +00:00
} , { } ] , "tQUs" : [ function ( require , module , exports ) {
2020-07-11 18:44:52 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
2020-07-17 13:43:28 +00:00
var _default = url => parseInt ( new URLSearchParams ( url ) . get ( 'id' ) ) ;
2020-07-11 18:44:52 +00:00
2020-07-11 12:08:43 +00:00
exports . default = _default ;
2020-07-12 16:17:25 +00:00
} , { } ] , "dSAr" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _getIDFromURL = _interopRequireDefault ( require ( "../utils/getIDFromURL" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
class InADayParser {
constructor ( html ) {
let filters = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
this . dom = new DOMParser ( ) . parseFromString ( html , 'text/html' ) ;
this . filters = filters ;
}
isValidRow ( row ) {
if ( ! row ) {
return false ;
}
if ( this . filters . playerID && row . playerID !== this . filters . playerID ) {
return false ;
}
return true ;
}
parseRow ( row ) {
if ( ! row || ! row instanceof HTMLTableRowElement ) {
return undefined ;
}
let obj = { } ;
obj . rank = parseInt ( row . children [ 0 ] . innerText . trim ( ) ) ;
obj . name = row . children [ 1 ] . innerText . trim ( ) ;
obj . playerID = ( 0 , _getIDFromURL . default ) ( row . children [ 1 ] . querySelector ( 'a' ) . getAttribute ( 'href' ) ) ;
obj . tribe = row . children [ 2 ] . innerText . trim ( ) ;
obj . tribeID = 0 ;
if ( obj . tribe ) {
obj . tribeID = ( 0 , _getIDFromURL . default ) ( row . children [ 2 ] . querySelector ( 'a' ) . getAttribute ( 'href' ) ) ;
}
obj . score = parseInt ( row . children [ 3 ] . innerText . trim ( ) . replace ( /\./g , '' ) ) ;
obj . date = row . children [ 4 ] . innerText . trim ( ) ;
return obj ;
}
parse ( ) {
const trs = this . dom . querySelectorAll ( '#in_a_day_ranking_table tbody tr' ) ;
const result = [ ] ;
for ( let i = 1 ; i < trs . length ; i ++ ) {
const row = trs [ i ] ;
const parsed = this . parseRow ( row ) ;
if ( this . isValidRow ( parsed ) ) {
result . push ( parsed ) ;
}
}
return result ;
}
}
exports . default = InADayParser ;
} , { "../utils/getIDFromURL" : "tQUs" } ] , "fHHP" : [ function ( require , module , exports ) {
2020-07-11 18:44:52 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2020-07-17 10:58:08 +00:00
exports . loadInADayData = exports . formatVillageName = exports . formatVillageURL = exports . formatPlayerURL = exports . formatTribeURL = void 0 ;
2020-07-12 16:17:25 +00:00
var _InADayParser = _interopRequireDefault ( require ( "../libs/InADayParser" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
function _objectWithoutProperties ( source , excluded ) { if ( source == null ) return { } ; var target = _objectWithoutPropertiesLoose ( source , excluded ) ; var key , i ; if ( Object . getOwnPropertySymbols ) { var sourceSymbolKeys = Object . getOwnPropertySymbols ( source ) ; for ( i = 0 ; i < sourceSymbolKeys . length ; i ++ ) { key = sourceSymbolKeys [ i ] ; if ( excluded . indexOf ( key ) >= 0 ) continue ; if ( ! Object . prototype . propertyIsEnumerable . call ( source , key ) ) continue ; target [ key ] = source [ key ] ; } } return target ; }
function _objectWithoutPropertiesLoose ( source , excluded ) { if ( source == null ) return { } ; var target = { } ; var sourceKeys = Object . keys ( source ) ; var key , i ; for ( i = 0 ; i < sourceKeys . length ; i ++ ) { key = sourceKeys [ i ] ; if ( excluded . indexOf ( key ) >= 0 ) continue ; target [ key ] = source [ key ] ; } return target ; }
2020-07-11 18:44:52 +00:00
const formatTribeURL = id => {
return window . location . origin + TribalWars . buildURL ( '' , {
screen : 'info_ally' ,
id
} ) ;
} ;
exports . formatTribeURL = formatTribeURL ;
const formatPlayerURL = id => {
return window . location . origin + TribalWars . buildURL ( '' , {
screen : 'info_player' ,
id
} ) ;
} ;
exports . formatPlayerURL = formatPlayerURL ;
const formatVillageURL = id => {
return window . location . origin + TribalWars . buildURL ( '' , {
screen : 'info_village' ,
id
} ) ;
} ;
exports . formatVillageURL = formatVillageURL ;
2020-07-12 16:17:25 +00:00
2020-07-17 10:58:08 +00:00
const formatVillageName = function formatVillageName ( ) {
let n = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '' ;
let x = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 500 ;
let y = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 500 ;
const continent = 'K' + String ( y ) [ 0 ] + String ( x ) [ 0 ] ;
return "" . concat ( n , " (" ) . concat ( x , "|" ) . concat ( y , ") " ) . concat ( continent ) ;
} ;
exports . formatVillageName = formatVillageName ;
2020-07-12 16:17:25 +00:00
const loadInADayData = async function loadInADayData ( type ) {
let _ref = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ,
{
name
} = _ref ,
rest = _objectWithoutProperties ( _ref , [ "name" ] ) ;
try {
const response = await fetch ( TribalWars . buildURL ( '' , {
screen : 'ranking' ,
mode : 'in_a_day' ,
type ,
name : name ? name : ''
} ) ) ;
const html = await response . text ( ) ;
if ( ! html ) {
throw new Error ( ) ;
}
const res = new _InADayParser . default ( html , rest ) . parse ( ) ;
if ( res . length === 0 ) {
throw new Error ( ) ;
}
return res [ 0 ] ;
} catch ( error ) {
return {
rank : 0 ,
playerID : 0 ,
score : 0 ,
tribeID : 0 ,
date : new Date ( )
} ;
}
} ;
exports . loadInADayData = loadInADayData ;
2020-07-17 13:43:28 +00:00
} , { "../libs/InADayParser" : "dSAr" } ] , "vhoq" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _pagination = require ( "./pagination" ) ;
var _renderPopup = _interopRequireDefault ( require ( "./renderPopup" ) ) ;
var _formatDate = _interopRequireDefault ( require ( "./formatDate" ) ) ;
var _tribalwars = require ( "./tribalwars" ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
const ENNOBLEMENTS _PAGINATION _CONTAINER _ID = 'ennoblementsPagination' ;
const getPlayerTd = ( player , tribe ) => {
if ( player ) {
return "<td><a href=\"" . concat ( ( 0 , _tribalwars . formatPlayerURL ) ( player . id ) , "\">" ) . concat ( player . name , " (" ) . concat ( tribe ? "<a href=\"" . concat ( ( 0 , _tribalwars . formatTribeURL ) ( tribe . id ) , "\">" ) . concat ( tribe . tag , "</a>" ) : '-' , ")</a></td>" ) ;
}
return '<td>-</td>' ;
} ;
var _default = function _default ( e , ennoblements ) {
let {
limit = 0 ,
currentPage = 1 ,
onPageChange = ( ) => { }
} = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
const paginationItems = ( 0 , _pagination . generatePaginationItems ) ( {
total : ennoblements . total ,
limit ,
currentPage
} ) ;
const html = "\n <div style=\"" . concat ( ( 0 , _pagination . getContainerStyles ) ( ) , "\" id=\"" ) . concat ( ENNOBLEMENTS _PAGINATION _CONTAINER _ID , "\">\n " ) . concat ( paginationItems . join ( '' ) , "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Village\n </th>\n <th>\n New Owner\n </th>\n <th>\n Old Owner\n </th>\n </tr>\n " ) . concat ( ennoblements . items . map ( ennoblement => {
let rowHTML = '<tr>' + "<td>" . concat ( ( 0 , _formatDate . default ) ( ennoblement . ennobledAt ) , "</td>" ) ;
if ( ennoblement . village ) {
rowHTML += "<td><a href=\"" . concat ( ( 0 , _tribalwars . formatVillageURL ) ( ennoblement . village . id ) , "\">" ) . concat ( ( 0 , _tribalwars . formatVillageName ) ( ennoblement . village . name , ennoblement . village . x , ennoblement . village . y ) , "</a></td>" ) ;
} else {
rowHTML += '<td>-</td>' ;
}
rowHTML += getPlayerTd ( ennoblement . newOwner , ennoblement . newOwnerTribe ) ;
rowHTML += getPlayerTd ( ennoblement . oldOwner , ennoblement . oldOwnerTribe ) ;
return rowHTML + '</tr>' ;
} ) . join ( '' ) , "\n </tbody>\n </table>\n " ) ;
( 0 , _renderPopup . default ) ( {
e ,
title : "Ennoblements" ,
id : 'ennoblements' ,
html
} ) ;
document . querySelectorAll ( '#' + ENNOBLEMENTS _PAGINATION _CONTAINER _ID + ' a' ) . forEach ( el => {
el . addEventListener ( 'click' , onPageChange ) ;
} ) ;
} ;
exports . default = _default ;
} , { "./pagination" : "fCHX" , "./renderPopup" : "P4rL" , "./formatDate" : "V6Mf" , "./tribalwars" : "fHHP" } ] , "DMkL" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _default = ( ) => window . location . host . split ( '.' ) [ 0 ] ;
exports . default = _default ;
} , { } ] , "Syko" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . formatPlayerURL = void 0 ;
const formatPlayerURL = function formatPlayerURL ( ) {
let server = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '' ;
let id = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 0 ;
return "http://www.twstats.com/in/" . concat ( server , "/player/" ) . concat ( id ) ;
} ;
exports . formatPlayerURL = formatPlayerURL ;
} , { } ] , "KWxH" : [ function ( require , module , exports ) {
2020-07-11 12:08:43 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . setItem = exports . getItem = void 0 ;
const getItem = key => {
const json = localStorage . getItem ( key ) ;
let obj = { } ;
if ( json ) {
obj = JSON . parse ( json ) ;
}
return obj ;
} ;
exports . getItem = getItem ;
const setItem = ( key , payload ) => {
localStorage . setItem ( key , JSON . stringify ( payload ) ) ;
} ;
exports . setItem = setItem ;
} , { } ] , "yRop" : [ function ( require , module , exports ) {
"use strict" ;
2020-07-15 18:55:24 +00:00
var _subDays = _interopRequireDefault ( require ( "date-fns/subDays" ) ) ;
2020-07-11 12:08:43 +00:00
var _requestCreator = _interopRequireDefault ( require ( "./libs/requestCreator" ) ) ;
2020-07-17 12:16:07 +00:00
var _renderTodaysStats = _interopRequireDefault ( require ( "./utils/renderTodaysStats" ) ) ;
2020-07-17 13:43:28 +00:00
var _renderPopup = _interopRequireDefault ( require ( "./utils/renderPopup" ) ) ;
var _renderEnnoblements = _interopRequireDefault ( require ( "./utils/renderEnnoblements" ) ) ;
2020-07-16 12:00:18 +00:00
var _pagination = require ( "./utils/pagination" ) ;
2020-07-15 18:55:24 +00:00
2020-07-11 12:08:43 +00:00
var _getIDFromURL = _interopRequireDefault ( require ( "./utils/getIDFromURL" ) ) ;
var _getCurrentServer = _interopRequireDefault ( require ( "./utils/getCurrentServer" ) ) ;
var _formatDate = _interopRequireDefault ( require ( "./utils/formatDate" ) ) ;
2020-07-11 13:14:29 +00:00
var _twstats = require ( "./utils/twstats" ) ;
2020-07-11 18:44:52 +00:00
var _tribalwars = require ( "./utils/tribalwars" ) ;
2020-07-11 12:08:43 +00:00
var _localStorage = require ( "./utils/localStorage" ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2020-07-15 18:55:24 +00:00
function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; if ( enumerableOnly ) symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ; keys . push . apply ( keys , symbols ) ; } return keys ; }
function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; if ( i % 2 ) { ownKeys ( Object ( source ) , true ) . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } else if ( Object . getOwnPropertyDescriptors ) { Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ; } else { ownKeys ( Object ( source ) ) . forEach ( function ( key ) { Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ; } ) ; } } return target ; }
function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
2020-07-11 10:08:26 +00:00
// ==UserScript==
// @name Extended Player Profile
2020-07-12 18:29:59 +00:00
// @namespace https://github.com/tribalwarshelp/scripts
2020-07-12 17:29:58 +00:00
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
2020-07-17 13:43:28 +00:00
// @version 1
2020-07-11 10:08:26 +00:00
// @description Extended Player Profile
// @author Kichiyaki http://dawid-wysokinski.pl/
2020-07-16 17:49:01 +00:00
// @match *://*/game.php*&screen=info_player*
2020-07-11 10:08:26 +00:00
// @grant none
2020-07-12 17:29:58 +00:00
// @run-at document-end
2020-07-11 10:08:26 +00:00
// ==/UserScript==
2020-07-11 12:08:43 +00:00
const SERVER = ( 0 , _getCurrentServer . default ) ( ) ;
let PLAYER _ID = ( 0 , _getIDFromURL . default ) ( window . location . search ) ;
2020-07-11 13:14:29 +00:00
const CURRENT _PLAYER _ID = parseInt ( game _data . player . id ) ;
2020-07-11 12:08:43 +00:00
if ( isNaN ( PLAYER _ID ) || ! PLAYER _ID ) {
2020-07-11 13:14:29 +00:00
PLAYER _ID = CURRENT _PLAYER _ID ;
2020-07-11 12:08:43 +00:00
}
2020-07-11 10:08:26 +00:00
const LOCAL _STORAGE _KEY = 'kichiyaki_extended_player_profile' + PLAYER _ID ;
2020-07-12 10:01:43 +00:00
const PLAYER _QUERY = "\n query pageData($server: String!, $id: Int!, $filter: DailyPlayerStatsFilter) {\n player(server: $server, id: $id) {\n id\n name\n bestRank\n bestRankAt\n mostPoints\n mostPointsAt\n mostVillages\n mostVillagesAt\n servers\n joinedAt\n nameChanges {\n oldName\n newName\n changeDate\n }\n dailyGrowth\n }\n dailyPlayerStats(server: $server, filter: $filter) {\n items {\n rank\n rankAtt\n rankDef\n rankSup\n rankTotal\n points\n scoreAtt\n scoreAtt\n scoreDef\n scoreSup\n scoreTotal\n villages\n }\n }\n }\n" ;
2020-07-11 18:44:52 +00:00
const TRIBE _CHANGES _QUERY = "\n query tribeChanges($server: String!, $filter: TribeChangeFilter!) {\n tribeChanges(server: $server, filter: $filter) {\n total\n items {\n oldTribe {\n id\n tag\n }\n newTribe {\n id\n tag\n }\n createdAt\n }\n }\n }\n" ;
const TRIBE _CHANGES _PAGINATION _CONTAINER _ID = 'tribeChangesPagination' ;
const TRIBE _CHANGES _PER _PAGE = 15 ;
2020-07-15 18:55:24 +00:00
const PLAYER _HISTORY _AND _PLAYER _DAILY _STATS _QUERY = "\nquery playerHistoryAndPlayerDailyStats($server: String!,\n $playerHistoryFilter: PlayerHistoryFilter!,\n $dailyPlayerStatsFilter: DailyPlayerStatsFilter!) {\n playerHistory(server: $server, filter: $playerHistoryFilter) {\n total\n items {\n totalVillages\n points\n rank\n scoreAtt\n rankAtt\n scoreDef\n rankDef\n scoreSup\n rankSup\n scoreTotal\n rankTotal\n tribe {\n id\n tag\n }\n createDate\n }\n }\n dailyPlayerStats(server: $server, filter: $dailyPlayerStatsFilter) {\n items {\n points\n scoreAtt\n scoreAtt\n scoreDef\n scoreSup\n scoreTotal\n villages\n createDate\n }\n }\n}\n" ;
const PLAYER _HISTORY _PAGINATION _CONTAINER _ID = 'playerHistoryPagination' ;
const PLAYER _HISTORY _PER _PAGE = 15 ;
2020-07-17 10:58:08 +00:00
const ENNOBLEMENTS _QUERY = "\n query ennoblements($server: String!, $filter: EnnoblementFilter!) {\n ennoblements(server: $server, filter: $filter) {\n total\n items {\n village {\n id\n name\n x\n y\n }\n oldOwner {\n id\n name\n }\n oldOwnerTribe {\n id\n tag\n }\n newOwner {\n id\n name\n }\n newOwnerTribe {\n id\n tag\n }\n ennobledAt\n }\n }\n }\n" ;
const ENNOBLEMENTS _PER _PAGE = 15 ;
2020-07-11 13:14:29 +00:00
const profileInfoTBody = document . querySelector ( '#player_info > tbody' ) ;
2020-07-11 18:44:52 +00:00
const actionsContainer = PLAYER _ID === CURRENT _PLAYER _ID ? profileInfoTBody : document . querySelector ( '#content_value > table > tbody > tr > td:nth-child(1) > table:nth-child(2) > tbody' ) ;
2020-07-11 13:14:29 +00:00
const otherElementsContainer = document . querySelector ( PLAYER _ID === CURRENT _PLAYER _ID ? '#content_value > table:nth-child(7) > tbody > tr > td:nth-child(2)' : '#content_value > table > tbody > tr > td:nth-child(2)' ) ;
2020-07-11 12:08:43 +00:00
2020-07-11 14:25:10 +00:00
const loadDataFromCache = ( ) => {
2020-07-11 12:08:43 +00:00
return ( 0 , _localStorage . getItem ) ( LOCAL _STORAGE _KEY ) ;
} ;
const cachePlayerData = function cachePlayerData ( ) {
let data = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
( 0 , _localStorage . setItem ) ( LOCAL _STORAGE _KEY , data ) ;
} ;
2020-07-11 14:25:10 +00:00
const loadData = async ( ) => {
2020-07-11 12:08:43 +00:00
const data = await ( 0 , _requestCreator . default ) ( {
2020-07-11 18:44:52 +00:00
query : PLAYER _QUERY ,
2020-07-11 12:08:43 +00:00
variables : {
server : SERVER ,
2020-07-11 14:25:10 +00:00
id : PLAYER _ID ,
filter : {
sort : 'createDate DESC' ,
limit : 1 ,
playerID : [ PLAYER _ID ]
}
2020-07-11 12:08:43 +00:00
}
} ) ;
if ( data . player ) {
const inADay = { } ;
2020-07-12 16:17:25 +00:00
inADay . att = await ( 0 , _tribalwars . loadInADayData ) ( 'kill_att' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
inADay . def = await ( 0 , _tribalwars . loadInADayData ) ( 'kill_def' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
inADay . sup = await ( 0 , _tribalwars . loadInADayData ) ( 'kill_sup' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
inADay . lootRes = await ( 0 , _tribalwars . loadInADayData ) ( 'loot_res' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
inADay . lootVil = await ( 0 , _tribalwars . loadInADayData ) ( 'loot_vil' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
inADay . scavenge = await ( 0 , _tribalwars . loadInADayData ) ( 'scavenge' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
inADay . conquer = await ( 0 , _tribalwars . loadInADayData ) ( 'conquer' , {
name : data . player . name ,
playerID : data . player . id
} ) ;
2020-07-11 12:08:43 +00:00
data . player . inADay = inADay ;
}
cachePlayerData ( data ) ;
return data ;
} ;
const renderTr = ( _ref ) => {
let {
title ,
data ,
id
} = _ref ;
let tr = document . querySelector ( '#' + id ) ;
if ( ! tr ) {
tr = document . createElement ( 'tr' ) ;
tr . id = id ;
tr . appendChild ( document . createElement ( 'td' ) ) ;
tr . appendChild ( document . createElement ( 'td' ) ) ;
2020-07-11 13:14:29 +00:00
profileInfoTBody . append ( tr ) ;
2020-07-11 12:08:43 +00:00
}
tr . children [ 0 ] . innerHTML = title ;
tr . children [ 1 ] . innerHTML = data ;
} ;
2020-07-11 13:14:29 +00:00
const renderPlayerServers = player => {
let playerServers = document . querySelector ( '#playerServers' ) ;
if ( ! playerServers ) {
playerServers = document . createElement ( 'table' ) ;
playerServers . id = 'playerServers' ;
playerServers . classList . add ( 'vis' ) ;
playerServers . width = '100%' ;
2020-07-12 10:25:39 +00:00
playerServers . innerHTML = "\n <tbody>\n <tr>\n <th>\n Player's servers\n </th>\n </tr>\n <tr>\n <td>\n </td>\n </tr>\n </tbody>\n " ;
2020-07-11 13:14:29 +00:00
otherElementsContainer . prepend ( playerServers ) ;
}
2020-07-11 14:25:10 +00:00
playerServers . querySelector ( 'td' ) . innerHTML = player . servers . sort ( ) . map ( server => "<a style=\"margin-right: 5px\" href=\"" . concat ( ( 0 , _twstats . formatPlayerURL ) ( server , player . id ) , "\">" ) . concat ( server , "</a>" ) ) . join ( '' ) ;
2020-07-11 13:14:29 +00:00
} ;
const renderPlayerOtherNames = player => {
let playerOtherNames = document . querySelector ( '#playerOtherNames' ) ;
if ( ! playerOtherNames ) {
playerOtherNames = document . createElement ( 'div' ) ;
playerOtherNames . id = 'playerOtherNames' ;
playerOtherNames . width = '100%' ;
otherElementsContainer . prepend ( playerOtherNames ) ;
}
playerOtherNames . innerHTML = "\n <table width=\"100%\" class=\"vis\">\n <tbody>\n <tr>\n <th>\n Old name\n </th>\n <th>\n New name\n </th>\n <th>\n Date\n </th>\n </tr>\n " . concat ( player . nameChanges . map ( nameChange => {
return "\n <tr>\n <td>\n " . concat ( nameChange . oldName , "\n </td>\n <td>\n " ) . concat ( nameChange . newName , "\n </td>\n <td>\n " ) . concat ( ( 0 , _formatDate . default ) ( nameChange . changeDate , {
year : 'numeric' ,
2020-07-12 15:56:03 +00:00
month : '2-digit' ,
day : '2-digit'
2020-07-11 13:14:29 +00:00
} ) , "\n </td>\n </tr>\n " ) ;
} ) . join ( '' ) , "\n </tbody>\n </table>\n " ) ;
} ;
2020-07-11 15:57:05 +00:00
const renderInADayRanks = player => {
let inADayRanks = document . querySelector ( '#inADayRanks' ) ;
if ( ! inADayRanks ) {
inADayRanks = document . createElement ( 'div' ) ;
inADayRanks . id = 'inADayRanks' ;
inADayRanks . width = '100%' ;
otherElementsContainer . prepend ( inADayRanks ) ;
}
inADayRanks . innerHTML = "\n <table width=\"100%\" class=\"vis\">\n <tbody>\n <tr>\n <th colspan=\"2\">\n 'In a day' best scores\n </th>\n </tr>\n <tr>\n <td>\n Units defeated while attacking:\n </td>\n <td>\n " . concat ( player . inADay . att . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . att . rank , ".)\n </td>\n </tr>\n <tr>\n <td>\n Units defeated while defending:\n </td>\n <td>\n " ) . concat ( player . inADay . def . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . def . rank , ".)\n </td>\n </tr>\n <tr>\n <td>\n Units defeated while supporting:\n </td>\n <td>\n " ) . concat ( player . inADay . sup . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . sup . rank , ".)\n </td>\n </tr>\n <tr>\n <td>\n Resources plundered:\n </td>\n <td>\n " ) . concat ( player . inADay . lootRes . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . lootRes . rank , ".)\n </td>\n </tr>\n <tr>\n <td>\n Villages plundered:\n </td>\n <td>\n " ) . concat ( player . inADay . lootVil . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . lootVil . rank , ".)\n </td>\n </tr>\n <tr>\n <td>\n Resources gathered:\n </td>\n <td>\n " ) . concat ( player . inADay . scavenge . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . scavenge . rank , ".)\n </td>\n </tr>\n <tr>\n <td>\n Villages conquered:\n </td>\n <td>\n " ) . concat ( player . inADay . conquer . score . toLocaleString ( ) , " (" ) . concat ( player . inADay . conquer . rank , ".)\n </td>\n </tr>\n </tbody>\n </table>\n " ) ;
2020-07-11 14:25:10 +00:00
} ;
const render = ( _ref2 ) => {
let {
player ,
dailyPlayerStats
} = _ref2 ;
2020-07-11 12:08:43 +00:00
[ {
2020-07-11 13:14:29 +00:00
title : 'Joined at:' ,
2020-07-11 12:08:43 +00:00
data : ( 0 , _formatDate . default ) ( player . joinedAt ) ,
id : 'joined_at'
} , {
2020-07-11 13:14:29 +00:00
title : 'Daily growth:' ,
2020-07-11 12:08:43 +00:00
data : player . dailyGrowth . toLocaleString ( ) ,
id : 'dg'
2020-07-12 10:01:43 +00:00
} , {
title : 'Best rank:' ,
data : player . bestRank + ' ' + "(" . concat ( ( 0 , _formatDate . default ) ( player . bestRankAt ) , ")" ) ,
id : 'best_rank'
} , {
title : 'Most points:' ,
2020-07-17 11:50:29 +00:00
data : player . mostPoints . toLocaleString ( ) + ' ' + "(" . concat ( ( 0 , _formatDate . default ) ( player . mostPointsAt ) , ")" ) ,
2020-07-12 10:01:43 +00:00
id : 'most_points'
} , {
title : 'Most villages:' ,
data : player . mostVillages + ' ' + "(" . concat ( ( 0 , _formatDate . default ) ( player . mostVillagesAt ) , ")" ) ,
id : 'most_villages'
2020-07-11 12:08:43 +00:00
} ] . forEach ( data => {
renderTr ( data ) ;
} ) ;
2020-07-11 15:57:05 +00:00
renderInADayRanks ( player ) ;
2020-07-11 13:14:29 +00:00
2020-07-11 14:25:10 +00:00
if ( dailyPlayerStats && dailyPlayerStats . items . length > 0 ) {
2020-07-17 12:16:07 +00:00
( 0 , _renderTodaysStats . default ) ( otherElementsContainer , dailyPlayerStats . items [ 0 ] ) ;
2020-07-11 14:25:10 +00:00
}
2020-07-11 13:14:29 +00:00
if ( player . nameChanges . length > 0 ) {
renderPlayerOtherNames ( player ) ;
}
if ( player . servers . length > 0 ) {
renderPlayerServers ( player ) ;
}
2020-07-11 12:08:43 +00:00
} ;
2020-07-17 10:58:08 +00:00
const addPaginationListeners = ( id , fn ) => {
document . querySelectorAll ( '#' + id + ' a' ) . forEach ( el => {
el . addEventListener ( 'click' , fn ) ;
2020-07-11 18:44:52 +00:00
} ) ;
} ;
const renderTribeChanges = ( e , currentPage , tribeChanges ) => {
2020-07-15 18:55:24 +00:00
const paginationItems = ( 0 , _pagination . generatePaginationItems ) ( {
total : tribeChanges . total ,
limit : TRIBE _CHANGES _PER _PAGE ,
currentPage
} ) ;
2020-07-17 13:43:28 +00:00
const html = "\n <div style=\"" . concat ( ( 0 , _pagination . getContainerStyles ) ( ) , "\" id=\"" ) . concat ( TRIBE _CHANGES _PAGINATION _CONTAINER _ID , "\">\n " ) . concat ( paginationItems . join ( '' ) , "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n New tribe\n </th>\n <th>\n Old tribe\n </th>\n </tr>\n " ) . concat ( tribeChanges . items . map ( tribeChange => {
2020-07-11 18:44:52 +00:00
let rowHTML = '<tr>' + "<td>" . concat ( ( 0 , _formatDate . default ) ( tribeChange . createdAt ) , "</td>" ) ;
if ( tribeChange . newTribe ) {
rowHTML += "<td><a href=\"" . concat ( ( 0 , _tribalwars . formatTribeURL ) ( tribeChange . newTribe . id ) , "\">" ) . concat ( tribeChange . newTribe . tag , "</a></td>" ) ;
} else {
rowHTML += '<td>-</td>' ;
}
if ( tribeChange . oldTribe ) {
rowHTML += "<td><a href=\"" . concat ( ( 0 , _tribalwars . formatTribeURL ) ( tribeChange . oldTribe . id ) , "\">" ) . concat ( tribeChange . oldTribe . tag , "</a></td>" ) ;
} else {
rowHTML += '<td>-</td>' ;
}
2020-07-17 10:58:08 +00:00
return rowHTML + '</tr>' ;
2020-07-11 18:44:52 +00:00
} ) . join ( '' ) , "\n </tbody>\n </table>\n " ) ;
( 0 , _renderPopup . default ) ( {
e ,
title : "Tribe changes" ,
id : 'tribeChanges' ,
html
} ) ;
2020-07-17 10:58:08 +00:00
addPaginationListeners ( TRIBE _CHANGES _PAGINATION _CONTAINER _ID , handleShowTribeChangesButtonClick ) ;
2020-07-11 18:44:52 +00:00
} ;
2020-07-12 13:18:49 +00:00
const handleShowTribeChangesButtonClick = async e => {
2020-07-11 18:44:52 +00:00
e . preventDefault ( ) ;
2020-07-15 18:55:24 +00:00
const page = ( 0 , _pagination . getPage ) ( e . target ) ;
2020-07-11 18:44:52 +00:00
if ( ! isNaN ( page ) ) {
const data = await ( 0 , _requestCreator . default ) ( {
query : TRIBE _CHANGES _QUERY ,
variables : {
filter : {
playerID : [ PLAYER _ID ] ,
offset : TRIBE _CHANGES _PER _PAGE * ( page - 1 ) ,
limit : TRIBE _CHANGES _PER _PAGE ,
sort : 'createdAt DESC'
} ,
server : SERVER
}
} ) ;
renderTribeChanges ( e , page , data . tribeChanges ) ;
}
} ;
2020-07-15 18:55:24 +00:00
const addMathSymbol = v => {
return v > 0 ? '+' + v : v ;
} ;
const renderPlayerHistory = ( e , currentPage , playerHistory , playerDailyStats ) => {
const paginationItems = ( 0 , _pagination . generatePaginationItems ) ( {
total : playerHistory . total ,
limit : PLAYER _HISTORY _PER _PAGE ,
currentPage
} ) ;
2020-07-17 13:43:28 +00:00
const html = "\n <div style=\"" . concat ( ( 0 , _pagination . getContainerStyles ) ( ) , "\" id=\"" ) . concat ( PLAYER _HISTORY _PAGINATION _CONTAINER _ID , "\">\n " ) . concat ( paginationItems . join ( '' ) , "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Tribe\n </th>\n <th>\n Points\n </th>\n <th>\n Villages\n </th>\n <th>\n OD\n </th>\n <th>\n ODA\n </th>\n <th>\n ODD\n </th>\n <th>\n ODS\n </th>\n </tr>\n " ) . concat ( playerHistory . items . map ( playerHistory => {
2020-07-15 18:55:24 +00:00
const subtracted = ( 0 , _subDays . default ) ( new Date ( playerHistory . createDate ) , 1 ) . toISOString ( ) . split ( '.' ) [ 0 ] + 'Z' ;
const stats = playerDailyStats . items . find ( stats => {
return stats . createDate === subtracted ;
} ) ;
let rowHTML = '<tr>' + "<td>" . concat ( ( 0 , _formatDate . default ) ( playerHistory . createDate , {
year : 'numeric' ,
month : '2-digit' ,
day : '2-digit'
} ) , "</td>" ) ;
if ( playerHistory . tribe ) {
rowHTML += "<td><a href=\"" . concat ( ( 0 , _tribalwars . formatTribeURL ) ( playerHistory . tribe . id ) , "\">" ) . concat ( playerHistory . tribe . tag , "</a></td>" ) ;
} else {
rowHTML += '<td>-</td>' ;
}
2020-07-16 17:49:01 +00:00
rowHTML += "\n <td title=\"" . concat ( stats ? addMathSymbol ( stats . points ) : '' , "\">\n " ) . concat ( playerHistory . points . toLocaleString ( ) , " (<strong>" ) . concat ( playerHistory . rank , "</strong>)\n </td>\n <td title=\"" ) . concat ( stats ? addMathSymbol ( stats . villages ) : '' , "\">\n " ) . concat ( playerHistory . totalVillages , "\n </td>\n <td title=\"" ) . concat ( stats ? addMathSymbol ( stats . scoreTotal ) : '' , "\">\n " ) . concat ( playerHistory . scoreTotal . toLocaleString ( ) , " (<strong>" ) . concat ( playerHistory . rankTotal , "</strong>)\n </td>\n <td title=\"" ) . concat ( stats ? addMathSymbol ( stats . scoreAtt ) : '' , "\">\n " ) . concat ( playerHistory . scoreAtt . toLocaleString ( ) , " (<strong>" ) . concat ( playerHistory . rankAtt , "</strong>)\n </td>\n <td title=\"" ) . concat ( stats ? addMathSymbol ( stats . scoreDef ) : '' , "\">\n " ) . concat ( playerHistory . scoreDef . toLocaleString ( ) , " (<strong>" ) . concat ( playerHistory . rankDef , "</strong>)\n </td>\n <td title=\"" ) . concat ( stats ? addMathSymbol ( stats . scoreSup ) : '' , "\">\n " ) . concat ( playerHistory . scoreSup . toLocaleString ( ) , " (<strong>" ) . concat ( playerHistory . rankSup , "</strong>)\n </td>\n " ) + '</tr>' ;
2020-07-15 18:55:24 +00:00
return rowHTML ;
} ) . join ( '' ) , "\n </tbody>\n </table>\n " ) ;
( 0 , _renderPopup . default ) ( {
e ,
title : "Player history" ,
id : 'playerHistory' ,
html
} ) ;
2020-07-17 10:58:08 +00:00
addPaginationListeners ( PLAYER _HISTORY _PAGINATION _CONTAINER _ID , handleShowPlayerHistoryClick ) ;
2020-07-15 18:55:24 +00:00
} ;
const handleShowPlayerHistoryClick = async e => {
e . preventDefault ( ) ;
const page = ( 0 , _pagination . getPage ) ( e . target ) ;
if ( ! isNaN ( page ) ) {
try {
const filter = {
playerID : [ PLAYER _ID ] ,
offset : PLAYER _HISTORY _PER _PAGE * ( page - 1 ) ,
limit : PLAYER _HISTORY _PER _PAGE ,
sort : 'createDate DESC'
} ;
const {
playerHistory ,
dailyPlayerStats
} = await ( 0 , _requestCreator . default ) ( {
query : PLAYER _HISTORY _AND _PLAYER _DAILY _STATS _QUERY ,
variables : {
server : SERVER ,
playerHistoryFilter : filter ,
dailyPlayerStatsFilter : _objectSpread ( _objectSpread ( { } , filter ) , { } , {
offset : filter . offset + 1
} )
}
} ) ;
renderPlayerHistory ( e , page , playerHistory , dailyPlayerStats ) ;
} catch ( error ) {
console . log ( 'cannot load player history' , error ) ;
}
}
} ;
2020-07-17 10:58:08 +00:00
const handleShowPlayerEnnoblementsClick = async e => {
e . preventDefault ( ) ;
const page = ( 0 , _pagination . getPage ) ( e . target ) ;
if ( ! isNaN ( page ) ) {
const data = await ( 0 , _requestCreator . default ) ( {
query : ENNOBLEMENTS _QUERY ,
variables : {
filter : {
or : {
oldOwnerID : [ PLAYER _ID ] ,
newOwnerID : [ PLAYER _ID ]
} ,
offset : ENNOBLEMENTS _PER _PAGE * ( page - 1 ) ,
limit : ENNOBLEMENTS _PER _PAGE ,
sort : 'ennobledAt DESC'
} ,
server : SERVER
}
} ) ;
2020-07-17 13:43:28 +00:00
( 0 , _renderEnnoblements . default ) ( e , data . ennoblements , {
currentPage : page ,
limit : ENNOBLEMENTS _PER _PAGE ,
onPageChange : handleShowPlayerEnnoblementsClick
} ) ;
2020-07-17 10:58:08 +00:00
}
} ;
2020-07-12 13:18:49 +00:00
const handleExportPlayerVillagesButtonClick = e => {
e . preventDefault ( ) ;
Dialog . show ( 'Exported villages' , "<textarea cols=30 rows=8 readonly>" . concat ( document . querySelector ( '#villages_list' ) . innerHTML . match ( /(\d+)\|(\d+)/g ) . join ( ' ' ) , "</textarea>" ) ) ;
} ;
2020-07-15 18:55:24 +00:00
const wrapAction = action => {
const actionWrapperTd = document . createElement ( 'td' ) ;
actionWrapperTd . colSpan = '2' ;
actionWrapperTd . append ( action ) ;
const actionWrapperTr = document . createElement ( 'tr' ) ;
actionWrapperTr . appendChild ( actionWrapperTd ) ;
return actionWrapperTr ;
} ;
2020-07-11 18:44:52 +00:00
const renderActions = ( ) => {
const showTribeChanges = document . createElement ( 'a' ) ;
showTribeChanges . href = '#' ;
2020-07-15 18:55:24 +00:00
( 0 , _pagination . setPage ) ( showTribeChanges , '1' ) ;
2020-07-11 18:44:52 +00:00
showTribeChanges . innerHTML = 'Show tribe changes' ;
2020-07-12 13:18:49 +00:00
showTribeChanges . addEventListener ( 'click' , handleShowTribeChangesButtonClick ) ;
2020-07-15 18:55:24 +00:00
actionsContainer . appendChild ( wrapAction ( showTribeChanges ) ) ;
const showPlayerHistory = document . createElement ( 'a' ) ;
showPlayerHistory . href = '#' ;
( 0 , _pagination . setPage ) ( showPlayerHistory , '1' ) ;
showPlayerHistory . innerHTML = 'Show player history' ;
showPlayerHistory . addEventListener ( 'click' , handleShowPlayerHistoryClick ) ;
actionsContainer . appendChild ( wrapAction ( showPlayerHistory ) ) ;
2020-07-17 10:58:08 +00:00
const showEnnoblements = document . createElement ( 'a' ) ;
showEnnoblements . href = '#' ;
( 0 , _pagination . setPage ) ( showEnnoblements , '1' ) ;
showEnnoblements . innerHTML = 'Show player ennoblements' ;
showEnnoblements . addEventListener ( 'click' , handleShowPlayerEnnoblementsClick ) ;
actionsContainer . appendChild ( wrapAction ( showEnnoblements ) ) ;
2020-07-12 13:18:49 +00:00
const exportPlayerVillages = document . createElement ( 'a' ) ;
exportPlayerVillages . href = '#' ;
2020-07-12 21:14:00 +00:00
exportPlayerVillages . innerHTML = "Export player's villages" ;
2020-07-12 13:18:49 +00:00
exportPlayerVillages . addEventListener ( 'click' , handleExportPlayerVillagesButtonClick ) ;
2020-07-15 18:55:24 +00:00
actionsContainer . appendChild ( wrapAction ( exportPlayerVillages ) ) ;
2020-07-11 18:44:52 +00:00
} ;
2020-07-11 12:08:43 +00:00
( async function ( ) {
try {
2020-07-11 18:44:52 +00:00
renderActions ( ) ;
2020-07-11 14:25:10 +00:00
const dataFromCache = loadDataFromCache ( ) ;
2020-07-11 12:08:43 +00:00
2020-07-11 14:25:10 +00:00
if ( dataFromCache && dataFromCache . player ) {
render ( dataFromCache ) ;
2020-07-11 12:08:43 +00:00
}
2020-07-11 14:25:10 +00:00
const dataFromAPI = await loadData ( ) ;
2020-07-11 12:08:43 +00:00
2020-07-11 14:25:10 +00:00
if ( dataFromAPI ) {
render ( dataFromAPI ) ;
2020-07-11 12:08:43 +00:00
}
} catch ( error ) {
console . log ( 'extended player profile' , error ) ;
}
} ) ( ) ;
2020-07-17 13:43:28 +00:00
} , { "date-fns/subDays" : "mRRL" , "./libs/requestCreator" : "Ph2E" , "./utils/renderTodaysStats" : "dPMc" , "./utils/renderPopup" : "P4rL" , "./utils/renderEnnoblements" : "vhoq" , "./utils/pagination" : "fCHX" , "./utils/getIDFromURL" : "tQUs" , "./utils/getCurrentServer" : "DMkL" , "./utils/formatDate" : "V6Mf" , "./utils/twstats" : "Syko" , "./utils/tribalwars" : "fHHP" , "./utils/localStorage" : "KWxH" } ] } , { } , [ "yRop" ] , null )