2020-07-24 12:09:33 +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-08-13 07:47:25 +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 ) {
2020-07-24 12:09:33 +00:00
"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 ) ;
}
}
2020-08-13 07:47:25 +00:00
} , { "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "umce" : [ function ( require , module , exports ) {
2020-07-25 13:47:49 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = addMilliseconds ;
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 addMilliseconds
* @ category Millisecond Helpers
* @ summary Add the specified number of milliseconds to the given date .
*
* @ description
* Add the specified number of milliseconds 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 milliseconds 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 milliseconds added
* @ throws { TypeError } 2 arguments required
*
* @ example
* // Add 750 milliseconds to 10 July 2014 12:45:30.000:
* var result = addMilliseconds ( new Date ( 2014 , 6 , 10 , 12 , 45 , 30 , 0 ) , 750 )
* //=> Thu Jul 10 2014 12:45:30.750
* /
function addMilliseconds ( dirtyDate , dirtyAmount ) {
( 0 , _index3 . default ) ( 2 , arguments ) ;
var timestamp = ( 0 , _index2 . default ) ( dirtyDate ) . getTime ( ) ;
var amount = ( 0 , _index . default ) ( dirtyAmount ) ;
return new Date ( timestamp + amount ) ;
}
} , { "../_lib/toInteger/index.js" : "VYL5" , "../toDate/index.js" : "KYJg" , "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "pfh4" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = addMinutes ;
var _index = _interopRequireDefault ( require ( "../_lib/toInteger/index.js" ) ) ;
var _index2 = _interopRequireDefault ( require ( "../addMilliseconds/index.js" ) ) ;
var _index3 = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
var MILLISECONDS _IN _MINUTE = 60000 ;
/ * *
* @ name addMinutes
* @ category Minute Helpers
* @ summary Add the specified number of minutes to the given date .
*
* @ description
* Add the specified number of minutes 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 minutes 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 minutes added
* @ throws { TypeError } 2 arguments required
*
* @ example
* // Add 30 minutes to 10 July 2014 12:00:00:
* var result = addMinutes ( new Date ( 2014 , 6 , 10 , 12 , 0 ) , 30 )
* //=> Thu Jul 10 2014 12:30:00
* /
function addMinutes ( dirtyDate , dirtyAmount ) {
( 0 , _index3 . default ) ( 2 , arguments ) ;
var amount = ( 0 , _index . default ) ( dirtyAmount ) ;
return ( 0 , _index2 . default ) ( dirtyDate , amount * MILLISECONDS _IN _MINUTE ) ;
}
} , { "../_lib/toInteger/index.js" : "VYL5" , "../addMilliseconds/index.js" : "umce" , "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "ddIN" : [ function ( require , module , exports ) {
2020-07-24 12:14:43 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
const translations = {
pl _PL : {
ennobledAt : 'Podbita o' ,
never : 'Nigdy' ,
2020-08-13 09:28:03 +00:00
possibleLoyalty : 'Prawdopodobne poparcie' ,
2020-07-24 14:38:57 +00:00
canSendNoble : 'Można wysłać szlachcica' ,
2020-07-24 14:31:54 +00:00
yes : 'Tak' ,
no : 'Nie'
2020-07-24 12:14:43 +00:00
} ,
en _DK : {
ennobledAt : 'Ennobled at' ,
never : 'Never' ,
2020-07-24 14:31:54 +00:00
possibleLoyalty : 'Possible loyalty' ,
2020-07-24 14:38:57 +00:00
canSendNoble : 'Can send noble' ,
2020-07-24 14:31:54 +00:00
yes : 'Yes' ,
no : 'No'
2020-07-24 12:14:43 +00:00
}
} ;
var _default = ( ) => translations [ window . game _data . locale ] || translations . en _DK ;
exports . default = _default ;
} , { } ] , "Ph2E" : [ function ( require , module , exports ) {
2020-07-24 12:09:33 +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 ( API _URI , {
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 ;
} , { } ] , "V6Mf" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _default = ( date , options ) => {
return new Date ( date ) . toLocaleDateString ( window . game _data . locale . replace ( '_' , '-' ) , options ? options : {
year : 'numeric' ,
month : '2-digit' ,
day : '2-digit' ,
hour : '2-digit' ,
minute : '2-digit' ,
second : '2-digit'
} ) ;
} ;
exports . default = _default ;
} , { } ] , "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 ;
2020-07-24 14:31:54 +00:00
} , { } ] , "XOOL" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . calcDistanceBetweenTwoPoints = void 0 ;
const calcDistanceBetweenTwoPoints = ( x1 , y1 , x2 , y2 ) => {
const a = x1 - x2 ;
const b = y1 - y2 ;
return Math . sqrt ( a * a + b * b ) ;
} ;
exports . calcDistanceBetweenTwoPoints = calcDistanceBetweenTwoPoints ;
2020-08-05 19:10:42 +00:00
} , { } ] , "fHHP" : [ function ( require , module , exports ) {
2020-07-25 13:47:49 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2021-01-03 12:13:05 +00:00
exports . buildImgURL = exports . calcAttackDuration = exports . buildVillageName = exports . buildVillageURL = exports . buildPlayerURL = exports . buildTribeURL = void 0 ;
2020-07-25 13:47:49 +00:00
2021-01-03 12:13:05 +00:00
const buildTribeURL = id => {
2020-07-25 13:47:49 +00:00
return window . location . origin + TribalWars . buildURL ( '' , {
screen : 'info_ally' ,
id
} ) ;
} ;
2021-01-03 12:13:05 +00:00
exports . buildTribeURL = buildTribeURL ;
2020-07-25 13:47:49 +00:00
2021-01-03 12:13:05 +00:00
const buildPlayerURL = id => {
2020-07-25 13:47:49 +00:00
return window . location . origin + TribalWars . buildURL ( '' , {
screen : 'info_player' ,
id
} ) ;
} ;
2021-01-03 12:13:05 +00:00
exports . buildPlayerURL = buildPlayerURL ;
2020-07-25 13:47:49 +00:00
2021-01-03 12:13:05 +00:00
const buildVillageURL = id => {
2020-07-25 13:47:49 +00:00
return window . location . origin + TribalWars . buildURL ( '' , {
screen : 'info_village' ,
id
} ) ;
} ;
2021-01-03 12:13:05 +00:00
exports . buildVillageURL = buildVillageURL ;
2020-07-25 13:47:49 +00:00
2021-01-03 12:13:05 +00:00
const buildVillageName = function buildVillageName ( ) {
2020-07-25 13:47:49 +00:00
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 ) ;
} ;
2021-01-03 12:13:05 +00:00
exports . buildVillageName = buildVillageName ;
2020-07-25 13:47:49 +00:00
2021-01-03 12:13:05 +00:00
const calcAttackDuration = ( distance , baseSpeed ) => {
return Math . round ( distance * baseSpeed ) ;
2020-07-25 13:47:49 +00:00
} ;
exports . calcAttackDuration = calcAttackDuration ;
const buildImgURL = img => {
return image _base + img ;
} ;
exports . buildImgURL = buildImgURL ;
2020-08-05 19:10:42 +00:00
} , { } ] , "KX6P" : [ function ( require , module , exports ) {
2020-07-25 13:47:49 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
var _tribalwars = require ( "./tribalwars" ) ;
var _default = unit => {
return ( 0 , _tribalwars . buildImgURL ) ( "unit/unit_" . concat ( unit , ".png" ) ) ;
} ;
exports . default = _default ;
} , { "./tribalwars" : "fHHP" } ] , "KWxH" : [ function ( require , module , exports ) {
2020-07-24 12:09:33 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . setItem = exports . getItem = void 0 ;
2020-07-24 17:46:07 +00:00
const getItem = function getItem ( key ) {
let d = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
2020-07-24 12:09:33 +00:00
const json = localStorage . getItem ( key ) ;
2020-07-24 17:46:07 +00:00
let obj = d ;
2020-07-24 12:09:33 +00:00
if ( json ) {
obj = JSON . parse ( json ) ;
}
return obj ;
} ;
exports . getItem = getItem ;
const setItem = ( key , payload ) => {
localStorage . setItem ( key , JSON . stringify ( payload ) ) ;
} ;
exports . setItem = setItem ;
2020-08-13 07:47:25 +00:00
} , { } ] , "H70G" : [ function ( require , module , exports ) {
2020-07-24 12:09:33 +00:00
"use strict" ;
2020-08-13 07:47:25 +00:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = differenceInMilliseconds ;
var _index = _interopRequireDefault ( require ( "../toDate/index.js" ) ) ;
var _index2 = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
/ * *
* @ name differenceInMilliseconds
* @ category Millisecond Helpers
* @ summary Get the number of milliseconds between the given dates .
*
* @ description
* Get the number of milliseconds between the given dates .
*
* # # # 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 } dateLeft - the later date
* @ param { Date | Number } dateRight - the earlier date
* @ returns { Number } the number of milliseconds
* @ throws { TypeError } 2 arguments required
*
* @ example
* // How many milliseconds are between
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
* var result = differenceInMilliseconds (
* new Date ( 2014 , 6 , 2 , 12 , 30 , 21 , 700 ) ,
* new Date ( 2014 , 6 , 2 , 12 , 30 , 20 , 600 )
* )
* //=> 1100
* /
function differenceInMilliseconds ( dirtyDateLeft , dirtyDateRight ) {
( 0 , _index2 . default ) ( 2 , arguments ) ;
var dateLeft = ( 0 , _index . default ) ( dirtyDateLeft ) ;
var dateRight = ( 0 , _index . default ) ( dirtyDateRight ) ;
return dateLeft . getTime ( ) - dateRight . getTime ( ) ;
}
} , { "../toDate/index.js" : "KYJg" , "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "oGJj" : [ function ( require , module , exports ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = differenceInMinutes ;
var _index = _interopRequireDefault ( require ( "../differenceInMilliseconds/index.js" ) ) ;
var _index2 = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
var MILLISECONDS _IN _MINUTE = 60000 ;
/ * *
* @ name differenceInMinutes
* @ category Minute Helpers
* @ summary Get the number of minutes between the given dates .
*
* @ description
* Get the signed number of full ( rounded towards 0 ) minutes between the given dates .
*
* # # # 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 } dateLeft - the later date
* @ param { Date | Number } dateRight - the earlier date
* @ returns { Number } the number of minutes
* @ throws { TypeError } 2 arguments required
*
* @ example
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
* var result = differenceInMinutes (
* new Date ( 2014 , 6 , 2 , 12 , 20 , 0 ) ,
* new Date ( 2014 , 6 , 2 , 12 , 7 , 59 )
* )
* //=> 12
*
* @ example
* // How many minutes are from 10:01:59 to 10:00:00
* var result = differenceInMinutes (
* new Date ( 2000 , 0 , 1 , 10 , 0 , 0 ) ,
* new Date ( 2000 , 0 , 1 , 10 , 1 , 59 )
* )
* //=> -1
* /
function differenceInMinutes ( dirtyDateLeft , dirtyDateRight ) {
( 0 , _index2 . default ) ( 2 , arguments ) ;
var diff = ( 0 , _index . default ) ( dirtyDateLeft , dirtyDateRight ) / MILLISECONDS _IN _MINUTE ;
return diff > 0 ? Math . floor ( diff ) : Math . ceil ( diff ) ;
}
2021-01-03 12:13:05 +00:00
} , { "../differenceInMilliseconds/index.js" : "H70G" , "../_lib/requiredArgs/index.js" : "kK6Q" } ] , "kcC2" : [ function ( require , module , exports ) {
2020-08-13 07:47:25 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
2020-07-24 12:09:33 +00:00
var _differenceInMinutes = _interopRequireDefault ( require ( "date-fns/differenceInMinutes" ) ) ;
2020-08-13 07:47:25 +00:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2021-01-03 12:13:05 +00:00
const calcLoyalty = ( ennobledAt , speed ) => {
2020-08-13 07:47:25 +00:00
let loyalty = 25 + Math . abs ( ( 0 , _differenceInMinutes . default ) ( ennobledAt , new Date ( ) ) ) * ( speed / 60 ) ;
if ( loyalty > 100 ) {
loyalty = 100 ;
}
return Math . floor ( loyalty ) ;
} ;
2021-01-03 12:13:05 +00:00
var _default = calcLoyalty ;
2020-08-13 07:47:25 +00:00
exports . default = _default ;
} , { "date-fns/differenceInMinutes" : "oGJj" } ] , "HdqX" : [ function ( require , module , exports ) {
"use strict" ;
2020-07-25 13:47:49 +00:00
var _addMinutes = _interopRequireDefault ( require ( "date-fns/addMinutes" ) ) ;
2020-07-24 12:14:43 +00:00
var _extendedMapPopup = _interopRequireDefault ( require ( "./i18n/extendedMapPopup" ) ) ;
2020-07-24 12:09:33 +00:00
var _requestCreator = _interopRequireDefault ( require ( "./libs/requestCreator" ) ) ;
var _formatDate = _interopRequireDefault ( require ( "./utils/formatDate" ) ) ;
var _getCurrentServer = _interopRequireDefault ( require ( "./utils/getCurrentServer" ) ) ;
2020-07-24 14:31:54 +00:00
var _math = require ( "./utils/math" ) ;
2020-07-25 13:47:49 +00:00
var _buildUnitImgURL = _interopRequireDefault ( require ( "./utils/buildUnitImgURL" ) ) ;
2020-07-24 12:09:33 +00:00
var _localStorage = require ( "./utils/localStorage" ) ;
2020-07-25 13:47:49 +00:00
var _tribalwars = require ( "./utils/tribalwars" ) ;
2021-01-03 12:13:05 +00:00
var _calcLoyalty = _interopRequireDefault ( require ( "./utils/calcLoyalty" ) ) ;
2020-08-13 07:47:25 +00:00
2020-07-24 12:09:33 +00:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2020-07-25 13:47:49 +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-24 12:09:33 +00:00
// ==UserScript==
2020-08-15 11:11:11 +00:00
// @name Extended map popup
2020-07-24 12:09:33 +00:00
// @namespace https://github.com/tribalwarshelp/scripts
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedMapPopup.js
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedMapPopup.js
2021-01-03 12:13:05 +00:00
// @version 0.6.5
2020-08-15 11:11:11 +00:00
// @description Extended map popup
2021-01-01 17:03:36 +00:00
// @author Kichiyaki https://dawid-wysokinski.pl/
2020-07-24 12:09:33 +00:00
// @match *://*/game.php*screen=map*
// @grant none
// ==/UserScript==
const SERVER = ( 0 , _getCurrentServer . default ) ( ) ;
2020-07-25 13:47:49 +00:00
const CURR _SERVER _CONFIG = "\n query server($key: String!) {\n server(key: $key) {\n config {\n speed\n unitSpeed\n snob {\n maxDist\n }\n }\n unitConfig {\n spear {\n speed\n }\n sword {\n speed\n }\n axe {\n speed\n }\n archer {\n speed\n }\n spy {\n speed\n }\n light {\n speed\n }\n marcher {\n speed\n }\n heavy {\n speed\n }\n ram {\n speed\n }\n catapult {\n speed\n }\n knight {\n speed\n }\n snob {\n speed\n }\n }\n }\n }\n" ;
2020-11-21 14:01:40 +00:00
const LAST _VILLAGE _CONQUER _QUERY = "\n query ennoblements($server: String!, $filter: EnnoblementFilter!, $sort: [String!], $limit: Int) {\n ennoblements(server: $server, filter: $filter, sort: $sort, limit: $limit) {\n items {\n ennobledAt\n village {\n id\n }\n }\n }\n }\n" ;
2020-07-24 12:09:33 +00:00
const SERVER _CONFIG _LOCAL _STORAGE _KEY = 'kiszkowaty_extended_map_popup_server_cfg' ;
2020-07-24 12:14:43 +00:00
const translations = ( 0 , _extendedMapPopup . default ) ( ) ;
2020-07-24 12:09:33 +00:00
2020-08-07 13:50:26 +00:00
const loadConfigFromLocalStorage = ( ) => {
2020-07-24 12:09:33 +00:00
return ( 0 , _localStorage . getItem ) ( SERVER _CONFIG _LOCAL _STORAGE _KEY ) ;
} ;
const cacheServerConfig = function cacheServerConfig ( ) {
let data = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
( 0 , _localStorage . setItem ) ( SERVER _CONFIG _LOCAL _STORAGE _KEY , data ) ;
} ;
const isConfigExpired = date => {
2020-08-07 13:50:26 +00:00
return Math . abs ( date . getTime ( ) - new Date ( ) . getTime ( ) ) > 1000 * 60 * 60 * 24 ;
2020-07-24 12:09:33 +00:00
} ;
2020-08-07 13:50:26 +00:00
const loadConfig = async ( ) => {
let data = loadConfigFromLocalStorage ( ) ;
2020-07-24 12:09:33 +00:00
2020-07-25 13:47:49 +00:00
if ( ! data || ! data . server || isConfigExpired ( new Date ( data . loadedAt ) ) || ! data . server . config || ! data . server . config . speed || ! data . server . config . snob || ! data . server . config . snob . maxDist || ! data . server . config . unitSpeed || ! data . server . unitConfig ) {
2020-07-24 12:09:33 +00:00
data = await ( 0 , _requestCreator . default ) ( {
query : CURR _SERVER _CONFIG ,
variables : {
key : SERVER
}
} ) ;
data . loadedAt = new Date ( ) ;
cacheServerConfig ( data ) ;
}
2020-07-25 13:47:49 +00:00
return data && data . server && data . server . config ? {
config : data . server . config ,
unitConfig : data . server . unitConfig
} : { } ;
2020-07-24 12:09:33 +00:00
} ;
const loadVillageData = async function loadVillageData ( id ) {
let {
cacheOnly = false
} = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
if ( cacheOnly || TWMap . popup . extendedMapPopupCache [ id ] ) {
return TWMap . popup . extendedMapPopupCache [ id ] ;
}
try {
const data = await ( 0 , _requestCreator . default ) ( {
query : LAST _VILLAGE _CONQUER _QUERY ,
variables : {
server : SERVER ,
2020-11-21 14:01:40 +00:00
sort : [ 'ennobledAt DESC' ] ,
2020-07-24 12:09:33 +00:00
filter : {
2020-11-21 14:01:40 +00:00
villageID : [ id ]
} ,
limit : 1
2020-07-24 12:09:33 +00:00
}
} ) ;
TWMap . popup . extendedMapPopupCache [ id ] = data ;
return data ;
} catch ( error ) {
console . log ( 'loadVillageData' , error ) ;
}
} ;
2020-07-25 13:47:49 +00:00
const getAvailableUnits = function getAvailableUnits ( ) {
let unitCfg = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
const units = [ ] ;
for ( let unit in unitCfg ) {
if ( unitCfg [ unit ] . speed !== 0 ) {
units . push ( _objectSpread ( _objectSpread ( { } , unitCfg [ unit ] ) , { } , {
name : unit ,
img : ( 0 , _buildUnitImgURL . default ) ( unit )
} ) ) ;
}
}
return units ;
} ;
const getUnitTdBgColor = index => index % 2 === 0 ? '#f8f4e8' : '#ded3b9;' ;
const buildUnitHeader = ( unit , index ) => {
return "\n <td style=\"padding: 2px; background-color: " . concat ( getUnitTdBgColor ( index ) , ";\">\n <img\n src=\"" ) . concat ( unit . img , "\"\n title=\"" ) . concat ( unit . name , "\"\n alt=\"" ) . concat ( unit . name , "\"\n />\n </td>\n " ) ;
} ;
const buildUnitArrivalInfo = ( t , index ) => {
2020-09-17 10:26:43 +00:00
return "\n <td style=\"padding: 2px; background-color: " . concat ( getUnitTdBgColor ( index ) , ";\">\n " ) . concat ( ( 0 , _formatDate . default ) ( ( 0 , _addMinutes . default ) ( Timing . getCurrentServerTime ( ) , t ) ) , "\n </td>\n " ) ;
2020-07-25 13:47:49 +00:00
} ;
const renderAdditionalInfo = ( id , data , _ref ) => {
let {
config ,
unitConfig
} = _ref ;
2020-07-24 14:31:54 +00:00
const coords = TWMap . CoordByXY ( TWMap . villageKey [ id ] ) ;
2020-07-25 13:47:49 +00:00
const distance = ( 0 , _math . calcDistanceBetweenTwoPoints ) ( coords [ 0 ] , coords [ 1 ] , window . game _data . village . x , window . game _data . village . y ) ;
2020-07-24 12:09:33 +00:00
const ennoblement = data && data . ennoblements && data . ennoblements . items && data . ennoblements . items . length > 0 ? data . ennoblements . items [ 0 ] : undefined ;
const parent = document . querySelector ( '#map_popup #info_content tbody' ) ;
2020-07-25 13:47:49 +00:00
let unitsEl = parent . querySelector ( '#units' ) ;
if ( ! unitsEl ) {
unitsEl = document . createElement ( 'tr' ) ;
unitsEl . id = 'units' ;
parent . appendChild ( unitsEl ) ;
}
const units = getAvailableUnits ( unitConfig ) ;
unitsEl . innerHTML = "\n <td colspan=\"2\">\n <table style=\"border: 1px solid #ded3b9; max-width: 450px;\"\n width=\"100%\"\n cellpadding=\"0\"\n cellspacing=\"0\">\n <tbody>\n <tr class=\"center\">\n " . concat ( units . map ( buildUnitHeader ) . join ( '' ) , "\n </tr>\n <tr class=\"center\">\n " ) . concat ( units . map ( ( unit , index ) => {
2021-01-03 12:13:05 +00:00
return buildUnitArrivalInfo ( ( 0 , _tribalwars . calcAttackDuration ) ( distance , unit . speed ) , index ) ;
2020-07-25 13:47:49 +00:00
} ) . join ( '' ) , "\n </tr>\n </tbody>\n </table>\n </td>\n " ) ;
2020-07-24 12:09:33 +00:00
let lastEnnobledAt = parent . querySelector ( '#lastEnnobledAt' ) ;
if ( ! lastEnnobledAt ) {
lastEnnobledAt = document . createElement ( 'tr' ) ;
lastEnnobledAt . id = 'lastEnnobledAt' ;
parent . appendChild ( lastEnnobledAt ) ;
}
2020-07-24 12:14:43 +00:00
lastEnnobledAt . innerHTML = "\n <td>\n " . concat ( translations . ennobledAt , ":\n </td>\n <td>\n " ) . concat ( ennoblement ? ( 0 , _formatDate . default ) ( ennoblement . ennobledAt ) : translations . never , "\n </td>\n " ) ;
2020-07-24 12:09:33 +00:00
let loyalty = parent . querySelector ( '#loyalty' ) ;
if ( ! loyalty ) {
loyalty = document . createElement ( 'tr' ) ;
loyalty . id = 'loyalty' ;
parent . appendChild ( loyalty ) ;
}
2021-01-03 12:13:05 +00:00
loyalty . innerHTML = "\n <td>\n " . concat ( translations . possibleLoyalty , ":\n </td>\n <td>\n " ) . concat ( ennoblement ? ( 0 , _calcLoyalty . default ) ( new Date ( ennoblement . ennobledAt ) , config . speed ) : 100 , "\n </td>\n " ) ;
2020-07-24 14:38:57 +00:00
let canSendNoble = parent . querySelector ( '#canSendNoble' ) ;
2020-07-24 14:31:54 +00:00
2020-07-24 14:38:57 +00:00
if ( ! canSendNoble ) {
canSendNoble = document . createElement ( 'tr' ) ;
canSendNoble . id = 'canSendNoble' ;
parent . appendChild ( canSendNoble ) ;
2020-07-24 14:31:54 +00:00
}
2020-07-25 13:47:49 +00:00
canSendNoble . innerHTML = "\n <td>\n " . concat ( translations . canSendNoble , ":\n </td>\n <td>\n " ) . concat ( distance < config . snob . maxDist ? translations . yes : translations . no , "\n </td>\n " ) ;
2020-07-24 12:09:33 +00:00
} ;
const createLoadVillageHandler = cfg => async e => {
TWMap . popup . _loadVillage ( e ) ;
const data = await loadVillageData ( parseInt ( e ) ) ;
2020-07-24 14:31:54 +00:00
renderAdditionalInfo ( parseInt ( e ) , data , cfg ) ;
2020-07-24 12:09:33 +00:00
} ;
const createDisplayForVillageHandler = cfg => async ( e , a , t ) => {
TWMap . popup . _displayForVillage ( e , a , t ) ;
const data = await loadVillageData ( parseInt ( e . id ) , {
2020-07-24 12:25:42 +00:00
cacheOnly : window . game _data . features . Premium . active
2020-07-24 12:09:33 +00:00
} ) ;
2020-07-24 14:31:54 +00:00
renderAdditionalInfo ( parseInt ( e . id ) , data , cfg ) ;
2020-07-24 12:09:33 +00:00
} ;
( async function ( ) {
try {
2020-08-07 13:50:26 +00:00
const configs = await loadConfig ( ) ;
2020-07-24 12:09:33 +00:00
TWMap . popup . extendedMapPopupCache = { } ;
TWMap . popup . _loadVillage = TWMap . popup . loadVillage ;
2020-07-25 13:47:49 +00:00
TWMap . popup . loadVillage = createLoadVillageHandler ( configs ) ;
2020-07-24 12:09:33 +00:00
TWMap . popup . _displayForVillage = TWMap . popup . displayForVillage ;
2020-07-25 13:47:49 +00:00
TWMap . popup . displayForVillage = createDisplayForVillageHandler ( configs ) ;
2020-07-24 12:09:33 +00:00
} catch ( error ) {
console . log ( 'extended map popup' , error ) ;
}
} ) ( ) ;
2021-01-03 12:13:05 +00:00
} , { "date-fns/addMinutes" : "pfh4" , "./i18n/extendedMapPopup" : "ddIN" , "./libs/requestCreator" : "Ph2E" , "./utils/formatDate" : "V6Mf" , "./utils/getCurrentServer" : "DMkL" , "./utils/math" : "XOOL" , "./utils/buildUnitImgURL" : "KX6P" , "./utils/localStorage" : "KWxH" , "./utils/tribalwars" : "fHHP" , "./utils/calcLoyalty" : "kcC2" } ] } , { } , [ "HdqX" ] , null )