2021-06-12 05:26:55 +00:00
( function ( ) {
2021-10-17 11:02:02 +00:00
function $6a49e4c969cec444$export$2e2bcd8739ae039 ( obj , key , value ) {
if ( key in obj ) Object . defineProperty ( obj , key , {
value : value ,
enumerable : true ,
configurable : true ,
writable : true
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
else obj [ key ] = value ;
return obj ;
}
function $f1e9793517c51c58$export$2e2bcd8739ae039 ( target ) {
for ( var i = 1 ; i < arguments . length ; i ++ ) {
var source = arguments [ i ] != null ? arguments [ i ] : {
} ;
var ownKeys = Object . keys ( source ) ;
if ( typeof Object . getOwnPropertySymbols === 'function' ) ownKeys = ownKeys . concat ( Object . getOwnPropertySymbols ( source ) . filter ( function ( sym ) {
return Object . getOwnPropertyDescriptor ( source , sym ) . enumerable ;
} ) ) ;
ownKeys . forEach ( function ( key ) {
$6a49e4c969cec444$export$2e2bcd8739ae039 ( target , key , source [ key ] ) ;
} ) ;
}
return target ;
}
function $b1520df0e3a4699c$export$2e2bcd8739ae039 ( 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 ;
}
function $f26b272b176e5476$export$2e2bcd8739ae039 ( source , excluded ) {
if ( source == null ) return {
} ;
var target = $b1520df0e3a4699c$export$2e2bcd8739ae039 ( 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 ;
}
const $902f167bfdc7b30b$export$fb18762d0c18fa09 = 'https://api.tribalwarshelp.com/graphql' ;
var $902f167bfdc7b30b$export$2e2bcd8739ae039 = ( { query : query , variables : variables = {
} } = {
} ) => {
return fetch ( $902f167bfdc7b30b$export$fb18762d0c18fa09 , {
method : 'POST' ,
body : JSON . stringify ( {
query : query ,
variables : variables
} ) ,
headers : {
'Content-Type' : 'application/json'
}
} ) . then ( ( res ) => {
return res . json ( ) ;
} ) . then ( ( { data : data , errors : errors } ) => {
if ( errors && Array . isArray ( errors ) && errors . length > 0 ) throw new Error ( errors [ 0 ] . message ) ;
return new Promise ( ( resolve ) => resolve ( data )
) ;
} ) ;
} ;
const $880b3d6f803ef712$var$translations = {
2021-06-12 05:26:55 +00:00
pl _PL : {
2021-10-17 11:02:02 +00:00
loaded : 'Załadowano' ,
pop : 'Populacja' ,
mySupport : 'Moje wsparcie' ,
allySupport : 'Wsparcie plemienia' ,
total : 'Łącznie' ,
possibleLoyalty : 'Prawdopodobne poparcie' ,
ennobledAt : 'Podbita o' ,
never : 'Nigdy' ,
action : {
linkToTWHelp : 'Akta wioski (TWHelp)' ,
showEnnoblements : 'Pokaż przejęcia' ,
countIncomingSupport : 'Policz nadchodzące wsparcie'
}
2021-06-12 05:26:55 +00:00
} ,
en _DK : {
2021-10-17 11:02:02 +00:00
loaded : 'Loaded' ,
pop : 'Pop' ,
mySupport : 'My support' ,
allySupport : 'Ally support' ,
total : 'Total' ,
possibleLoyalty : 'Possible loyalty' ,
never : 'Never' ,
ennobledAt : 'Ennobled at' ,
action : {
linkToTWHelp : 'Village file (TWHelp)' ,
showEnnoblements : 'Show ennoblements' ,
countIncomingSupport : 'Count incoming support'
}
2021-06-12 05:26:55 +00:00
} ,
de _DE : {
2021-10-17 11:02:02 +00:00
loaded : 'Geladen' ,
pop : 'Pop' ,
mySupport : 'Meine Unterstützung' ,
allySupport : 'Verbündete Unterstützung' ,
total : 'Total' ,
possibleLoyalty : 'Mögliche Zustimmung' ,
never : 'Niemals' ,
ennobledAt : 'Geadelt am' ,
action : {
linkToTWHelp : 'Dorfakte (TWHelp)' ,
showEnnoblements : 'Zeige Adelungen' ,
countIncomingSupport : 'Zähle ankommende Unterstützung'
}
2020-07-18 10:38:26 +00:00
}
2021-10-17 11:02:02 +00:00
} ;
var $880b3d6f803ef712$export$2e2bcd8739ae039 = ( ) => $880b3d6f803ef712$var$translations [ window . game _data . locale ] || $880b3d6f803ef712$var$translations . en _DK
;
const $57fe06ddde7dcd5d$var$ATTRIBUTE = 'data-page' ;
const $57fe06ddde7dcd5d$export$8947b11ec08f5f9d = ( ) => {
2021-06-12 05:26:55 +00:00
return 'display: flex; flex-direction: row; flex-wrap: wrap;' ;
2021-10-17 11:02:02 +00:00
} ;
const $57fe06ddde7dcd5d$export$5e830c5f3cd8a610 = ( el , page = 1 ) => {
if ( ! el instanceof HTMLElement ) throw new Error ( 'Expected HTMLElement as the first argument' ) ;
2021-06-12 05:26:55 +00:00
page = parseInt ( page ) ;
2021-10-17 11:02:02 +00:00
if ( typeof page !== 'number' || isNaN ( page ) ) throw new Error ( 'Expected number or string as the second argument' ) ;
el . setAttribute ( $57fe06ddde7dcd5d$var$ATTRIBUTE , page + '' ) ;
} ;
const $57fe06ddde7dcd5d$export$c2a6433281518c91 = ( el ) => {
if ( ! el instanceof HTMLElement ) return 0 ;
return parseInt ( el . getAttribute ( $57fe06ddde7dcd5d$var$ATTRIBUTE ) ) ;
} ;
const $57fe06ddde7dcd5d$export$9b5e2cbbf1f8d8c4 = ( 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' ) ;
2021-06-12 05:26:55 +00:00
return total > 0 ? Math . ceil ( total / limit ) : 1 ;
2021-10-17 11:02:02 +00:00
} ;
const $57fe06ddde7dcd5d$export$58a42a77c71a7de0 = ( { total : total , limit : limit , marginRight : marginRight = 3 , currentPage : currentPage = 0 , } = {
} ) => {
const numberOfPages = $57fe06ddde7dcd5d$export$9b5e2cbbf1f8d8c4 ( total , limit ) ;
2021-06-12 05:26:55 +00:00
const paginationItems = [ ] ;
2021-10-17 11:02:02 +00:00
for ( let i = 1 ; i <= numberOfPages ; i ++ ) if ( i === currentPage ) paginationItems . push ( ` <strong style="margin-right: ${ marginRight } px">> ${ i } <</strong> ` ) ;
else paginationItems . push ( ` <a style="margin-right: ${ marginRight } px" href="#" ${ $57fe06ddde7dcd5d$var$ATTRIBUTE } =" ${ i } "> ${ i } </a> ` ) ;
2021-06-12 05:26:55 +00:00
return paginationItems ;
2021-10-17 11:02:02 +00:00
} ;
var $9412d55e353d4b8b$export$2e2bcd8739ae039 = ( ) => window . location . host . split ( '.' ) [ 0 ]
;
var $c1259165cf39ac5b$export$2e2bcd8739ae039 = ( url ) => parseInt ( new URLSearchParams ( url ) . get ( 'id' ) )
;
const $db1dd60e5389e0c9$export$7345792e21cfc457 = ( id ) => {
2021-06-12 05:26:55 +00:00
return window . location . origin + TribalWars . buildURL ( '' , {
2021-10-17 11:02:02 +00:00
screen : 'info_ally' ,
id : id
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
} ;
const $db1dd60e5389e0c9$export$3df7b9b48f38839e = ( id ) => {
2021-06-12 05:26:55 +00:00
return window . location . origin + TribalWars . buildURL ( '' , {
2021-10-17 11:02:02 +00:00
screen : 'info_player' ,
id : id
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
} ;
const $db1dd60e5389e0c9$export$e537a41a0fc85cc5 = ( id ) => {
2021-06-12 05:26:55 +00:00
return window . location . origin + TribalWars . buildURL ( '' , {
2021-10-17 11:02:02 +00:00
screen : 'info_village' ,
id : id
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
} ;
const $db1dd60e5389e0c9$export$c6f77ec2633c38b1 = ( n = '' , x = 500 , y = 500 ) => {
2021-06-12 05:26:55 +00:00
const continent = 'K' + String ( y ) [ 0 ] + String ( x ) [ 0 ] ;
2021-10-17 11:02:02 +00:00
return ` ${ n } ( ${ x } | ${ y } ) ${ continent } ` ;
} ;
const $db1dd60e5389e0c9$export$893530ca1c0f63a2 = ( distance , baseSpeed ) => {
2021-06-12 05:26:55 +00:00
return Math . round ( distance * baseSpeed ) ;
2021-10-17 11:02:02 +00:00
} ;
const $db1dd60e5389e0c9$export$8b4b6650247854da = ( img ) => {
2021-06-12 05:26:55 +00:00
return image _base + img ;
2021-10-17 11:02:02 +00:00
} ;
var $3cc0f054d48dddd4$export$2e2bcd8739ae039 = ( unit ) => {
return $db1dd60e5389e0c9$export$8b4b6650247854da ( ` unit/unit_ ${ unit } .png ` ) ;
} ;
const $ca7593443ca49f96$export$17201263355d526a = ( d = new Date ( ) , tz = 'UTC' ) => {
2021-06-12 05:26:55 +00:00
return new Date ( new Date ( d ) . toLocaleString ( 'en-US' , {
2021-10-17 11:02:02 +00:00
timeZone : tz
2021-06-12 05:26:55 +00:00
} ) ) ;
2021-10-17 11:02:02 +00:00
} ;
const $ca7593443ca49f96$export$6a20e8f386d90a85 = ( d = new Date ( ) ) => {
return $ca7593443ca49f96$export$17201263355d526a ( d ) ;
} ;
const $ca7593443ca49f96$export$3ae94a2503e890a1 = ( date , options ) => {
2021-06-12 05:26:55 +00:00
return new Date ( date ) . toLocaleDateString ( undefined , options ? options : {
2021-10-17 11:02:02 +00:00
year : 'numeric' ,
month : '2-digit' ,
day : '2-digit' ,
hour : '2-digit' ,
minute : '2-digit' ,
second : '2-digit'
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
} ;
var $fc029eaf0e980c2d$export$2e2bcd8739ae039 = ( t ) => new Promise ( ( resolve ) => setTimeout ( resolve , t )
)
;
const $362bcac9fa8968ec$export$f92dfeb71e9bb569 = ( key , d = {
} ) => {
2021-06-12 05:26:55 +00:00
const json = localStorage . getItem ( key ) ;
let obj = d ;
2021-10-17 11:02:02 +00:00
if ( json ) obj = JSON . parse ( json ) ;
2021-06-12 05:26:55 +00:00
return obj ;
2021-10-17 11:02:02 +00:00
} ;
const $362bcac9fa8968ec$export$8a8216c44337cd5 = ( key , payload ) => {
2021-06-12 05:26:55 +00:00
localStorage . setItem ( key , JSON . stringify ( payload ) ) ;
2021-10-17 11:02:02 +00:00
} ;
function $14473fdd7558f621$export$2e2bcd8739ae039 ( required , args ) {
if ( args . length < required ) throw new TypeError ( required + ' argument' + ( required > 1 ? 's' : '' ) + ' required, but only ' + args . length + ' present' ) ;
}
function $cef0ab118a15bdd4$export$2e2bcd8739ae039 ( argument ) {
$14473fdd7558f621$export$2e2bcd8739ae039 ( 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 date 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-07-18 10:38:26 +00:00
}
2021-10-17 11:02:02 +00:00
}
function $0efd46ae48a1111f$export$2e2bcd8739ae039 ( dirtyDateLeft , dirtyDateRight ) {
$14473fdd7558f621$export$2e2bcd8739ae039 ( 2 , arguments ) ;
var dateLeft = $cef0ab118a15bdd4$export$2e2bcd8739ae039 ( dirtyDateLeft ) ;
var dateRight = $cef0ab118a15bdd4$export$2e2bcd8739ae039 ( dirtyDateRight ) ;
2021-06-12 05:26:55 +00:00
return dateLeft . getTime ( ) - dateRight . getTime ( ) ;
2021-10-17 11:02:02 +00:00
}
var $d8d089e636d25180$var$MILLISECONDS _IN _MINUTE = 60000 ;
function $d8d089e636d25180$export$2e2bcd8739ae039 ( dirtyDateLeft , dirtyDateRight ) {
$14473fdd7558f621$export$2e2bcd8739ae039 ( 2 , arguments ) ;
var diff = $0efd46ae48a1111f$export$2e2bcd8739ae039 ( dirtyDateLeft , dirtyDateRight ) / $d8d089e636d25180$var$MILLISECONDS _IN _MINUTE ;
2021-06-12 05:26:55 +00:00
return diff > 0 ? Math . floor ( diff ) : Math . ceil ( diff ) ;
2021-10-17 11:02:02 +00:00
}
const $8e88e9cb6c51e781$var$calcLoyalty = ( ennobledAt , speed ) => {
let loyalty = 25 + Math . abs ( $d8d089e636d25180$export$2e2bcd8739ae039 ( ennobledAt , new Date ( ) ) ) * ( speed / 60 ) ;
if ( loyalty > 100 ) loyalty = 100 ;
2021-06-12 05:26:55 +00:00
return Math . floor ( loyalty ) ;
2021-10-17 11:02:02 +00:00
} ;
var $8e88e9cb6c51e781$export$2e2bcd8739ae039 = $8e88e9cb6c51e781$var$calcLoyalty ;
var $5b3edb3901c8177a$export$2e2bcd8739ae039 = ( server = '' ) => server . substr ( 0 , 2 )
;
const $f3b273bd698d94bc$export$ca6dda5263526f75 = 'tribalwarshelp.com' ;
const $f3b273bd698d94bc$export$5d5850cc00079a21 = ( version = '' , server = '' ) => {
return ` https:// ${ version } . ${ $f3b273bd698d94bc$export$ca6dda5263526f75 } /server/ ${ server } ` ;
} ;
const $f3b273bd698d94bc$export$a4588dcb88e3f9db = ( version = '' , server = '' , id = 0 , entity = '' ) => {
return ` ${ $f3b273bd698d94bc$export$5d5850cc00079a21 ( version , server ) } / ${ entity } / ${ id } ` ;
} ;
const $f3b273bd698d94bc$export$3df7b9b48f38839e = ( version = '' , server = '' , id = 0 ) => {
return $f3b273bd698d94bc$export$a4588dcb88e3f9db ( version , server , id , 'player' ) ;
} ;
const $f3b273bd698d94bc$export$7345792e21cfc457 = ( version = '' , server = '' , id = 0 ) => {
return $f3b273bd698d94bc$export$a4588dcb88e3f9db ( version , server , id , 'tribe' ) ;
} ;
const $f3b273bd698d94bc$export$e537a41a0fc85cc5 = ( version = '' , server = '' , id = 0 ) => {
return $f3b273bd698d94bc$export$a4588dcb88e3f9db ( version , server , id , 'village' ) ;
} ;
const $37476051484be03e$var$translations = {
2021-06-12 05:26:55 +00:00
pl _PL : {
2021-10-17 11:02:02 +00:00
date : 'Data' ,
newOwner : 'Nowy właściciel' ,
oldOwner : 'Poprzedni właściciel' ,
village : 'Wioska' ,
title : 'Przejęcia'
2021-06-12 05:26:55 +00:00
} ,
en _DK : {
2021-10-17 11:02:02 +00:00
date : 'Date' ,
newOwner : 'New owner' ,
oldOwner : 'Old owner' ,
village : 'Village' ,
title : 'Ennoblements'
2021-06-12 05:26:55 +00:00
} ,
de _DE : {
2021-10-17 11:02:02 +00:00
date : 'Datum' ,
newOwner : 'Neuer Besitzer' ,
oldOwner : 'Alter Besitzer' ,
village : 'Dorf' ,
title : 'Adelungen'
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
} ;
var $37476051484be03e$export$2e2bcd8739ae039 = ( ) => $37476051484be03e$var$translations [ window . game _data . locale ] || $37476051484be03e$var$translations . en _DK
;
const $20636c16dad2c11a$export$21d4bed11ae27f0b = '.popup_box' ;
const $20636c16dad2c11a$var$showPopup = ( { html : html , id : id , title : title } = {
} ) => {
Dialog . show ( id , ` <h3> ${ title } </h3> ` + html ) ;
const popup = document . querySelector ( $20636c16dad2c11a$export$21d4bed11ae27f0b ) ;
2021-06-12 05:26:55 +00:00
if ( popup ) {
2021-10-17 11:02:02 +00:00
popup . style . width = 'auto' ;
popup . style . maxWidth = '1000px' ;
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
} ;
var $20636c16dad2c11a$export$2e2bcd8739ae039 = $20636c16dad2c11a$var$showPopup ;
const $5d71a092de4ef3d0$var$PAGINATION _CONTAINER _ID = 'ennoblementsPagination' ;
const $5d71a092de4ef3d0$var$translations = $37476051484be03e$export$2e2bcd8739ae039 ( ) ;
const $5d71a092de4ef3d0$var$getPlayerTd = ( player , tribe ) => {
if ( player ) return ` <td><a href=" ${ $db1dd60e5389e0c9$export$3df7b9b48f38839e ( player . id ) } "> ${ player . name } ( ${ tribe ? ` <a href=" ${ $db1dd60e5389e0c9$export$7345792e21cfc457 ( tribe . id ) } "> ${ tribe . tag } </a> ` : '-' } )</a></td> ` ;
2021-06-12 05:26:55 +00:00
return '<td>-</td>' ;
2021-10-17 11:02:02 +00:00
} ;
var $5d71a092de4ef3d0$export$2e2bcd8739ae039 = ( e , ennoblements , { limit : limit = 0 , currentPage : currentPage = 1 , onPageChange : onPageChange = ( ) => {
} } = {
} ) => {
const paginationItems = $57fe06ddde7dcd5d$export$58a42a77c71a7de0 ( {
total : ennoblements . total ,
limit : limit ,
currentPage : currentPage
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
const html = `
< div style = "${$57fe06ddde7dcd5d$export$8947b11ec08f5f9d()}" id = "${$5d71a092de4ef3d0$var$PAGINATION_CONTAINER_ID}" >
$ { paginationItems . join ( '' ) }
< / d i v >
< table class = "vis" style = "border-collapse: separate; border-spacing: 2px; width: 100%;" >
< tbody >
< tr >
< th >
$ { $5d71a092de4ef3d0$var$translations . date }
< / t h >
< th >
$ { $5d71a092de4ef3d0$var$translations . village }
< / t h >
< th >
$ { $5d71a092de4ef3d0$var$translations . newOwner }
< / t h >
< th >
$ { $5d71a092de4ef3d0$var$translations . oldOwner }
< / t h >
< / t r >
$ { ennoblements . items . map ( ( ennoblement ) => {
let rowHTML = '<tr>' + ` <td> ${ $ca7593443ca49f96$export$3ae94a2503e890a1 ( ennoblement . ennobledAt ) } </td> ` ;
if ( ennoblement . village ) rowHTML += ` <td><a href=" ${ $db1dd60e5389e0c9$export$e537a41a0fc85cc5 ( ennoblement . village . id ) } "> ${ $db1dd60e5389e0c9$export$c6f77ec2633c38b1 ( ennoblement . village . name , ennoblement . village . x , ennoblement . village . y ) } </a></td> ` ;
else rowHTML += '<td>-</td>' ;
rowHTML += $5d71a092de4ef3d0$var$getPlayerTd ( ennoblement . newOwner , ennoblement . newOwnerTribe ) ;
rowHTML += $5d71a092de4ef3d0$var$getPlayerTd ( ennoblement . oldOwner , ennoblement . oldOwnerTribe ) ;
return rowHTML + '</tr>' ;
} ) . join ( '' ) }
< / t b o d y >
< / t a b l e >
` ;
$20636c16dad2c11a$export$2e2bcd8739ae039 ( {
e : e ,
title : $5d71a092de4ef3d0$var$translations . title ,
id : 'ennoblements' ,
html : html
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
document . querySelectorAll ( '#' + $5d71a092de4ef3d0$var$PAGINATION _CONTAINER _ID + ' a' ) . forEach ( ( el ) => {
el . addEventListener ( 'click' , onPageChange ) ;
2021-06-12 05:26:55 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
} ;
// ==UserScript==
// @name Extended village profile
// @namespace https://github.com/tribalwarshelp/scripts
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedVillageProfile.js
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedVillageProfile.js
// @version 0.7.8
// @description Extended village profile
// @author Kichiyaki https://dwysokinski.me/
// @match *://*/game.php*screen=info_village*
// @grant none
// @run-at document-end
// ==/UserScript==
const $5206cf4fa105cda6$var$SERVER = $9412d55e353d4b8b$export$2e2bcd8739ae039 ( ) ;
const $5206cf4fa105cda6$var$VILLAGE _ID = $c1259165cf39ac5b$export$2e2bcd8739ae039 ( window . location . search ) ;
const $5206cf4fa105cda6$var$LAST _CONQUER _QUERY = `
query ennoblements ( $server : String ! , $limit : Int , $sort : [ String ! ] , $filter : EnnoblementFilter ! ) {
ennoblements ( server : $server , limit : $limit , sort : $sort , filter : $filter ) {
items {
ennobledAt
village {
id
}
}
}
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
` ;
const $5206cf4fa105cda6$var$ENNOBLEMENTS _QUERY = `
query ennoblements ( $server : String ! , $offset : Int , $limit : Int , $sort : [ String ! ] , $filter : EnnoblementFilter ! ) {
ennoblements ( server : $server , offset : $offset , limit : $limit , sort : $sort , filter : $filter ) {
total
items {
village {
id
name
x
y
}
oldOwner {
id
name
}
oldOwnerTribe {
id
tag
}
newOwner {
id
name
}
newOwnerTribe {
id
tag
}
ennobledAt
}
2021-06-12 05:26:55 +00:00
}
}
2021-10-17 11:02:02 +00:00
` ;
const $5206cf4fa105cda6$var$ENNOBLEMENTS _PER _PAGE = 15 ;
const $5206cf4fa105cda6$var$CURR _SERVER _CONFIG = `
query server ( $key : String ! ) {
server ( key : $key ) {
config {
speed
}
unitConfig {
spear {
pop
}
sword {
pop
}
axe {
pop
}
archer {
pop
}
spy {
pop
}
light {
pop
}
marcher {
pop
}
heavy {
pop
}
ram {
pop
}
catapult {
pop
}
knight {
pop
}
snob {
pop
}
}
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
}
` ;
const $5206cf4fa105cda6$var$SERVER _CONFIG _LOCAL _STORAGE _KEY = 'kiszkowaty_extended_village_profile_server_cfg' ;
const $5206cf4fa105cda6$var$actionContainer = document . querySelector ( '#content_value > table > tbody > tr > td:nth-child(1) > table:nth-child(2) > tbody' ) ;
const $5206cf4fa105cda6$var$additionalInfoContainer = document . querySelector ( '#content_value table.vis tbody' ) ;
let $5206cf4fa105cda6$var$serverConfig = {
} ;
const $5206cf4fa105cda6$var$translations = $880b3d6f803ef712$export$2e2bcd8739ae039 ( ) ;
const $5206cf4fa105cda6$var$loadConfigFromLocalStorage = ( ) => {
return $362bcac9fa8968ec$export$f92dfeb71e9bb569 ( $5206cf4fa105cda6$var$SERVER _CONFIG _LOCAL _STORAGE _KEY ) ;
} ;
const $5206cf4fa105cda6$var$cacheServerConfig = ( data = {
} ) => {
$362bcac9fa8968ec$export$8a8216c44337cd5 ( $5206cf4fa105cda6$var$SERVER _CONFIG _LOCAL _STORAGE _KEY , data ) ;
} ;
const $5206cf4fa105cda6$var$isConfigExpired = ( date ) => {
return Math . abs ( date . getTime ( ) - new Date ( ) . getTime ( ) ) > 86400000 ;
} ;
const $5206cf4fa105cda6$var$loadConfig = async ( ) => {
let data = $5206cf4fa105cda6$var$loadConfigFromLocalStorage ( ) ;
if ( ! data . server || $5206cf4fa105cda6$var$isConfigExpired ( new Date ( data . loadedAt ) ) || ! data . server . unitConfig || ! data . server . config ) {
data = await $902f167bfdc7b30b$export$2e2bcd8739ae039 ( {
query : $5206cf4fa105cda6$var$CURR _SERVER _CONFIG ,
variables : {
key : $5206cf4fa105cda6$var$SERVER
}
} ) ;
data . loadedAt = new Date ( ) ;
$5206cf4fa105cda6$var$cacheServerConfig ( data ) ;
2020-08-13 07:47:25 +00:00
}
2021-06-12 05:26:55 +00:00
return data . server ;
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$loadPageData = async ( ) => {
let data = await $902f167bfdc7b30b$export$2e2bcd8739ae039 ( {
query : $5206cf4fa105cda6$var$LAST _CONQUER _QUERY ,
variables : {
server : $5206cf4fa105cda6$var$SERVER ,
filter : {
villageID : [
$5206cf4fa105cda6$var$VILLAGE _ID
]
} ,
sort : [
'ennobledAt DESC'
] ,
limit : 1
}
2020-07-18 10:38:26 +00:00
} ) ;
2021-06-12 05:26:55 +00:00
return data ;
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$handleShowTribeEnnoblementsClick = async ( e ) => {
2021-06-12 05:26:55 +00:00
e . preventDefault ( ) ;
2021-10-17 11:02:02 +00:00
const page = $57fe06ddde7dcd5d$export$c2a6433281518c91 ( e . target ) ;
2021-06-12 05:26:55 +00:00
if ( ! isNaN ( page ) ) {
2021-10-17 11:02:02 +00:00
const data = await $902f167bfdc7b30b$export$2e2bcd8739ae039 ( {
query : $5206cf4fa105cda6$var$ENNOBLEMENTS _QUERY ,
variables : {
filter : {
villageID : [
$5206cf4fa105cda6$var$VILLAGE _ID
]
} ,
offset : $5206cf4fa105cda6$var$ENNOBLEMENTS _PER _PAGE * ( page - 1 ) ,
limit : $5206cf4fa105cda6$var$ENNOBLEMENTS _PER _PAGE ,
sort : [
'ennobledAt DESC'
] ,
server : $5206cf4fa105cda6$var$SERVER
}
} ) ;
$5d71a092de4ef3d0$export$2e2bcd8739ae039 ( e , data . ennoblements , {
currentPage : page ,
limit : $5206cf4fa105cda6$var$ENNOBLEMENTS _PER _PAGE ,
onPageChange : $5206cf4fa105cda6$var$handleShowTribeEnnoblementsClick
} ) ;
2020-08-07 13:50:26 +00:00
}
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$buildCellsForIncSupport = ( units ) => {
2021-06-12 05:26:55 +00:00
const cells = [ ] ;
let pop = 0 ;
2021-10-17 11:02:02 +00:00
for ( let unit in units ) {
pop += units [ unit ] * $5206cf4fa105cda6$var$serverConfig . unitConfig [ unit ] . pop ;
cells . push ( ` <td> ${ units [ unit ] . toLocaleString ( ) } </td> ` ) ;
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
cells . push ( ` <td><strong> ${ pop . toLocaleString ( ) } </strong></td> ` ) ;
2021-06-12 05:26:55 +00:00
return cells ;
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$handleCountIncomingSupportClick = async ( e ) => {
2021-06-12 05:26:55 +00:00
e . preventDefault ( ) ;
const ids = [ ] ;
2021-10-17 11:02:02 +00:00
const allyCommand = {
} ;
document . querySelectorAll ( 'span.command_hover_details[data-command-type="support"]' ) . forEach ( ( el ) => {
const id = parseInt ( el . getAttribute ( 'data-command-id' ) ) ;
if ( el . classList . contains ( 'commandicon-ally' ) ) allyCommand [ id ] = true ;
else allyCommand [ id ] = false ;
ids . push ( id ) ;
2020-08-07 13:50:26 +00:00
} ) ;
2021-06-12 05:26:55 +00:00
const mySupport = {
2021-10-17 11:02:02 +00:00
spear : 0 ,
sword : 0 ,
axe : 0 ,
archer : 0 ,
spy : 0 ,
light : 0 ,
marcher : 0 ,
heavy : 0 ,
ram : 0 ,
catapult : 0 ,
knight : 0 ,
snob : 0
2021-06-12 05:26:55 +00:00
} ;
2021-10-17 11:02:02 +00:00
const allySupport = $f1e9793517c51c58$export$2e2bcd8739ae039 ( {
} , mySupport ) ;
const total = $f1e9793517c51c58$export$2e2bcd8739ae039 ( {
} , mySupport ) ;
for ( let i = 0 ; i < ids . length ; i ++ ) {
Dialog . show ( 'incomingSupport' , ` ${ $5206cf4fa105cda6$var$translations . loaded } : <strong> ${ i } / ${ ids . length } </strong> ` ) ;
const id = ids [ i ] ;
const url = TribalWars . buildURL ( '' , {
screen : 'info_command' ,
ajax : 'details' ,
id : id
} ) ;
try {
const resp = await fetch ( url ) ;
const { units : units } = await resp . json ( ) ;
if ( units ) for ( let unit in mySupport ) {
const count = parseInt ( units [ unit ] . count ) ;
if ( allyCommand [ id ] ) allySupport [ unit ] += count ;
else mySupport [ unit ] += count ;
total [ unit ] += count ;
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
await $fc029eaf0e980c2d$export$2e2bcd8739ae039 ( 200 ) ;
} catch ( error ) {
console . log ( 'count incoming support' , error ) ;
2020-08-07 13:50:26 +00:00
}
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
const ths = [
'<th></th>'
] ;
for ( let unit in mySupport ) ths . push ( ` <th><img src=" ${ $3cc0f054d48dddd4$export$2e2bcd8739ae039 ( unit ) } " /></th> ` ) ;
ths . push ( ` <th> ${ $5206cf4fa105cda6$var$translations . pop } </th> ` ) ;
const mySupportCells = [
` <th> ${ $5206cf4fa105cda6$var$translations . mySupport } </th> ` ,
... $5206cf4fa105cda6$var$buildCellsForIncSupport ( mySupport ) ,
] ;
const allySupportCells = [
` <th> ${ $5206cf4fa105cda6$var$translations . allySupport } </th> ` ,
... $5206cf4fa105cda6$var$buildCellsForIncSupport ( allySupport ) ,
] ;
const totalCells = [
` <th> ${ $5206cf4fa105cda6$var$translations . total } </th> ` ,
... $5206cf4fa105cda6$var$buildCellsForIncSupport ( total ) ,
] ;
Dialog . show ( 'incomingSupport' , `
< table class = "vis" style = "width: 100%;" >
< tbody >
< tr >
$ { ths . join ( '' ) }
< / t r >
< tr >
$ { mySupportCells . join ( '' ) }
< / t r >
< tr >
$ { allySupportCells . join ( '' ) }
< / t r >
< tr >
$ { totalCells . join ( '' ) }
< / t r >
< / t b o d y >
< / t a b l e >
` );
2021-06-12 05:26:55 +00:00
const popup = document . querySelector ( '.popup_box' ) ;
if ( popup ) {
2021-10-17 11:02:02 +00:00
popup . style . width = 'auto' ;
popup . style . maxWidth = '900px' ;
2021-06-12 05:26:55 +00:00
}
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$wrapAction = ( action ) => {
2021-06-12 05:26:55 +00:00
const actionWrapperTd = document . createElement ( 'td' ) ;
actionWrapperTd . colSpan = '2' ;
actionWrapperTd . append ( action ) ;
const actionWrapperTr = document . createElement ( 'tr' ) ;
actionWrapperTr . appendChild ( actionWrapperTd ) ;
return actionWrapperTr ;
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$renderActions = ( ) => {
2021-06-12 05:26:55 +00:00
const linkToTWHelp = document . createElement ( 'a' ) ;
2021-10-17 11:02:02 +00:00
linkToTWHelp . href = $f3b273bd698d94bc$export$e537a41a0fc85cc5 ( $5b3edb3901c8177a$export$2e2bcd8739ae039 ( $5206cf4fa105cda6$var$SERVER ) , $5206cf4fa105cda6$var$SERVER , $5206cf4fa105cda6$var$VILLAGE _ID ) ;
linkToTWHelp . innerHTML = $5206cf4fa105cda6$var$translations . action . linkToTWHelp ;
$5206cf4fa105cda6$var$actionContainer . appendChild ( $5206cf4fa105cda6$var$wrapAction ( linkToTWHelp ) ) ;
2021-06-12 05:26:55 +00:00
const showEnnoblementsPopup = document . createElement ( 'a' ) ;
showEnnoblementsPopup . href = '#' ;
2021-10-17 11:02:02 +00:00
$57fe06ddde7dcd5d$export$5e830c5f3cd8a610 ( showEnnoblementsPopup , '1' ) ;
showEnnoblementsPopup . innerHTML = $5206cf4fa105cda6$var$translations . action . showEnnoblements ;
showEnnoblementsPopup . addEventListener ( 'click' , $5206cf4fa105cda6$var$handleShowTribeEnnoblementsClick ) ;
$5206cf4fa105cda6$var$actionContainer . appendChild ( $5206cf4fa105cda6$var$wrapAction ( showEnnoblementsPopup ) ) ;
2021-06-12 05:26:55 +00:00
const countIncomingSupport = document . createElement ( 'a' ) ;
countIncomingSupport . href = '#' ;
2021-10-17 11:02:02 +00:00
countIncomingSupport . innerHTML = $5206cf4fa105cda6$var$translations . action . countIncomingSupport ;
countIncomingSupport . addEventListener ( 'click' , $5206cf4fa105cda6$var$handleCountIncomingSupportClick ) ;
$5206cf4fa105cda6$var$actionContainer . appendChild ( $5206cf4fa105cda6$var$wrapAction ( countIncomingSupport ) ) ;
} ;
const $5206cf4fa105cda6$var$renderTr = ( { title : title , data : data , id : id } ) => {
2021-06-12 05:26:55 +00:00
let tr = document . querySelector ( '#' + id ) ;
if ( ! tr ) {
2021-10-17 11:02:02 +00:00
tr = document . createElement ( 'tr' ) ;
tr . id = id ;
tr . appendChild ( document . createElement ( 'td' ) ) ;
tr . appendChild ( document . createElement ( 'td' ) ) ;
$5206cf4fa105cda6$var$additionalInfoContainer . append ( tr ) ;
2021-06-12 05:26:55 +00:00
}
tr . children [ 0 ] . innerHTML = title ;
tr . children [ 1 ] . innerHTML = data ;
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$countUnitsInVillage = ( ) => {
2021-06-12 05:26:55 +00:00
const trs = document . querySelectorAll ( '#content_value > div tbody tr' ) ;
const units = [ ] ;
if ( trs . length === 0 ) throw new Error ( ) ;
2021-10-17 11:02:02 +00:00
trs [ 0 ] . querySelectorAll ( '.unit_link' ) . forEach ( ( ) => {
units . push ( 0 ) ;
2020-08-16 14:33:40 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
for ( let i = 1 ; i < trs . length ; i ++ ) {
const tr = trs [ i ] ;
tr . querySelectorAll ( '.unit-item' ) . forEach ( ( td , index ) => {
units [ index ] += parseInt ( td . innerHTML ) ;
} ) ;
2021-06-12 05:26:55 +00:00
}
return units ;
2021-10-17 11:02:02 +00:00
} ;
const $5206cf4fa105cda6$var$renderAdditionalInfo = ( { config : config , ennoblements : ennoblements } = {
} ) => {
2021-06-12 05:26:55 +00:00
const firstEnnoblement = ennoblements && Array . isArray ( ennoblements . items ) && ennoblements . items [ 0 ] ? ennoblements . items [ 0 ] : undefined ;
2021-10-17 11:02:02 +00:00
$5206cf4fa105cda6$var$renderTr ( {
id : 'loyalty' ,
title : ` ${ $5206cf4fa105cda6$var$translations . possibleLoyalty } : ` ,
data : firstEnnoblement ? $8e88e9cb6c51e781$export$2e2bcd8739ae039 ( new Date ( firstEnnoblement . ennobledAt ) , config . speed ) : 100
2020-08-16 14:33:40 +00:00
} ) ;
2021-10-17 11:02:02 +00:00
$5206cf4fa105cda6$var$renderTr ( {
id : 'ennobledAt' ,
title : ` ${ $5206cf4fa105cda6$var$translations . ennobledAt } : ` ,
data : firstEnnoblement ? $ca7593443ca49f96$export$3ae94a2503e890a1 ( firstEnnoblement . ennobledAt ) : $5206cf4fa105cda6$var$translations . never
2020-08-13 07:47:25 +00:00
} ) ;
2021-06-12 05:26:55 +00:00
try {
2021-10-17 11:02:02 +00:00
const units = $5206cf4fa105cda6$var$countUnitsInVillage ( ) ;
const tr = document . createElement ( 'tr' ) ;
tr . style . textAlign = 'center' ;
tr . style . fontWeight = 'bold' ;
tr . appendChild ( document . createElement ( 'td' ) ) ;
units . forEach ( ( count ) => {
const td = document . createElement ( 'td' ) ;
td . innerHTML = count ;
tr . appendChild ( td ) ;
} ) ;
document . querySelector ( '#content_value > div tbody' ) . appendChild ( tr ) ;
} catch ( error ) {
}
} ;
( async function ( ) {
2021-06-12 05:26:55 +00:00
try {
2021-10-17 11:02:02 +00:00
const pageData = await $5206cf4fa105cda6$var$loadPageData ( ) ;
$5206cf4fa105cda6$var$serverConfig = await $5206cf4fa105cda6$var$loadConfig ( ) ;
$5206cf4fa105cda6$var$renderAdditionalInfo ( {
config : $5206cf4fa105cda6$var$serverConfig . config ,
ennoblements : pageData . ennoblements
} ) ;
$5206cf4fa105cda6$var$renderActions ( ) ;
2021-06-12 05:26:55 +00:00
} catch ( error ) {
2021-10-17 11:02:02 +00:00
console . log ( 'extended village profile' , error ) ;
2021-06-12 05:26:55 +00:00
}
2020-07-18 10:38:26 +00:00
} ) ( ) ;
2021-06-12 05:26:55 +00:00
2021-10-17 11:02:02 +00:00
} ) ( ) ;