2020-08-05 19:10:42 +00:00
|
|
|
import InADayParser from './libs/InADayParser';
|
2020-07-11 12:08:43 +00:00
|
|
|
import requestCreator from './libs/requestCreator';
|
2020-07-22 15:02:49 +00:00
|
|
|
import getTranslations from './i18n/extendedPlayerProfile';
|
2020-07-22 14:19:44 +00:00
|
|
|
import renderTodaysStats from './common/renderTodaysStats';
|
2020-07-20 12:07:57 +00:00
|
|
|
import showPopup from './utils/showPopup';
|
2020-07-22 14:19:44 +00:00
|
|
|
import showEnnoblementsPopup from './common/showEnnoblementsPopup';
|
|
|
|
import showHistoryPopup from './common/showHistoryPopup';
|
2020-09-17 10:26:43 +00:00
|
|
|
import hyphensToCamelCase from './utils/hyphensToCamelCase';
|
2020-07-17 13:43:28 +00:00
|
|
|
import {
|
|
|
|
generatePaginationItems,
|
|
|
|
getContainerStyles,
|
|
|
|
setPage,
|
|
|
|
getPage,
|
|
|
|
} from './utils/pagination';
|
2020-07-11 12:08:43 +00:00
|
|
|
import getIDFromURL from './utils/getIDFromURL';
|
|
|
|
import getCurrentServer from './utils/getCurrentServer';
|
2021-01-01 17:03:36 +00:00
|
|
|
import getServerVersionCode from './utils/getServerVersionCode';
|
2021-01-17 15:21:47 +00:00
|
|
|
import { formatDate } from './utils/date';
|
2021-01-03 12:13:05 +00:00
|
|
|
import * as twutils from './utils/tribalwars';
|
2021-01-02 15:01:07 +00:00
|
|
|
import * as twhelputils from './utils/twhelp';
|
2020-07-11 12:08:43 +00:00
|
|
|
import { setItem, getItem } from './utils/localStorage';
|
|
|
|
|
2020-07-11 10:08:26 +00:00
|
|
|
// ==UserScript==
|
2020-08-14 11:53:56 +00:00
|
|
|
// @name Extended player profile
|
2020-07-12 18:28:46 +00:00
|
|
|
// @namespace https://github.com/tribalwarshelp/scripts
|
2020-07-12 17:29:58 +00:00
|
|
|
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
|
2020-09-17 10:26:43 +00:00
|
|
|
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
|
2021-05-08 16:41:04 +00:00
|
|
|
// @version 1.2.1
|
2020-08-14 11:53:56 +00:00
|
|
|
// @description Extended player profile
|
2021-01-17 08:20:19 +00:00
|
|
|
// @author Kichiyaki https://dwysokinski.me/
|
2020-07-19 19:35:07 +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 = getCurrentServer();
|
2021-01-02 15:01:07 +00:00
|
|
|
const VERSION = getServerVersionCode(SERVER);
|
2020-07-11 12:08:43 +00:00
|
|
|
let PLAYER_ID = getIDFromURL(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-11 18:44:52 +00:00
|
|
|
const PLAYER_QUERY = `
|
2020-11-21 14:01:40 +00:00
|
|
|
query player($server: String!, $id: Int!, $limit: Int, $sort: [String!], $filter: DailyPlayerStatsFilter) {
|
2020-07-11 10:08:26 +00:00
|
|
|
player(server: $server, id: $id) {
|
|
|
|
id
|
2020-07-11 12:08:43 +00:00
|
|
|
name
|
2020-07-12 10:01:43 +00:00
|
|
|
bestRank
|
|
|
|
bestRankAt
|
|
|
|
mostPoints
|
|
|
|
mostPointsAt
|
|
|
|
mostVillages
|
|
|
|
mostVillagesAt
|
2020-07-11 10:08:26 +00:00
|
|
|
servers
|
2020-07-11 12:08:43 +00:00
|
|
|
joinedAt
|
2020-07-11 10:08:26 +00:00
|
|
|
nameChanges {
|
|
|
|
oldName
|
|
|
|
newName
|
2020-07-11 12:08:43 +00:00
|
|
|
changeDate
|
2020-07-11 10:08:26 +00:00
|
|
|
}
|
|
|
|
dailyGrowth
|
|
|
|
}
|
2020-11-21 14:01:40 +00:00
|
|
|
dailyPlayerStats(server: $server, limit: $limit, sort: $sort, filter: $filter) {
|
2020-07-11 14:25:10 +00:00
|
|
|
items {
|
|
|
|
rank
|
|
|
|
rankAtt
|
|
|
|
rankDef
|
|
|
|
rankSup
|
|
|
|
rankTotal
|
|
|
|
points
|
|
|
|
scoreAtt
|
|
|
|
scoreAtt
|
|
|
|
scoreDef
|
|
|
|
scoreSup
|
|
|
|
scoreTotal
|
|
|
|
villages
|
|
|
|
}
|
|
|
|
}
|
2020-07-11 10:08:26 +00:00
|
|
|
}
|
|
|
|
`;
|
2020-07-11 18:44:52 +00:00
|
|
|
const TRIBE_CHANGES_QUERY = `
|
2020-11-21 14:01:40 +00:00
|
|
|
query tribeChanges($server: String!, $limit: Int, $offset: Int, $sort: [String!], $filter: TribeChangeFilter!) {
|
|
|
|
tribeChanges(server: $server, limit: $limit, offset: $offset, sort: $sort, filter: $filter) {
|
2020-07-11 18:44:52 +00:00
|
|
|
total
|
|
|
|
items {
|
|
|
|
oldTribe {
|
|
|
|
id
|
|
|
|
tag
|
|
|
|
}
|
|
|
|
newTribe {
|
|
|
|
id
|
|
|
|
tag
|
|
|
|
}
|
|
|
|
createdAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
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 = `
|
|
|
|
query playerHistoryAndPlayerDailyStats($server: String!,
|
|
|
|
$playerHistoryFilter: PlayerHistoryFilter!,
|
2020-11-21 14:01:40 +00:00
|
|
|
$dailyPlayerStatsFilter: DailyPlayerStatsFilter!,
|
|
|
|
$limit: Int,
|
|
|
|
$offset: Int,
|
|
|
|
$sort: [String!]) {
|
|
|
|
playerHistory(server: $server, limit: $limit, offset: $offset, sort: $sort, filter: $playerHistoryFilter) {
|
2020-07-15 18:55:24 +00:00
|
|
|
total
|
|
|
|
items {
|
|
|
|
totalVillages
|
|
|
|
points
|
|
|
|
rank
|
|
|
|
scoreAtt
|
|
|
|
rankAtt
|
|
|
|
scoreDef
|
|
|
|
rankDef
|
|
|
|
scoreSup
|
|
|
|
rankSup
|
|
|
|
scoreTotal
|
|
|
|
rankTotal
|
|
|
|
tribe {
|
|
|
|
id
|
|
|
|
tag
|
|
|
|
}
|
|
|
|
createDate
|
|
|
|
}
|
|
|
|
}
|
2020-11-21 14:01:40 +00:00
|
|
|
dailyPlayerStats(server: $server, limit: $limit, offset: $offset, sort: $sort, filter: $dailyPlayerStatsFilter) {
|
2020-07-15 18:55:24 +00:00
|
|
|
items {
|
|
|
|
points
|
|
|
|
scoreAtt
|
|
|
|
scoreAtt
|
|
|
|
scoreDef
|
|
|
|
scoreSup
|
|
|
|
scoreTotal
|
|
|
|
villages
|
|
|
|
createDate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
const PLAYER_HISTORY_PER_PAGE = 15;
|
2020-07-17 10:58:08 +00:00
|
|
|
const ENNOBLEMENTS_QUERY = `
|
2020-11-21 14:01:40 +00:00
|
|
|
query ennoblements($server: String!, $limit: Int, $offset: Int, $sort: [String!], $filter: EnnoblementFilter!) {
|
|
|
|
ennoblements(server: $server, limit: $limit, offset: $offset, sort: $sort, filter: $filter) {
|
2020-07-17 10:58:08 +00:00
|
|
|
total
|
|
|
|
items {
|
|
|
|
village {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
x
|
|
|
|
y
|
|
|
|
}
|
|
|
|
oldOwner {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
oldOwnerTribe {
|
|
|
|
id
|
|
|
|
tag
|
|
|
|
}
|
|
|
|
newOwner {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
newOwnerTribe {
|
|
|
|
id
|
|
|
|
tag
|
|
|
|
}
|
|
|
|
ennobledAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
const ENNOBLEMENTS_PER_PAGE = 15;
|
2020-07-15 18:55:24 +00:00
|
|
|
|
2020-07-11 13:14:29 +00:00
|
|
|
const profileInfoTBody = document.querySelector('#player_info > tbody');
|
2020-07-20 12:07:57 +00:00
|
|
|
const actionContainer =
|
2020-07-11 18:44:52 +00:00
|
|
|
PLAYER_ID === CURRENT_PLAYER_ID
|
|
|
|
? profileInfoTBody
|
|
|
|
: document.querySelector(
|
|
|
|
'#content_value > table > tbody > tr > td:nth-child(1) > table:nth-child(2) > tbody'
|
|
|
|
);
|
2020-07-20 12:07:57 +00:00
|
|
|
const otherElementContainer = document.querySelector(
|
2020-07-11 13:14:29 +00:00
|
|
|
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-22 15:02:49 +00:00
|
|
|
const translations = getTranslations();
|
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 getItem(LOCAL_STORAGE_KEY);
|
|
|
|
};
|
|
|
|
|
|
|
|
const cachePlayerData = (data = {}) => {
|
|
|
|
setItem(LOCAL_STORAGE_KEY, data);
|
|
|
|
};
|
|
|
|
|
2020-08-05 19:10:42 +00:00
|
|
|
const loadInADayData = async (type, { name, ...rest } = {}) => {
|
|
|
|
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(html, rest).parse();
|
|
|
|
if (res.length === 0) {
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
return res[0];
|
|
|
|
} catch (error) {
|
|
|
|
return {
|
|
|
|
rank: 0,
|
|
|
|
playerID: 0,
|
|
|
|
score: 0,
|
|
|
|
tribeID: 0,
|
|
|
|
tribe: '',
|
|
|
|
date: new Date(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-11 14:25:10 +00:00
|
|
|
const loadData = async () => {
|
2020-07-11 12:08:43 +00:00
|
|
|
const data = await requestCreator({
|
2020-07-11 18:44:52 +00:00
|
|
|
query: PLAYER_QUERY,
|
2020-07-11 12:08:43 +00:00
|
|
|
variables: {
|
|
|
|
server: SERVER,
|
|
|
|
id: PLAYER_ID,
|
2020-11-21 14:01:40 +00:00
|
|
|
limit: 1,
|
|
|
|
sort: ['createDate DESC'],
|
2020-07-11 14:25:10 +00:00
|
|
|
filter: {
|
|
|
|
playerID: [PLAYER_ID],
|
|
|
|
},
|
2020-07-11 12:08:43 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (data.player) {
|
|
|
|
const inADay = {};
|
2020-09-17 10:26:43 +00:00
|
|
|
const filter = {
|
2020-07-12 16:17:25 +00:00
|
|
|
name: data.player.name,
|
|
|
|
playerID: data.player.id,
|
2020-09-17 10:26:43 +00:00
|
|
|
};
|
|
|
|
for (let type of [
|
|
|
|
'kill_att',
|
|
|
|
'kill_def',
|
|
|
|
'kill_sup',
|
|
|
|
'loot_res',
|
|
|
|
'loot_vil',
|
|
|
|
'scavenge',
|
|
|
|
'conquer',
|
|
|
|
]) {
|
2021-06-12 05:26:55 +00:00
|
|
|
inADay[hyphensToCamelCase(type.replace('kill_', ''))] =
|
|
|
|
await loadInADayData(type, filter);
|
2020-09-17 10:26:43 +00:00
|
|
|
}
|
2020-07-11 12:08:43 +00:00
|
|
|
data.player.inADay = inADay;
|
|
|
|
}
|
|
|
|
cachePlayerData(data);
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTr = ({ title, data, id }) => {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const renderPlayerServers = player => {
|
2020-07-11 13:14:29 +00:00
|
|
|
let playerServers = document.querySelector('#playerServers');
|
|
|
|
if (!playerServers) {
|
|
|
|
playerServers = document.createElement('table');
|
|
|
|
playerServers.id = 'playerServers';
|
|
|
|
playerServers.classList.add('vis');
|
|
|
|
playerServers.width = '100%';
|
|
|
|
playerServers.innerHTML = `
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.playerServers}
|
2020-07-11 13:14:29 +00:00
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
`;
|
2020-07-20 12:07:57 +00:00
|
|
|
otherElementContainer.prepend(playerServers);
|
2020-07-11 13:14:29 +00:00
|
|
|
}
|
|
|
|
playerServers.querySelector('td').innerHTML = player.servers
|
2020-07-11 14:25:10 +00:00
|
|
|
.sort()
|
2020-07-11 13:14:29 +00:00
|
|
|
.map(
|
2021-02-26 17:04:05 +00:00
|
|
|
server =>
|
2021-01-14 16:51:10 +00:00
|
|
|
`<a target="_blank" style="margin-right: 5px" href="${twhelputils.buildPlayerURL(
|
2021-01-02 15:01:07 +00:00
|
|
|
VERSION,
|
2020-07-11 13:14:29 +00:00
|
|
|
server,
|
|
|
|
player.id
|
|
|
|
)}">${server}</a>`
|
|
|
|
)
|
|
|
|
.join('');
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const renderPlayerOtherNames = player => {
|
2020-07-11 13:14:29 +00:00
|
|
|
let playerOtherNames = document.querySelector('#playerOtherNames');
|
|
|
|
if (!playerOtherNames) {
|
|
|
|
playerOtherNames = document.createElement('div');
|
|
|
|
playerOtherNames.id = 'playerOtherNames';
|
|
|
|
playerOtherNames.width = '100%';
|
2020-07-20 12:07:57 +00:00
|
|
|
otherElementContainer.prepend(playerOtherNames);
|
2020-07-11 13:14:29 +00:00
|
|
|
}
|
|
|
|
playerOtherNames.innerHTML = `
|
|
|
|
<table width="100%" class="vis">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.oldName}
|
2020-07-11 13:14:29 +00:00
|
|
|
</th>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.newName}
|
2020-07-11 13:14:29 +00:00
|
|
|
</th>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.date}
|
2020-07-11 13:14:29 +00:00
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
${player.nameChanges
|
2021-02-26 17:04:05 +00:00
|
|
|
.map(nameChange => {
|
2020-07-11 13:14:29 +00:00
|
|
|
return `
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
${nameChange.oldName}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${nameChange.newName}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${formatDate(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
|
|
|
})}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`;
|
|
|
|
})
|
|
|
|
.join('')}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const renderInADayRanks = player => {
|
2020-07-11 15:57:05 +00:00
|
|
|
let inADayRanks = document.querySelector('#inADayRanks');
|
|
|
|
if (!inADayRanks) {
|
|
|
|
inADayRanks = document.createElement('div');
|
|
|
|
inADayRanks.id = 'inADayRanks';
|
|
|
|
inADayRanks.width = '100%';
|
2020-07-20 12:07:57 +00:00
|
|
|
otherElementContainer.prepend(inADayRanks);
|
2020-07-11 15:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inADayRanks.innerHTML = `
|
|
|
|
<table width="100%" class="vis">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<th colspan="2">
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.inADayBestScores}
|
2020-07-11 15:57:05 +00:00
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.unitsDefeatedWhileAttacking}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.att.score.toLocaleString()} (${
|
|
|
|
player.inADay.att.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.unitsDefeatedWhileDefending}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.def.score.toLocaleString()} (${
|
|
|
|
player.inADay.def.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.unitsDefeatedWhileSupporting}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.sup.score.toLocaleString()} (${
|
|
|
|
player.inADay.sup.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.resourcesPlundered}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.lootRes.score.toLocaleString()} (${
|
|
|
|
player.inADay.lootRes.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.villagesPlundered}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.lootVil.score.toLocaleString()} (${
|
|
|
|
player.inADay.lootVil.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.resourcesGathered}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.scavenge.score.toLocaleString()} (${
|
|
|
|
player.inADay.scavenge.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.villagesConquered}
|
2020-07-11 15:57:05 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
${player.inADay.conquer.score.toLocaleString()} (${
|
|
|
|
player.inADay.conquer.rank
|
|
|
|
}.)
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
2020-07-11 14:25:10 +00:00
|
|
|
const render = ({ player, dailyPlayerStats }) => {
|
2020-07-11 12:08:43 +00:00
|
|
|
[
|
|
|
|
{
|
2020-07-22 15:02:49 +00:00
|
|
|
title: translations.joinedAt + ':',
|
2020-07-11 12:08:43 +00:00
|
|
|
data: formatDate(player.joinedAt),
|
|
|
|
id: 'joined_at',
|
|
|
|
},
|
|
|
|
{
|
2020-07-22 15:02:49 +00:00
|
|
|
title: translations.dailyGrowth + ':',
|
2020-07-11 12:08:43 +00:00
|
|
|
data: player.dailyGrowth.toLocaleString(),
|
|
|
|
id: 'dg',
|
|
|
|
},
|
2020-07-12 10:01:43 +00:00
|
|
|
{
|
2020-07-22 15:02:49 +00:00
|
|
|
title: translations.bestRank + ':',
|
2020-07-12 10:01:43 +00:00
|
|
|
data: player.bestRank + ' ' + `(${formatDate(player.bestRankAt)})`,
|
|
|
|
id: 'best_rank',
|
|
|
|
},
|
|
|
|
{
|
2020-07-22 15:02:49 +00:00
|
|
|
title: translations.mostPoints + ':',
|
2020-07-17 11:50:29 +00:00
|
|
|
data:
|
|
|
|
player.mostPoints.toLocaleString() +
|
|
|
|
' ' +
|
|
|
|
`(${formatDate(player.mostPointsAt)})`,
|
2020-07-12 10:01:43 +00:00
|
|
|
id: 'most_points',
|
|
|
|
},
|
|
|
|
{
|
2020-07-22 15:02:49 +00:00
|
|
|
title: translations.mostVillages + ':',
|
2020-07-12 10:01:43 +00:00
|
|
|
data:
|
|
|
|
player.mostVillages + ' ' + `(${formatDate(player.mostVillagesAt)})`,
|
|
|
|
id: 'most_villages',
|
|
|
|
},
|
2021-02-26 17:04:05 +00:00
|
|
|
].forEach(data => {
|
2020-07-11 12:08:43 +00:00
|
|
|
renderTr(data);
|
|
|
|
});
|
2020-07-11 13:14:29 +00:00
|
|
|
|
2020-07-11 15:57:05 +00:00
|
|
|
renderInADayRanks(player);
|
2020-07-11 14:25:10 +00:00
|
|
|
if (dailyPlayerStats && dailyPlayerStats.items.length > 0) {
|
2020-07-20 12:07:57 +00:00
|
|
|
renderTodaysStats(otherElementContainer, 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-11 18:44:52 +00:00
|
|
|
const renderTribeChanges = (e, currentPage, tribeChanges) => {
|
2020-07-15 18:55:24 +00:00
|
|
|
const paginationItems = generatePaginationItems({
|
|
|
|
total: tribeChanges.total,
|
|
|
|
limit: TRIBE_CHANGES_PER_PAGE,
|
|
|
|
currentPage,
|
|
|
|
});
|
2020-07-11 18:44:52 +00:00
|
|
|
const html = `
|
2020-07-17 13:43:28 +00:00
|
|
|
<div style="${getContainerStyles()}" id="${TRIBE_CHANGES_PAGINATION_CONTAINER_ID}">
|
2020-07-11 18:44:52 +00:00
|
|
|
${paginationItems.join('')}
|
|
|
|
</div>
|
2020-07-17 10:58:08 +00:00
|
|
|
<table class="vis" style="border-collapse: separate; border-spacing: 2px; width: 100%;">
|
2020-07-11 18:44:52 +00:00
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.date}
|
2020-07-11 18:44:52 +00:00
|
|
|
</th>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.newTribe}
|
2020-07-11 18:44:52 +00:00
|
|
|
</th>
|
|
|
|
<th>
|
2020-07-22 15:02:49 +00:00
|
|
|
${translations.oldTribe}
|
2020-07-11 18:44:52 +00:00
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
${tribeChanges.items
|
2021-02-26 17:04:05 +00:00
|
|
|
.map(tribeChange => {
|
2020-07-11 18:44:52 +00:00
|
|
|
let rowHTML =
|
|
|
|
'<tr>' + `<td>${formatDate(tribeChange.createdAt)}</td>`;
|
|
|
|
if (tribeChange.newTribe) {
|
2021-01-03 12:13:05 +00:00
|
|
|
rowHTML += `<td><a href="${twutils.buildTribeURL(
|
2020-07-11 18:44:52 +00:00
|
|
|
tribeChange.newTribe.id
|
|
|
|
)}">${tribeChange.newTribe.tag}</a></td>`;
|
|
|
|
} else {
|
|
|
|
rowHTML += '<td>-</td>';
|
|
|
|
}
|
|
|
|
if (tribeChange.oldTribe) {
|
2021-01-03 12:13:05 +00:00
|
|
|
rowHTML += `<td><a href="${twutils.buildTribeURL(
|
2020-07-11 18:44:52 +00:00
|
|
|
tribeChange.oldTribe.id
|
|
|
|
)}">${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('')}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
`;
|
|
|
|
|
2020-07-20 12:07:57 +00:00
|
|
|
showPopup({
|
2020-07-11 18:44:52 +00:00
|
|
|
e,
|
2020-07-22 15:31:27 +00:00
|
|
|
title: translations.tribeChanges,
|
2020-07-11 18:44:52 +00:00
|
|
|
id: 'tribeChanges',
|
|
|
|
html,
|
|
|
|
});
|
|
|
|
|
2020-07-20 12:07:57 +00:00
|
|
|
document
|
|
|
|
.querySelectorAll('#' + TRIBE_CHANGES_PAGINATION_CONTAINER_ID + ' a')
|
2021-02-26 17:04:05 +00:00
|
|
|
.forEach(el => {
|
2020-07-20 12:07:57 +00:00
|
|
|
el.addEventListener('click', handleShowTribeChangesButtonClick);
|
|
|
|
});
|
2020-07-11 18:44:52 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +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 = getPage(e.target);
|
2020-07-11 18:44:52 +00:00
|
|
|
if (!isNaN(page)) {
|
|
|
|
const data = await requestCreator({
|
|
|
|
query: TRIBE_CHANGES_QUERY,
|
|
|
|
variables: {
|
|
|
|
filter: {
|
|
|
|
playerID: [PLAYER_ID],
|
|
|
|
},
|
2020-11-21 14:01:40 +00:00
|
|
|
sort: ['createdAt DESC'],
|
|
|
|
offset: TRIBE_CHANGES_PER_PAGE * (page - 1),
|
|
|
|
limit: TRIBE_CHANGES_PER_PAGE,
|
2020-07-11 18:44:52 +00:00
|
|
|
server: SERVER,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
renderTribeChanges(e, page, data.tribeChanges);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const handleShowPlayerHistoryClick = async e => {
|
2020-07-15 18:55:24 +00:00
|
|
|
e.preventDefault();
|
|
|
|
const page = getPage(e.target);
|
|
|
|
if (!isNaN(page)) {
|
|
|
|
try {
|
|
|
|
const filter = {
|
|
|
|
playerID: [PLAYER_ID],
|
|
|
|
};
|
|
|
|
const { playerHistory, dailyPlayerStats } = await requestCreator({
|
|
|
|
query: PLAYER_HISTORY_AND_PLAYER_DAILY_STATS_QUERY,
|
|
|
|
variables: {
|
|
|
|
server: SERVER,
|
|
|
|
playerHistoryFilter: filter,
|
2020-11-21 14:01:40 +00:00
|
|
|
offset: PLAYER_HISTORY_PER_PAGE * (page - 1),
|
|
|
|
limit: PLAYER_HISTORY_PER_PAGE,
|
|
|
|
sort: ['createDate DESC'],
|
|
|
|
dailyPlayerStatsFilter: filter,
|
2020-07-15 18:55:24 +00:00
|
|
|
},
|
|
|
|
});
|
2020-07-20 12:07:57 +00:00
|
|
|
showHistoryPopup(e, playerHistory, dailyPlayerStats, {
|
2020-07-17 14:13:09 +00:00
|
|
|
currentPage: page,
|
|
|
|
limit: PLAYER_HISTORY_PER_PAGE,
|
|
|
|
onPageChange: handleShowPlayerHistoryClick,
|
|
|
|
tribe: false,
|
|
|
|
});
|
2020-07-15 18:55:24 +00:00
|
|
|
} catch (error) {
|
2021-06-12 05:49:43 +00:00
|
|
|
console.log('couldnt load player history', error);
|
2020-07-15 18:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const handleShowPlayerEnnoblementsClick = async e => {
|
2020-07-17 10:58:08 +00:00
|
|
|
e.preventDefault();
|
|
|
|
const page = getPage(e.target);
|
|
|
|
if (!isNaN(page)) {
|
|
|
|
const data = await requestCreator({
|
|
|
|
query: ENNOBLEMENTS_QUERY,
|
|
|
|
variables: {
|
|
|
|
filter: {
|
|
|
|
or: {
|
|
|
|
oldOwnerID: [PLAYER_ID],
|
|
|
|
newOwnerID: [PLAYER_ID],
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 14:01:40 +00:00
|
|
|
offset: ENNOBLEMENTS_PER_PAGE * (page - 1),
|
|
|
|
limit: ENNOBLEMENTS_PER_PAGE,
|
|
|
|
sort: ['ennobledAt DESC'],
|
2020-07-17 10:58:08 +00:00
|
|
|
server: SERVER,
|
|
|
|
},
|
|
|
|
});
|
2020-07-20 12:07:57 +00:00
|
|
|
showEnnoblementsPopup(e, data.ennoblements, {
|
2020-07-17 13:43:28 +00:00
|
|
|
currentPage: page,
|
|
|
|
limit: ENNOBLEMENTS_PER_PAGE,
|
|
|
|
onPageChange: handleShowPlayerEnnoblementsClick,
|
|
|
|
});
|
2020-07-17 10:58:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const handleExportPlayerVillagesButtonClick = e => {
|
2020-07-12 13:18:49 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
Dialog.show(
|
2020-07-22 15:02:49 +00:00
|
|
|
translations.exportedVillages,
|
2020-07-12 13:18:49 +00:00
|
|
|
`<textarea cols=30 rows=8 readonly>${document
|
|
|
|
.querySelector('#villages_list')
|
|
|
|
.innerHTML.match(/(\d+)\|(\d+)/g)
|
|
|
|
.join(' ')}</textarea>`
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-02-26 17:04:05 +00:00
|
|
|
const wrapAction = action => {
|
2020-07-15 18:55:24 +00:00
|
|
|
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 = () => {
|
2021-01-01 17:03:36 +00:00
|
|
|
const linkToTWHelp = document.createElement('a');
|
2021-01-02 15:01:07 +00:00
|
|
|
linkToTWHelp.href = twhelputils.buildPlayerURL(VERSION, SERVER, PLAYER_ID);
|
2021-01-01 17:03:36 +00:00
|
|
|
linkToTWHelp.innerHTML = translations.action.linkToTWHelp;
|
|
|
|
actionContainer.appendChild(wrapAction(linkToTWHelp));
|
|
|
|
|
2020-07-11 18:44:52 +00:00
|
|
|
const showTribeChanges = document.createElement('a');
|
|
|
|
showTribeChanges.href = '#';
|
2020-07-15 18:55:24 +00:00
|
|
|
setPage(showTribeChanges, '1');
|
2020-07-22 15:02:49 +00:00
|
|
|
showTribeChanges.innerHTML = translations.action.showTribeChanges;
|
2020-07-12 13:18:49 +00:00
|
|
|
showTribeChanges.addEventListener('click', handleShowTribeChangesButtonClick);
|
2020-07-20 12:07:57 +00:00
|
|
|
actionContainer.appendChild(wrapAction(showTribeChanges));
|
2020-07-15 18:55:24 +00:00
|
|
|
|
|
|
|
const showPlayerHistory = document.createElement('a');
|
|
|
|
showPlayerHistory.href = '#';
|
|
|
|
setPage(showPlayerHistory, '1');
|
2020-07-22 15:02:49 +00:00
|
|
|
showPlayerHistory.innerHTML = translations.action.showHistory;
|
2020-07-15 18:55:24 +00:00
|
|
|
showPlayerHistory.addEventListener('click', handleShowPlayerHistoryClick);
|
2020-07-20 12:07:57 +00:00
|
|
|
actionContainer.appendChild(wrapAction(showPlayerHistory));
|
2020-07-12 13:18:49 +00:00
|
|
|
|
2020-07-17 10:58:08 +00:00
|
|
|
const showEnnoblements = document.createElement('a');
|
|
|
|
showEnnoblements.href = '#';
|
|
|
|
setPage(showEnnoblements, '1');
|
2020-07-22 15:02:49 +00:00
|
|
|
showEnnoblements.innerHTML = translations.action.showEnnoblements;
|
2020-07-17 10:58:08 +00:00
|
|
|
showEnnoblements.addEventListener('click', handleShowPlayerEnnoblementsClick);
|
2020-07-20 12:07:57 +00:00
|
|
|
actionContainer.appendChild(wrapAction(showEnnoblements));
|
2020-07-17 10:58:08 +00:00
|
|
|
|
2020-07-12 13:18:49 +00:00
|
|
|
const exportPlayerVillages = document.createElement('a');
|
|
|
|
exportPlayerVillages.href = '#';
|
2020-07-22 15:02:49 +00:00
|
|
|
exportPlayerVillages.innerHTML = translations.action.exportVillages;
|
2020-07-12 13:18:49 +00:00
|
|
|
exportPlayerVillages.addEventListener(
|
|
|
|
'click',
|
|
|
|
handleExportPlayerVillagesButtonClick
|
2020-07-11 18:44:52 +00:00
|
|
|
);
|
2020-07-20 12:07:57 +00:00
|
|
|
actionContainer.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-15 18:55:24 +00:00
|
|
|
|
2020-07-11 14:25:10 +00:00
|
|
|
const dataFromCache = loadDataFromCache();
|
|
|
|
if (dataFromCache && dataFromCache.player) {
|
|
|
|
render(dataFromCache);
|
2020-07-11 12:08:43 +00:00
|
|
|
}
|
2020-07-15 18:55:24 +00:00
|
|
|
|
2020-07-11 14:25:10 +00:00
|
|
|
const dataFromAPI = await loadData();
|
|
|
|
if (dataFromAPI) {
|
|
|
|
render(dataFromAPI);
|
2020-07-11 12:08:43 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log('extended player profile', error);
|
|
|
|
}
|
|
|
|
})();
|