add 'show ennoblements' action to extendedTribeProfile.js, extendedPlayerProfile.js is now stable
This commit is contained in:
parent
a638a1400c
commit
96f6c5bc22
|
@ -397,15 +397,59 @@ var _default = (container, stats) => {
|
|||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{"./isNil":"yQib"}],"fCHX":[function(require,module,exports) {
|
||||
},{"./isNil":"yQib"}],"P4rL":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.generatePaginationItems = exports.calcNumberOfPages = exports.getPage = exports.setPage = void 0;
|
||||
exports.default = void 0;
|
||||
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
|
||||
const POPUP_SELECTOR = '#inline_popup';
|
||||
|
||||
var _default = function _default() {
|
||||
let {
|
||||
e,
|
||||
title,
|
||||
html,
|
||||
id
|
||||
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
inlinePopup(e, id, null, {
|
||||
offset_x: 0,
|
||||
offset_y: 0
|
||||
}, html, title);
|
||||
const popup = document.querySelector(POPUP_SELECTOR);
|
||||
|
||||
if (popup) {
|
||||
popup.style.width = 'auto';
|
||||
popup.style.maxWidth = '800px';
|
||||
}
|
||||
|
||||
const popupWrapper = document.querySelector(POPUP_WRAPPER_SELECTOR);
|
||||
|
||||
if (popupWrapper) {
|
||||
popupWrapper.style.width = 'auto';
|
||||
popupWrapper.style.position = 'fixed';
|
||||
popupWrapper.style.zIndex = '50001';
|
||||
}
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"fCHX":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.generatePaginationItems = exports.calcNumberOfPages = exports.getPage = exports.setPage = exports.getContainerStyles = void 0;
|
||||
const ATTRIBUTE = 'data-page';
|
||||
|
||||
const getContainerStyles = () => {
|
||||
return 'display: flex; flex-direction: row; flex-wrap: wrap;';
|
||||
};
|
||||
|
||||
exports.getContainerStyles = getContainerStyles;
|
||||
|
||||
const setPage = function setPage(el) {
|
||||
let page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
||||
|
||||
|
@ -470,28 +514,6 @@ const generatePaginationItems = function generatePaginationItems() {
|
|||
};
|
||||
|
||||
exports.generatePaginationItems = generatePaginationItems;
|
||||
},{}],"tQUs":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _default = url => parseInt(new URLSearchParams(url).get('id'));
|
||||
|
||||
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;
|
||||
},{}],"V6Mf":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
|
@ -512,59 +534,17 @@ var _default = (date, options) => {
|
|||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"P4rL":[function(require,module,exports) {
|
||||
},{}],"tQUs":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
|
||||
const POPUP_SELECTOR = '#inline_popup';
|
||||
|
||||
var _default = function _default() {
|
||||
let {
|
||||
e,
|
||||
title,
|
||||
html,
|
||||
id
|
||||
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
inlinePopup(e, id, null, {
|
||||
offset_x: 0,
|
||||
offset_y: 0
|
||||
}, html, title);
|
||||
const popup = document.querySelector(POPUP_SELECTOR);
|
||||
|
||||
if (popup) {
|
||||
popup.style.width = 'auto';
|
||||
popup.style.maxWidth = '800px';
|
||||
}
|
||||
|
||||
const popupWrapper = document.querySelector(POPUP_WRAPPER_SELECTOR);
|
||||
|
||||
if (popupWrapper) {
|
||||
popupWrapper.style.width = 'auto';
|
||||
popupWrapper.style.position = 'fixed';
|
||||
popupWrapper.style.zIndex = '50001';
|
||||
}
|
||||
};
|
||||
var _default = url => parseInt(new URLSearchParams(url).get('id'));
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"Syko":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.formatPlayerURL = void 0;
|
||||
|
||||
const formatPlayerURL = function formatPlayerURL() {
|
||||
let server = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
||||
let id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
||||
return "http://www.twstats.com/in/".concat(server, "/player/").concat(id);
|
||||
};
|
||||
|
||||
exports.formatPlayerURL = formatPlayerURL;
|
||||
},{}],"dSAr":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
|
@ -728,7 +708,97 @@ const loadInADayData = async function loadInADayData(type) {
|
|||
};
|
||||
|
||||
exports.loadInADayData = loadInADayData;
|
||||
},{"../libs/InADayParser":"dSAr"}],"KWxH":[function(require,module,exports) {
|
||||
},{"../libs/InADayParser":"dSAr"}],"vhoq":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _pagination = require("./pagination");
|
||||
|
||||
var _renderPopup = _interopRequireDefault(require("./renderPopup"));
|
||||
|
||||
var _formatDate = _interopRequireDefault(require("./formatDate"));
|
||||
|
||||
var _tribalwars = require("./tribalwars");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const ENNOBLEMENTS_PAGINATION_CONTAINER_ID = 'ennoblementsPagination';
|
||||
|
||||
const getPlayerTd = (player, tribe) => {
|
||||
if (player) {
|
||||
return "<td><a href=\"".concat((0, _tribalwars.formatPlayerURL)(player.id), "\">").concat(player.name, " (").concat(tribe ? "<a href=\"".concat((0, _tribalwars.formatTribeURL)(tribe.id), "\">").concat(tribe.tag, "</a>") : '-', ")</a></td>");
|
||||
}
|
||||
|
||||
return '<td>-</td>';
|
||||
};
|
||||
|
||||
var _default = function _default(e, ennoblements) {
|
||||
let {
|
||||
limit = 0,
|
||||
currentPage = 1,
|
||||
onPageChange = () => {}
|
||||
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
const paginationItems = (0, _pagination.generatePaginationItems)({
|
||||
total: ennoblements.total,
|
||||
limit,
|
||||
currentPage
|
||||
});
|
||||
const html = "\n <div style=\"".concat((0, _pagination.getContainerStyles)(), "\" id=\"").concat(ENNOBLEMENTS_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Village\n </th>\n <th>\n New Owner\n </th>\n <th>\n Old Owner\n </th>\n </tr>\n ").concat(ennoblements.items.map(ennoblement => {
|
||||
let rowHTML = '<tr>' + "<td>".concat((0, _formatDate.default)(ennoblement.ennobledAt), "</td>");
|
||||
|
||||
if (ennoblement.village) {
|
||||
rowHTML += "<td><a href=\"".concat((0, _tribalwars.formatVillageURL)(ennoblement.village.id), "\">").concat((0, _tribalwars.formatVillageName)(ennoblement.village.name, ennoblement.village.x, ennoblement.village.y), "</a></td>");
|
||||
} else {
|
||||
rowHTML += '<td>-</td>';
|
||||
}
|
||||
|
||||
rowHTML += getPlayerTd(ennoblement.newOwner, ennoblement.newOwnerTribe);
|
||||
rowHTML += getPlayerTd(ennoblement.oldOwner, ennoblement.oldOwnerTribe);
|
||||
return rowHTML + '</tr>';
|
||||
}).join(''), "\n </tbody>\n </table>\n ");
|
||||
(0, _renderPopup.default)({
|
||||
e,
|
||||
title: "Ennoblements",
|
||||
id: 'ennoblements',
|
||||
html
|
||||
});
|
||||
document.querySelectorAll('#' + ENNOBLEMENTS_PAGINATION_CONTAINER_ID + ' a').forEach(el => {
|
||||
el.addEventListener('click', onPageChange);
|
||||
});
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{"./pagination":"fCHX","./renderPopup":"P4rL","./formatDate":"V6Mf","./tribalwars":"fHHP"}],"DMkL":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _default = () => window.location.host.split('.')[0];
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"Syko":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.formatPlayerURL = void 0;
|
||||
|
||||
const formatPlayerURL = function formatPlayerURL() {
|
||||
let server = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
||||
let id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
||||
return "http://www.twstats.com/in/".concat(server, "/player/").concat(id);
|
||||
};
|
||||
|
||||
exports.formatPlayerURL = formatPlayerURL;
|
||||
},{}],"KWxH":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
|
@ -763,6 +833,10 @@ var _requestCreator = _interopRequireDefault(require("./libs/requestCreator"));
|
|||
|
||||
var _renderTodaysStats = _interopRequireDefault(require("./utils/renderTodaysStats"));
|
||||
|
||||
var _renderPopup = _interopRequireDefault(require("./utils/renderPopup"));
|
||||
|
||||
var _renderEnnoblements = _interopRequireDefault(require("./utils/renderEnnoblements"));
|
||||
|
||||
var _pagination = require("./utils/pagination");
|
||||
|
||||
var _getIDFromURL = _interopRequireDefault(require("./utils/getIDFromURL"));
|
||||
|
@ -771,8 +845,6 @@ var _getCurrentServer = _interopRequireDefault(require("./utils/getCurrentServer
|
|||
|
||||
var _formatDate = _interopRequireDefault(require("./utils/formatDate"));
|
||||
|
||||
var _renderPopup = _interopRequireDefault(require("./utils/renderPopup"));
|
||||
|
||||
var _twstats = require("./utils/twstats");
|
||||
|
||||
var _tribalwars = require("./utils/tribalwars");
|
||||
|
@ -792,7 +864,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|||
// @namespace https://github.com/tribalwarshelp/scripts
|
||||
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
|
||||
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
|
||||
// @version 0.7.2
|
||||
// @version 1
|
||||
// @description Extended Player Profile
|
||||
// @author Kichiyaki http://dawid-wysokinski.pl/
|
||||
// @match *://*/game.php*&screen=info_player*
|
||||
|
@ -816,7 +888,6 @@ const PLAYER_HISTORY_AND_PLAYER_DAILY_STATS_QUERY = "\nquery playerHistoryAndPla
|
|||
const PLAYER_HISTORY_PAGINATION_CONTAINER_ID = 'playerHistoryPagination';
|
||||
const PLAYER_HISTORY_PER_PAGE = 15;
|
||||
const ENNOBLEMENTS_QUERY = "\n query ennoblements($server: String!, $filter: EnnoblementFilter!) {\n ennoblements(server: $server, filter: $filter) {\n total\n items {\n village {\n id\n name\n x\n y\n }\n oldOwner {\n id\n name\n }\n oldOwnerTribe {\n id\n tag\n }\n newOwner {\n id\n name\n }\n newOwnerTribe {\n id\n tag\n }\n ennobledAt\n }\n }\n }\n";
|
||||
const ENNOBLEMENTS_PAGINATION_CONTAINER_ID = 'ennoblementsPagination';
|
||||
const ENNOBLEMENTS_PER_PAGE = 15;
|
||||
const profileInfoTBody = document.querySelector('#player_info > tbody');
|
||||
const actionsContainer = PLAYER_ID === CURRENT_PLAYER_ID ? profileInfoTBody : document.querySelector('#content_value > table > tbody > tr > td:nth-child(1) > table:nth-child(2) > tbody');
|
||||
|
@ -1004,7 +1075,7 @@ const renderTribeChanges = (e, currentPage, tribeChanges) => {
|
|||
limit: TRIBE_CHANGES_PER_PAGE,
|
||||
currentPage
|
||||
});
|
||||
const html = "\n <div id=\"".concat(TRIBE_CHANGES_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n New tribe\n </th>\n <th>\n Old tribe\n </th>\n </tr>\n ").concat(tribeChanges.items.map(tribeChange => {
|
||||
const html = "\n <div style=\"".concat((0, _pagination.getContainerStyles)(), "\" id=\"").concat(TRIBE_CHANGES_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n New tribe\n </th>\n <th>\n Old tribe\n </th>\n </tr>\n ").concat(tribeChanges.items.map(tribeChange => {
|
||||
let rowHTML = '<tr>' + "<td>".concat((0, _formatDate.default)(tribeChange.createdAt), "</td>");
|
||||
|
||||
if (tribeChange.newTribe) {
|
||||
|
@ -1061,7 +1132,7 @@ const renderPlayerHistory = (e, currentPage, playerHistory, playerDailyStats) =>
|
|||
limit: PLAYER_HISTORY_PER_PAGE,
|
||||
currentPage
|
||||
});
|
||||
const html = "\n <div id=\"".concat(PLAYER_HISTORY_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Tribe\n </th>\n <th>\n Points\n </th>\n <th>\n Villages\n </th>\n <th>\n OD\n </th>\n <th>\n ODA\n </th>\n <th>\n ODD\n </th>\n <th>\n ODS\n </th>\n </tr>\n ").concat(playerHistory.items.map(playerHistory => {
|
||||
const html = "\n <div style=\"".concat((0, _pagination.getContainerStyles)(), "\" id=\"").concat(PLAYER_HISTORY_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Tribe\n </th>\n <th>\n Points\n </th>\n <th>\n Villages\n </th>\n <th>\n OD\n </th>\n <th>\n ODA\n </th>\n <th>\n ODD\n </th>\n <th>\n ODS\n </th>\n </tr>\n ").concat(playerHistory.items.map(playerHistory => {
|
||||
const subtracted = (0, _subDays.default)(new Date(playerHistory.createDate), 1).toISOString().split('.')[0] + 'Z';
|
||||
const stats = playerDailyStats.items.find(stats => {
|
||||
return stats.createDate === subtracted;
|
||||
|
@ -1122,43 +1193,6 @@ const handleShowPlayerHistoryClick = async e => {
|
|||
}
|
||||
};
|
||||
|
||||
const renderPlayerEnnoblements = (e, currentPage, ennoblements) => {
|
||||
const paginationItems = (0, _pagination.generatePaginationItems)({
|
||||
total: ennoblements.total,
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
currentPage
|
||||
});
|
||||
|
||||
const getPlayerTd = (player, tribe) => {
|
||||
if (player) {
|
||||
return "<td><a href=\"".concat((0, _tribalwars.formatPlayerURL)(player.id), "\">").concat(player.name, " (").concat(tribe ? "<a href=\"".concat((0, _tribalwars.formatTribeURL)(tribe.id), "\">").concat(tribe.tag, "</a>") : '-', ")</a></td>");
|
||||
}
|
||||
|
||||
return '<td>-</td>';
|
||||
};
|
||||
|
||||
const html = "\n <div id=\"".concat(ENNOBLEMENTS_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Village\n </th>\n <th>\n New Owner\n </th>\n <th>\n Old Owner\n </th>\n </tr>\n ").concat(ennoblements.items.map(ennoblement => {
|
||||
let rowHTML = '<tr>' + "<td>".concat((0, _formatDate.default)(ennoblement.ennobledAt), "</td>");
|
||||
|
||||
if (ennoblement.village) {
|
||||
rowHTML += "<td><a href=\"".concat((0, _tribalwars.formatVillageURL)(ennoblement.village.id), "\">").concat((0, _tribalwars.formatVillageName)(ennoblement.village.name, ennoblement.village.x, ennoblement.village.y), "</a></td>");
|
||||
} else {
|
||||
rowHTML += '<td>-</td>';
|
||||
}
|
||||
|
||||
rowHTML += getPlayerTd(ennoblement.newOwner, ennoblement.newOwnerTribe);
|
||||
rowHTML += getPlayerTd(ennoblement.oldOwner, ennoblement.oldOwnerTribe);
|
||||
return rowHTML + '</tr>';
|
||||
}).join(''), "\n </tbody>\n </table>\n ");
|
||||
(0, _renderPopup.default)({
|
||||
e,
|
||||
title: "Ennoblements",
|
||||
id: 'ennoblements',
|
||||
html
|
||||
});
|
||||
addPaginationListeners(ENNOBLEMENTS_PAGINATION_CONTAINER_ID, handleShowPlayerEnnoblementsClick);
|
||||
};
|
||||
|
||||
const handleShowPlayerEnnoblementsClick = async e => {
|
||||
e.preventDefault();
|
||||
const page = (0, _pagination.getPage)(e.target);
|
||||
|
@ -1179,7 +1213,11 @@ const handleShowPlayerEnnoblementsClick = async e => {
|
|||
server: SERVER
|
||||
}
|
||||
});
|
||||
renderPlayerEnnoblements(e, page, data.ennoblements);
|
||||
(0, _renderEnnoblements.default)(e, data.ennoblements, {
|
||||
currentPage: page,
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
onPageChange: handleShowPlayerEnnoblementsClick
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1241,4 +1279,4 @@ const renderActions = () => {
|
|||
console.log('extended player profile', error);
|
||||
}
|
||||
})();
|
||||
},{"date-fns/subDays":"mRRL","./libs/requestCreator":"Ph2E","./utils/renderTodaysStats":"dPMc","./utils/pagination":"fCHX","./utils/getIDFromURL":"tQUs","./utils/getCurrentServer":"DMkL","./utils/formatDate":"V6Mf","./utils/renderPopup":"P4rL","./utils/twstats":"Syko","./utils/tribalwars":"fHHP","./utils/localStorage":"KWxH"}]},{},["yRop"], null)
|
||||
},{"date-fns/subDays":"mRRL","./libs/requestCreator":"Ph2E","./utils/renderTodaysStats":"dPMc","./utils/renderPopup":"P4rL","./utils/renderEnnoblements":"vhoq","./utils/pagination":"fCHX","./utils/getIDFromURL":"tQUs","./utils/getCurrentServer":"DMkL","./utils/formatDate":"V6Mf","./utils/twstats":"Syko","./utils/tribalwars":"fHHP","./utils/localStorage":"KWxH"}]},{},["yRop"], null)
|
|
@ -620,6 +620,85 @@ var _default = function _default() {
|
|||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"fCHX":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.generatePaginationItems = exports.calcNumberOfPages = exports.getPage = exports.setPage = exports.getContainerStyles = void 0;
|
||||
const ATTRIBUTE = 'data-page';
|
||||
|
||||
const getContainerStyles = () => {
|
||||
return 'display: flex; flex-direction: row; flex-wrap: wrap;';
|
||||
};
|
||||
|
||||
exports.getContainerStyles = getContainerStyles;
|
||||
|
||||
const setPage = function setPage(el) {
|
||||
let page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
||||
|
||||
if (!el instanceof HTMLElement) {
|
||||
throw new Error('Expected HTMLElement as the first argument');
|
||||
}
|
||||
|
||||
page = parseInt(page);
|
||||
|
||||
if (typeof page !== 'number' || isNaN(page)) {
|
||||
throw new Error('Expected number or string as the second argument');
|
||||
}
|
||||
|
||||
el.setAttribute(ATTRIBUTE, page + '');
|
||||
};
|
||||
|
||||
exports.setPage = setPage;
|
||||
|
||||
const getPage = el => {
|
||||
if (!el instanceof HTMLElement) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return parseInt(el.getAttribute(ATTRIBUTE));
|
||||
};
|
||||
|
||||
exports.getPage = getPage;
|
||||
|
||||
const calcNumberOfPages = (total, limit) => {
|
||||
if (typeof total !== 'number') {
|
||||
throw new Error('Expected number as the first argument');
|
||||
}
|
||||
|
||||
if (typeof limit !== 'number') {
|
||||
throw new Error('Expected number as the second argument');
|
||||
}
|
||||
|
||||
return total > 0 ? Math.ceil(total / limit) : 1;
|
||||
};
|
||||
|
||||
exports.calcNumberOfPages = calcNumberOfPages;
|
||||
|
||||
const generatePaginationItems = function generatePaginationItems() {
|
||||
let {
|
||||
total,
|
||||
limit,
|
||||
marginRight = 3,
|
||||
currentPage = 0
|
||||
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
const numberOfPages = calcNumberOfPages(total, limit);
|
||||
const paginationItems = [];
|
||||
|
||||
for (let i = 1; i <= numberOfPages; i++) {
|
||||
if (i === currentPage) {
|
||||
paginationItems.push("<strong style=\"margin-right: ".concat(marginRight, "px\">>").concat(i, "<</strong>"));
|
||||
} else {
|
||||
paginationItems.push("<a style=\"margin-right: ".concat(marginRight, "px\" href=\"#\" ").concat(ATTRIBUTE, "=\"").concat(i, "\">").concat(i, "</a>"));
|
||||
}
|
||||
}
|
||||
|
||||
return paginationItems;
|
||||
};
|
||||
|
||||
exports.generatePaginationItems = generatePaginationItems;
|
||||
},{}],"yQib":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
|
@ -665,7 +744,65 @@ var _default = (container, stats) => {
|
|||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{"./isNil":"yQib"}],"tQUs":[function(require,module,exports) {
|
||||
},{"./isNil":"yQib"}],"P4rL":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
|
||||
const POPUP_SELECTOR = '#inline_popup';
|
||||
|
||||
var _default = function _default() {
|
||||
let {
|
||||
e,
|
||||
title,
|
||||
html,
|
||||
id
|
||||
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
inlinePopup(e, id, null, {
|
||||
offset_x: 0,
|
||||
offset_y: 0
|
||||
}, html, title);
|
||||
const popup = document.querySelector(POPUP_SELECTOR);
|
||||
|
||||
if (popup) {
|
||||
popup.style.width = 'auto';
|
||||
popup.style.maxWidth = '800px';
|
||||
}
|
||||
|
||||
const popupWrapper = document.querySelector(POPUP_WRAPPER_SELECTOR);
|
||||
|
||||
if (popupWrapper) {
|
||||
popupWrapper.style.width = 'auto';
|
||||
popupWrapper.style.position = 'fixed';
|
||||
popupWrapper.style.zIndex = '50001';
|
||||
}
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"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;
|
||||
},{}],"tQUs":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
|
@ -676,7 +813,234 @@ exports.default = void 0;
|
|||
var _default = url => parseInt(new URLSearchParams(url).get('id'));
|
||||
|
||||
exports.default = _default;
|
||||
},{}],"DMkL":[function(require,module,exports) {
|
||||
},{}],"dSAr":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _getIDFromURL = _interopRequireDefault(require("../utils/getIDFromURL"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
class InADayParser {
|
||||
constructor(html) {
|
||||
let filters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
this.dom = new DOMParser().parseFromString(html, 'text/html');
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
isValidRow(row) {
|
||||
if (!row) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.filters.playerID && row.playerID !== this.filters.playerID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
parseRow(row) {
|
||||
if (!row || !row instanceof HTMLTableRowElement) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let obj = {};
|
||||
obj.rank = parseInt(row.children[0].innerText.trim());
|
||||
obj.name = row.children[1].innerText.trim();
|
||||
obj.playerID = (0, _getIDFromURL.default)(row.children[1].querySelector('a').getAttribute('href'));
|
||||
obj.tribe = row.children[2].innerText.trim();
|
||||
obj.tribeID = 0;
|
||||
|
||||
if (obj.tribe) {
|
||||
obj.tribeID = (0, _getIDFromURL.default)(row.children[2].querySelector('a').getAttribute('href'));
|
||||
}
|
||||
|
||||
obj.score = parseInt(row.children[3].innerText.trim().replace(/\./g, ''));
|
||||
obj.date = row.children[4].innerText.trim();
|
||||
return obj;
|
||||
}
|
||||
|
||||
parse() {
|
||||
const trs = this.dom.querySelectorAll('#in_a_day_ranking_table tbody tr');
|
||||
const result = [];
|
||||
|
||||
for (let i = 1; i < trs.length; i++) {
|
||||
const row = trs[i];
|
||||
const parsed = this.parseRow(row);
|
||||
|
||||
if (this.isValidRow(parsed)) {
|
||||
result.push(parsed);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = InADayParser;
|
||||
},{"../utils/getIDFromURL":"tQUs"}],"fHHP":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.loadInADayData = exports.formatVillageName = exports.formatVillageURL = exports.formatPlayerURL = exports.formatTribeURL = void 0;
|
||||
|
||||
var _InADayParser = _interopRequireDefault(require("../libs/InADayParser"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
const formatTribeURL = id => {
|
||||
return window.location.origin + TribalWars.buildURL('', {
|
||||
screen: 'info_ally',
|
||||
id
|
||||
});
|
||||
};
|
||||
|
||||
exports.formatTribeURL = formatTribeURL;
|
||||
|
||||
const formatPlayerURL = id => {
|
||||
return window.location.origin + TribalWars.buildURL('', {
|
||||
screen: 'info_player',
|
||||
id
|
||||
});
|
||||
};
|
||||
|
||||
exports.formatPlayerURL = formatPlayerURL;
|
||||
|
||||
const formatVillageURL = id => {
|
||||
return window.location.origin + TribalWars.buildURL('', {
|
||||
screen: 'info_village',
|
||||
id
|
||||
});
|
||||
};
|
||||
|
||||
exports.formatVillageURL = formatVillageURL;
|
||||
|
||||
const formatVillageName = function formatVillageName() {
|
||||
let n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
||||
let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
||||
let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 500;
|
||||
const continent = 'K' + String(y)[0] + String(x)[0];
|
||||
return "".concat(n, " (").concat(x, "|").concat(y, ") ").concat(continent);
|
||||
};
|
||||
|
||||
exports.formatVillageName = formatVillageName;
|
||||
|
||||
const loadInADayData = async function loadInADayData(type) {
|
||||
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
||||
{
|
||||
name
|
||||
} = _ref,
|
||||
rest = _objectWithoutProperties(_ref, ["name"]);
|
||||
|
||||
try {
|
||||
const response = await fetch(TribalWars.buildURL('', {
|
||||
screen: 'ranking',
|
||||
mode: 'in_a_day',
|
||||
type,
|
||||
name: name ? name : ''
|
||||
}));
|
||||
const html = await response.text();
|
||||
|
||||
if (!html) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
const res = new _InADayParser.default(html, rest).parse();
|
||||
|
||||
if (res.length === 0) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return res[0];
|
||||
} catch (error) {
|
||||
return {
|
||||
rank: 0,
|
||||
playerID: 0,
|
||||
score: 0,
|
||||
tribeID: 0,
|
||||
date: new Date()
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
exports.loadInADayData = loadInADayData;
|
||||
},{"../libs/InADayParser":"dSAr"}],"vhoq":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _pagination = require("./pagination");
|
||||
|
||||
var _renderPopup = _interopRequireDefault(require("./renderPopup"));
|
||||
|
||||
var _formatDate = _interopRequireDefault(require("./formatDate"));
|
||||
|
||||
var _tribalwars = require("./tribalwars");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const ENNOBLEMENTS_PAGINATION_CONTAINER_ID = 'ennoblementsPagination';
|
||||
|
||||
const getPlayerTd = (player, tribe) => {
|
||||
if (player) {
|
||||
return "<td><a href=\"".concat((0, _tribalwars.formatPlayerURL)(player.id), "\">").concat(player.name, " (").concat(tribe ? "<a href=\"".concat((0, _tribalwars.formatTribeURL)(tribe.id), "\">").concat(tribe.tag, "</a>") : '-', ")</a></td>");
|
||||
}
|
||||
|
||||
return '<td>-</td>';
|
||||
};
|
||||
|
||||
var _default = function _default(e, ennoblements) {
|
||||
let {
|
||||
limit = 0,
|
||||
currentPage = 1,
|
||||
onPageChange = () => {}
|
||||
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
const paginationItems = (0, _pagination.generatePaginationItems)({
|
||||
total: ennoblements.total,
|
||||
limit,
|
||||
currentPage
|
||||
});
|
||||
const html = "\n <div style=\"".concat((0, _pagination.getContainerStyles)(), "\" id=\"").concat(ENNOBLEMENTS_PAGINATION_CONTAINER_ID, "\">\n ").concat(paginationItems.join(''), "\n </div>\n <table class=\"vis\" style=\"border-collapse: separate; border-spacing: 2px; width: 100%;\">\n <tbody>\n <tr>\n <th>\n Date\n </th>\n <th>\n Village\n </th>\n <th>\n New Owner\n </th>\n <th>\n Old Owner\n </th>\n </tr>\n ").concat(ennoblements.items.map(ennoblement => {
|
||||
let rowHTML = '<tr>' + "<td>".concat((0, _formatDate.default)(ennoblement.ennobledAt), "</td>");
|
||||
|
||||
if (ennoblement.village) {
|
||||
rowHTML += "<td><a href=\"".concat((0, _tribalwars.formatVillageURL)(ennoblement.village.id), "\">").concat((0, _tribalwars.formatVillageName)(ennoblement.village.name, ennoblement.village.x, ennoblement.village.y), "</a></td>");
|
||||
} else {
|
||||
rowHTML += '<td>-</td>';
|
||||
}
|
||||
|
||||
rowHTML += getPlayerTd(ennoblement.newOwner, ennoblement.newOwnerTribe);
|
||||
rowHTML += getPlayerTd(ennoblement.oldOwner, ennoblement.oldOwnerTribe);
|
||||
return rowHTML + '</tr>';
|
||||
}).join(''), "\n </tbody>\n </table>\n ");
|
||||
(0, _renderPopup.default)({
|
||||
e,
|
||||
title: "Ennoblements",
|
||||
id: 'ennoblements',
|
||||
html
|
||||
});
|
||||
document.querySelectorAll('#' + ENNOBLEMENTS_PAGINATION_CONTAINER_ID + ' a').forEach(el => {
|
||||
el.addEventListener('click', onPageChange);
|
||||
});
|
||||
};
|
||||
|
||||
exports.default = _default;
|
||||
},{"./pagination":"fCHX","./renderPopup":"P4rL","./formatDate":"V6Mf","./tribalwars":"fHHP"}],"DMkL":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
|
@ -713,26 +1077,6 @@ const setItem = (key, payload) => {
|
|||
};
|
||||
|
||||
exports.setItem = setItem;
|
||||
},{}],"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;
|
||||
},{}],"Syko":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
|
@ -755,8 +1099,12 @@ var _isURL = _interopRequireDefault(require("validator/lib/isURL"));
|
|||
|
||||
var _requestCreator = _interopRequireDefault(require("./libs/requestCreator"));
|
||||
|
||||
var _pagination = require("./utils/pagination");
|
||||
|
||||
var _renderTodaysStats = _interopRequireDefault(require("./utils/renderTodaysStats"));
|
||||
|
||||
var _renderEnnoblements = _interopRequireDefault(require("./utils/renderEnnoblements"));
|
||||
|
||||
var _getIDFromURL = _interopRequireDefault(require("./utils/getIDFromURL"));
|
||||
|
||||
var _getCurrentServer = _interopRequireDefault(require("./utils/getCurrentServer"));
|
||||
|
@ -774,7 +1122,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|||
// @namespace https://github.com/tribalwarshelp/scripts
|
||||
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedTribeProfile.js
|
||||
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedTribeProfile.js
|
||||
// @version 0.3.1
|
||||
// @version 0.4
|
||||
// @description Extended Tribe Profile
|
||||
// @author Kichiyaki http://dawid-wysokinski.pl/
|
||||
// @match *://*/game.php*&screen=info_ally*
|
||||
|
@ -785,7 +1133,10 @@ const SERVER = (0, _getCurrentServer.default)();
|
|||
const TRIBE_ID = (0, _getIDFromURL.default)(window.location.search);
|
||||
const LOCAL_STORAGE_KEY = 'kichiyaki_extended_tribe_profile' + TRIBE_ID;
|
||||
const TRIBE_QUERY = "\n query tribe($server: String!, $id: Int!, $playerFilter: PlayerFilter!, $dailyTribeStatsFilter: DailyTribeStatsFilter!) {\n tribe(server: $server, id: $id) {\n id\n bestRank\n bestRankAt\n mostPoints\n mostPointsAt\n mostVillages\n mostVillagesAt\n createdAt\n dominance\n }\n dailyTribeStats(server: $server, filter: $dailyTribeStatsFilter) {\n items {\n rank\n rankAtt\n rankDef\n rankTotal\n points\n scoreAtt\n scoreAtt\n scoreDef\n scoreTotal\n villages\n }\n }\n players(server: $server, filter: $playerFilter) {\n items {\n id\n rankAtt\n rankDef\n rankSup\n rankTotal\n scoreAtt\n scoreAtt\n scoreDef\n scoreSup\n scoreTotal\n dailyGrowth\n }\n }\n }\n";
|
||||
const ENNOBLEMENTS_QUERY = "\n query ennoblements($server: String!, $filter: EnnoblementFilter!) {\n ennoblements(server: $server, filter: $filter) {\n total\n items {\n village {\n id\n name\n x\n y\n }\n oldOwner {\n id\n name\n }\n oldOwnerTribe {\n id\n tag\n }\n newOwner {\n id\n name\n }\n newOwnerTribe {\n id\n tag\n }\n ennobledAt\n }\n }\n }\n";
|
||||
const ENNOBLEMENTS_PER_PAGE = 15;
|
||||
const profileInfoTBody = document.querySelector('#content_value > table:nth-child(3) > tbody > tr > td:nth-child(1) > table > tbody');
|
||||
const actionsContainer = profileInfoTBody;
|
||||
const otherElementsContainer = document.querySelector('#content_value > table:nth-child(3) > tbody > tr > td:nth-child(2)');
|
||||
const membersContainer = document.querySelector('#content_value > table.vis > tbody');
|
||||
|
||||
|
@ -937,9 +1288,56 @@ const render = (_ref2) => {
|
|||
}
|
||||
};
|
||||
|
||||
const handleShowTribeEnnoblementsClick = async e => {
|
||||
e.preventDefault();
|
||||
const page = (0, _pagination.getPage)(e.target);
|
||||
|
||||
if (!isNaN(page)) {
|
||||
const data = await (0, _requestCreator.default)({
|
||||
query: ENNOBLEMENTS_QUERY,
|
||||
variables: {
|
||||
filter: {
|
||||
or: {
|
||||
oldOwnerTribeID: [TRIBE_ID],
|
||||
newOwnerTribeID: [TRIBE_ID]
|
||||
},
|
||||
offset: ENNOBLEMENTS_PER_PAGE * (page - 1),
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
sort: 'ennobledAt DESC'
|
||||
},
|
||||
server: SERVER
|
||||
}
|
||||
});
|
||||
(0, _renderEnnoblements.default)(e, data.ennoblements, {
|
||||
currentPage: page,
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
onPageChange: handleShowTribeEnnoblementsClick
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const wrapAction = action => {
|
||||
const actionWrapperTd = document.createElement('td');
|
||||
actionWrapperTd.colSpan = '2';
|
||||
actionWrapperTd.append(action);
|
||||
const actionWrapperTr = document.createElement('tr');
|
||||
actionWrapperTr.appendChild(actionWrapperTd);
|
||||
return actionWrapperTr;
|
||||
};
|
||||
|
||||
const renderActions = () => {
|
||||
const showEnnoblements = document.createElement('a');
|
||||
showEnnoblements.href = '#';
|
||||
(0, _pagination.setPage)(showEnnoblements, '1');
|
||||
showEnnoblements.innerHTML = 'Show tribe ennoblements';
|
||||
showEnnoblements.addEventListener('click', handleShowTribeEnnoblementsClick);
|
||||
actionsContainer.appendChild(wrapAction(showEnnoblements));
|
||||
};
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
document.querySelector('#content_value > table:nth-child(3)').style.width = '100%';
|
||||
renderActions();
|
||||
const dataFromCache = loadDataFromCache();
|
||||
|
||||
if (dataFromCache && dataFromCache.tribe) {
|
||||
|
@ -955,4 +1353,4 @@ const render = (_ref2) => {
|
|||
console.log('extended tribe profile', error);
|
||||
}
|
||||
})();
|
||||
},{"validator/lib/isURL":"XMVV","./libs/requestCreator":"Ph2E","./utils/renderTodaysStats":"dPMc","./utils/getIDFromURL":"tQUs","./utils/getCurrentServer":"DMkL","./utils/localStorage":"KWxH","./utils/formatDate":"V6Mf","./utils/twstats":"Syko"}]},{},["r4nF"], null)
|
||||
},{"validator/lib/isURL":"XMVV","./libs/requestCreator":"Ph2E","./utils/pagination":"fCHX","./utils/renderTodaysStats":"dPMc","./utils/renderEnnoblements":"vhoq","./utils/getIDFromURL":"tQUs","./utils/getCurrentServer":"DMkL","./utils/localStorage":"KWxH","./utils/formatDate":"V6Mf","./utils/twstats":"Syko"}]},{},["r4nF"], null)
|
|
@ -1,11 +1,17 @@
|
|||
import subDays from 'date-fns/subDays';
|
||||
import requestCreator from './libs/requestCreator';
|
||||
import renderTodaysStats from './utils/renderTodaysStats';
|
||||
import { generatePaginationItems, setPage, getPage } from './utils/pagination';
|
||||
import renderPopup from './utils/renderPopup';
|
||||
import renderEnnoblements from './utils/renderEnnoblements';
|
||||
import {
|
||||
generatePaginationItems,
|
||||
getContainerStyles,
|
||||
setPage,
|
||||
getPage,
|
||||
} from './utils/pagination';
|
||||
import getIDFromURL from './utils/getIDFromURL';
|
||||
import getCurrentServer from './utils/getCurrentServer';
|
||||
import formatDate from './utils/formatDate';
|
||||
import renderPopup from './utils/renderPopup';
|
||||
import { formatPlayerURL } from './utils/twstats';
|
||||
import {
|
||||
formatTribeURL,
|
||||
|
@ -21,7 +27,7 @@ import { setItem, getItem } from './utils/localStorage';
|
|||
// @namespace https://github.com/tribalwarshelp/scripts
|
||||
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
|
||||
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedPlayerProfile.js
|
||||
// @version 0.7.2
|
||||
// @version 1
|
||||
// @description Extended Player Profile
|
||||
// @author Kichiyaki http://dawid-wysokinski.pl/
|
||||
// @match *://*/game.php*&screen=info_player*
|
||||
|
@ -167,7 +173,6 @@ const ENNOBLEMENTS_QUERY = `
|
|||
}
|
||||
}
|
||||
`;
|
||||
const ENNOBLEMENTS_PAGINATION_CONTAINER_ID = 'ennoblementsPagination';
|
||||
const ENNOBLEMENTS_PER_PAGE = 15;
|
||||
|
||||
const profileInfoTBody = document.querySelector('#player_info > tbody');
|
||||
|
@ -487,7 +492,7 @@ const renderTribeChanges = (e, currentPage, tribeChanges) => {
|
|||
currentPage,
|
||||
});
|
||||
const html = `
|
||||
<div id="${TRIBE_CHANGES_PAGINATION_CONTAINER_ID}">
|
||||
<div style="${getContainerStyles()}" id="${TRIBE_CHANGES_PAGINATION_CONTAINER_ID}">
|
||||
${paginationItems.join('')}
|
||||
</div>
|
||||
<table class="vis" style="border-collapse: separate; border-spacing: 2px; width: 100%;">
|
||||
|
@ -577,7 +582,7 @@ const renderPlayerHistory = (
|
|||
currentPage,
|
||||
});
|
||||
const html = `
|
||||
<div id="${PLAYER_HISTORY_PAGINATION_CONTAINER_ID}">
|
||||
<div style="${getContainerStyles()}" id="${PLAYER_HISTORY_PAGINATION_CONTAINER_ID}">
|
||||
${paginationItems.join('')}
|
||||
</div>
|
||||
<table class="vis" style="border-collapse: separate; border-spacing: 2px; width: 100%;">
|
||||
|
@ -713,87 +718,6 @@ const handleShowPlayerHistoryClick = async (e) => {
|
|||
}
|
||||
};
|
||||
|
||||
const renderPlayerEnnoblements = (e, currentPage, ennoblements) => {
|
||||
const paginationItems = generatePaginationItems({
|
||||
total: ennoblements.total,
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
currentPage,
|
||||
});
|
||||
const getPlayerTd = (player, tribe) => {
|
||||
if (player) {
|
||||
return `<td><a href="${formatPlayerURLTribalWars(player.id)}">${
|
||||
player.name
|
||||
} (${
|
||||
tribe ? `<a href="${formatTribeURL(tribe.id)}">${tribe.tag}</a>` : '-'
|
||||
})</a></td>`;
|
||||
}
|
||||
return '<td>-</td>';
|
||||
};
|
||||
const html = `
|
||||
<div id="${ENNOBLEMENTS_PAGINATION_CONTAINER_ID}">
|
||||
${paginationItems.join('')}
|
||||
</div>
|
||||
<table class="vis" style="border-collapse: separate; border-spacing: 2px; width: 100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
Date
|
||||
</th>
|
||||
<th>
|
||||
Village
|
||||
</th>
|
||||
<th>
|
||||
New Owner
|
||||
</th>
|
||||
<th>
|
||||
Old Owner
|
||||
</th>
|
||||
</tr>
|
||||
${ennoblements.items
|
||||
.map((ennoblement) => {
|
||||
let rowHTML =
|
||||
'<tr>' + `<td>${formatDate(ennoblement.ennobledAt)}</td>`;
|
||||
if (ennoblement.village) {
|
||||
rowHTML += `<td><a href="${formatVillageURL(
|
||||
ennoblement.village.id
|
||||
)}">${formatVillageName(
|
||||
ennoblement.village.name,
|
||||
ennoblement.village.x,
|
||||
ennoblement.village.y
|
||||
)}</a></td>`;
|
||||
} else {
|
||||
rowHTML += '<td>-</td>';
|
||||
}
|
||||
|
||||
rowHTML += getPlayerTd(
|
||||
ennoblement.newOwner,
|
||||
ennoblement.newOwnerTribe
|
||||
);
|
||||
rowHTML += getPlayerTd(
|
||||
ennoblement.oldOwner,
|
||||
ennoblement.oldOwnerTribe
|
||||
);
|
||||
|
||||
return rowHTML + '</tr>';
|
||||
})
|
||||
.join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
|
||||
renderPopup({
|
||||
e,
|
||||
title: `Ennoblements`,
|
||||
id: 'ennoblements',
|
||||
html,
|
||||
});
|
||||
|
||||
addPaginationListeners(
|
||||
ENNOBLEMENTS_PAGINATION_CONTAINER_ID,
|
||||
handleShowPlayerEnnoblementsClick
|
||||
);
|
||||
};
|
||||
|
||||
const handleShowPlayerEnnoblementsClick = async (e) => {
|
||||
e.preventDefault();
|
||||
const page = getPage(e.target);
|
||||
|
@ -813,7 +737,11 @@ const handleShowPlayerEnnoblementsClick = async (e) => {
|
|||
server: SERVER,
|
||||
},
|
||||
});
|
||||
renderPlayerEnnoblements(e, page, data.ennoblements);
|
||||
renderEnnoblements(e, data.ennoblements, {
|
||||
currentPage: page,
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
onPageChange: handleShowPlayerEnnoblementsClick,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import isURL from 'validator/lib/isURL';
|
||||
import requestCreator from './libs/requestCreator';
|
||||
import { setPage, getPage } from './utils/pagination';
|
||||
import renderTodaysStats from './utils/renderTodaysStats';
|
||||
import renderEnnoblements from './utils/renderEnnoblements';
|
||||
import getIDFromURL from './utils/getIDFromURL';
|
||||
import getCurrentServer from './utils/getCurrentServer';
|
||||
import { setItem, getItem } from './utils/localStorage';
|
||||
|
@ -12,7 +14,7 @@ import { formatPlayerURL } from './utils/twstats';
|
|||
// @namespace https://github.com/tribalwarshelp/scripts
|
||||
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedTribeProfile.js
|
||||
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/extendedTribeProfile.js
|
||||
// @version 0.3.1
|
||||
// @version 0.4
|
||||
// @description Extended Tribe Profile
|
||||
// @author Kichiyaki http://dawid-wysokinski.pl/
|
||||
// @match *://*/game.php*&screen=info_ally*
|
||||
|
@ -67,9 +69,43 @@ const TRIBE_QUERY = `
|
|||
}
|
||||
}
|
||||
`;
|
||||
const ENNOBLEMENTS_QUERY = `
|
||||
query ennoblements($server: String!, $filter: EnnoblementFilter!) {
|
||||
ennoblements(server: $server, filter: $filter) {
|
||||
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;
|
||||
const profileInfoTBody = document.querySelector(
|
||||
'#content_value > table:nth-child(3) > tbody > tr > td:nth-child(1) > table > tbody'
|
||||
);
|
||||
const actionsContainer = profileInfoTBody;
|
||||
const otherElementsContainer = document.querySelector(
|
||||
'#content_value > table:nth-child(3) > tbody > tr > td:nth-child(2)'
|
||||
);
|
||||
|
@ -222,10 +258,56 @@ const render = ({ tribe, dailyTribeStats, players }) => {
|
|||
}
|
||||
};
|
||||
|
||||
const handleShowTribeEnnoblementsClick = async (e) => {
|
||||
e.preventDefault();
|
||||
const page = getPage(e.target);
|
||||
if (!isNaN(page)) {
|
||||
const data = await requestCreator({
|
||||
query: ENNOBLEMENTS_QUERY,
|
||||
variables: {
|
||||
filter: {
|
||||
or: {
|
||||
oldOwnerTribeID: [TRIBE_ID],
|
||||
newOwnerTribeID: [TRIBE_ID],
|
||||
},
|
||||
offset: ENNOBLEMENTS_PER_PAGE * (page - 1),
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
sort: 'ennobledAt DESC',
|
||||
},
|
||||
server: SERVER,
|
||||
},
|
||||
});
|
||||
renderEnnoblements(e, data.ennoblements, {
|
||||
currentPage: page,
|
||||
limit: ENNOBLEMENTS_PER_PAGE,
|
||||
onPageChange: handleShowTribeEnnoblementsClick,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const wrapAction = (action) => {
|
||||
const actionWrapperTd = document.createElement('td');
|
||||
actionWrapperTd.colSpan = '2';
|
||||
actionWrapperTd.append(action);
|
||||
const actionWrapperTr = document.createElement('tr');
|
||||
actionWrapperTr.appendChild(actionWrapperTd);
|
||||
return actionWrapperTr;
|
||||
};
|
||||
|
||||
const renderActions = () => {
|
||||
const showEnnoblements = document.createElement('a');
|
||||
showEnnoblements.href = '#';
|
||||
setPage(showEnnoblements, '1');
|
||||
showEnnoblements.innerHTML = 'Show tribe ennoblements';
|
||||
showEnnoblements.addEventListener('click', handleShowTribeEnnoblementsClick);
|
||||
actionsContainer.appendChild(wrapAction(showEnnoblements));
|
||||
};
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
document.querySelector('#content_value > table:nth-child(3)').style.width =
|
||||
'100%';
|
||||
renderActions();
|
||||
|
||||
const dataFromCache = loadDataFromCache();
|
||||
if (dataFromCache && dataFromCache.tribe) {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
const ATTRIBUTE = 'data-page';
|
||||
|
||||
export const getContainerStyles = () => {
|
||||
return 'display: flex; flex-direction: row; flex-wrap: wrap;';
|
||||
};
|
||||
|
||||
export const setPage = (el, page = 1) => {
|
||||
if (!el instanceof HTMLElement) {
|
||||
throw new Error('Expected HTMLElement as the first argument');
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
import { generatePaginationItems, getContainerStyles } from './pagination';
|
||||
import renderPopup from './renderPopup';
|
||||
import formatDate from './formatDate';
|
||||
import {
|
||||
formatTribeURL,
|
||||
formatPlayerURL as formatPlayerURLTribalWars,
|
||||
formatVillageName,
|
||||
formatVillageURL,
|
||||
} from './tribalwars';
|
||||
|
||||
const ENNOBLEMENTS_PAGINATION_CONTAINER_ID = 'ennoblementsPagination';
|
||||
|
||||
const getPlayerTd = (player, tribe) => {
|
||||
if (player) {
|
||||
return `<td><a href="${formatPlayerURLTribalWars(player.id)}">${
|
||||
player.name
|
||||
} (${
|
||||
tribe ? `<a href="${formatTribeURL(tribe.id)}">${tribe.tag}</a>` : '-'
|
||||
})</a></td>`;
|
||||
}
|
||||
return '<td>-</td>';
|
||||
};
|
||||
|
||||
export default (
|
||||
e,
|
||||
ennoblements,
|
||||
{ limit = 0, currentPage = 1, onPageChange = () => {} } = {}
|
||||
) => {
|
||||
const paginationItems = generatePaginationItems({
|
||||
total: ennoblements.total,
|
||||
limit,
|
||||
currentPage,
|
||||
});
|
||||
const html = `
|
||||
<div style="${getContainerStyles()}" id="${ENNOBLEMENTS_PAGINATION_CONTAINER_ID}">
|
||||
${paginationItems.join('')}
|
||||
</div>
|
||||
<table class="vis" style="border-collapse: separate; border-spacing: 2px; width: 100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
Date
|
||||
</th>
|
||||
<th>
|
||||
Village
|
||||
</th>
|
||||
<th>
|
||||
New Owner
|
||||
</th>
|
||||
<th>
|
||||
Old Owner
|
||||
</th>
|
||||
</tr>
|
||||
${ennoblements.items
|
||||
.map((ennoblement) => {
|
||||
let rowHTML =
|
||||
'<tr>' + `<td>${formatDate(ennoblement.ennobledAt)}</td>`;
|
||||
if (ennoblement.village) {
|
||||
rowHTML += `<td><a href="${formatVillageURL(
|
||||
ennoblement.village.id
|
||||
)}">${formatVillageName(
|
||||
ennoblement.village.name,
|
||||
ennoblement.village.x,
|
||||
ennoblement.village.y
|
||||
)}</a></td>`;
|
||||
} else {
|
||||
rowHTML += '<td>-</td>';
|
||||
}
|
||||
|
||||
rowHTML += getPlayerTd(
|
||||
ennoblement.newOwner,
|
||||
ennoblement.newOwnerTribe
|
||||
);
|
||||
rowHTML += getPlayerTd(
|
||||
ennoblement.oldOwner,
|
||||
ennoblement.oldOwnerTribe
|
||||
);
|
||||
|
||||
return rowHTML + '</tr>';
|
||||
})
|
||||
.join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
|
||||
renderPopup({
|
||||
e,
|
||||
title: `Ennoblements`,
|
||||
id: 'ennoblements',
|
||||
html,
|
||||
});
|
||||
|
||||
document
|
||||
.querySelectorAll('#' + ENNOBLEMENTS_PAGINATION_CONTAINER_ID + ' a')
|
||||
.forEach((el) => {
|
||||
el.addEventListener('click', onPageChange);
|
||||
});
|
||||
};
|
Reference in New Issue