extendedTribeProfile: add OD, ODA, ODS, ODD, daily growth and link to TWStats to member table
This commit is contained in:
parent
67e298ad62
commit
d329070c9c
|
@ -117,7 +117,469 @@ parcelRequire = (function (modules, cache, entry, globalName) {
|
|||
}
|
||||
|
||||
return newRequire;
|
||||
})({"Ph2E":[function(require,module,exports) {
|
||||
})({"d3m2":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = assertString;
|
||||
|
||||
function _typeof(obj) {
|
||||
"@babel/helpers - typeof";
|
||||
|
||||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
||||
_typeof = function _typeof(obj) {
|
||||
return typeof obj;
|
||||
};
|
||||
} else {
|
||||
_typeof = function _typeof(obj) {
|
||||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
||||
};
|
||||
}
|
||||
|
||||
return _typeof(obj);
|
||||
}
|
||||
|
||||
function assertString(input) {
|
||||
var isString = typeof input === 'string' || input instanceof String;
|
||||
|
||||
if (!isString) {
|
||||
var invalidType;
|
||||
|
||||
if (input === null) {
|
||||
invalidType = 'null';
|
||||
} else {
|
||||
invalidType = _typeof(input);
|
||||
|
||||
if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) {
|
||||
invalidType = input.constructor.name;
|
||||
} else {
|
||||
invalidType = "a ".concat(invalidType);
|
||||
}
|
||||
}
|
||||
|
||||
throw new TypeError("Expected string but received ".concat(invalidType, "."));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
module.exports.default = exports.default;
|
||||
},{}],"hxfi":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = merge;
|
||||
|
||||
function merge() {
|
||||
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
var defaults = arguments.length > 1 ? arguments[1] : undefined;
|
||||
|
||||
for (var key in defaults) {
|
||||
if (typeof obj[key] === 'undefined') {
|
||||
obj[key] = defaults[key];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
module.exports.default = exports.default;
|
||||
},{}],"KGu6":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = isFQDN;
|
||||
|
||||
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
||||
|
||||
var _merge = _interopRequireDefault(require("./util/merge"));
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
var default_fqdn_options = {
|
||||
require_tld: true,
|
||||
allow_underscores: false,
|
||||
allow_trailing_dot: false
|
||||
};
|
||||
|
||||
function isFQDN(str, options) {
|
||||
(0, _assertString.default)(str);
|
||||
options = (0, _merge.default)(options, default_fqdn_options);
|
||||
/* Remove the optional trailing dot before checking validity */
|
||||
|
||||
if (options.allow_trailing_dot && str[str.length - 1] === '.') {
|
||||
str = str.substring(0, str.length - 1);
|
||||
}
|
||||
|
||||
var parts = str.split('.');
|
||||
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
if (parts[i].length > 63) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.require_tld) {
|
||||
var tld = parts.pop();
|
||||
|
||||
if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
|
||||
return false;
|
||||
} // disallow spaces && special characers
|
||||
|
||||
|
||||
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (var part, _i = 0; _i < parts.length; _i++) {
|
||||
part = parts[_i];
|
||||
|
||||
if (options.allow_underscores) {
|
||||
part = part.replace(/_/g, '');
|
||||
}
|
||||
|
||||
if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) {
|
||||
return false;
|
||||
} // disallow full-width chars
|
||||
|
||||
|
||||
if (/[\uff01-\uff5e]/.test(part)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (part[0] === '-' || part[part.length - 1] === '-') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
module.exports.default = exports.default;
|
||||
},{"./util/assertString":"d3m2","./util/merge":"hxfi"}],"NHAn":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = isIP;
|
||||
|
||||
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
/**
|
||||
11.3. Examples
|
||||
|
||||
The following addresses
|
||||
|
||||
fe80::1234 (on the 1st link of the node)
|
||||
ff02::5678 (on the 5th link of the node)
|
||||
ff08::9abc (on the 10th organization of the node)
|
||||
|
||||
would be represented as follows:
|
||||
|
||||
fe80::1234%1
|
||||
ff02::5678%5
|
||||
ff08::9abc%10
|
||||
|
||||
(Here we assume a natural translation from a zone index to the
|
||||
<zone_id> part, where the Nth zone of any scope is translated into
|
||||
"N".)
|
||||
|
||||
If we use interface names as <zone_id>, those addresses could also be
|
||||
represented as follows:
|
||||
|
||||
fe80::1234%ne0
|
||||
ff02::5678%pvc1.3
|
||||
ff08::9abc%interface10
|
||||
|
||||
where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
|
||||
to the 5th link, and "interface10" belongs to the 10th organization.
|
||||
* * */
|
||||
|
||||
|
||||
var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
|
||||
var ipv6Block = /^[0-9A-F]{1,4}$/i;
|
||||
|
||||
function isIP(str) {
|
||||
var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
||||
(0, _assertString.default)(str);
|
||||
version = String(version);
|
||||
|
||||
if (!version) {
|
||||
return isIP(str, 4) || isIP(str, 6);
|
||||
} else if (version === '4') {
|
||||
if (!ipv4Maybe.test(str)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var parts = str.split('.').sort(function (a, b) {
|
||||
return a - b;
|
||||
});
|
||||
return parts[3] <= 255;
|
||||
} else if (version === '6') {
|
||||
var addressAndZone = [str]; // ipv6 addresses could have scoped architecture
|
||||
// according to https://tools.ietf.org/html/rfc4007#section-11
|
||||
|
||||
if (str.includes('%')) {
|
||||
addressAndZone = str.split('%');
|
||||
|
||||
if (addressAndZone.length !== 2) {
|
||||
// it must be just two parts
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!addressAndZone[0].includes(':')) {
|
||||
// the first part must be the address
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addressAndZone[1] === '') {
|
||||
// the second part must not be empty
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var blocks = addressAndZone[0].split(':');
|
||||
var foundOmissionBlock = false; // marker to indicate ::
|
||||
// At least some OS accept the last 32 bits of an IPv6 address
|
||||
// (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says
|
||||
// that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses,
|
||||
// and '::a.b.c.d' is deprecated, but also valid.
|
||||
|
||||
var foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4);
|
||||
var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8;
|
||||
|
||||
if (blocks.length > expectedNumberOfBlocks) {
|
||||
return false;
|
||||
} // initial or final ::
|
||||
|
||||
|
||||
if (str === '::') {
|
||||
return true;
|
||||
} else if (str.substr(0, 2) === '::') {
|
||||
blocks.shift();
|
||||
blocks.shift();
|
||||
foundOmissionBlock = true;
|
||||
} else if (str.substr(str.length - 2) === '::') {
|
||||
blocks.pop();
|
||||
blocks.pop();
|
||||
foundOmissionBlock = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < blocks.length; ++i) {
|
||||
// test for a :: which can not be at the string start/end
|
||||
// since those cases have been handled above
|
||||
if (blocks[i] === '' && i > 0 && i < blocks.length - 1) {
|
||||
if (foundOmissionBlock) {
|
||||
return false; // multiple :: in address
|
||||
}
|
||||
|
||||
foundOmissionBlock = true;
|
||||
} else if (foundIPv4TransitionBlock && i === blocks.length - 1) {// it has been checked before that the last
|
||||
// block is a valid IPv4 address
|
||||
} else if (!ipv6Block.test(blocks[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundOmissionBlock) {
|
||||
return blocks.length >= 1;
|
||||
}
|
||||
|
||||
return blocks.length === expectedNumberOfBlocks;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
module.exports.default = exports.default;
|
||||
},{"./util/assertString":"d3m2"}],"XMVV":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = isURL;
|
||||
|
||||
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
||||
|
||||
var _isFQDN = _interopRequireDefault(require("./isFQDN"));
|
||||
|
||||
var _isIP = _interopRequireDefault(require("./isIP"));
|
||||
|
||||
var _merge = _interopRequireDefault(require("./util/merge"));
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
/*
|
||||
options for isURL method
|
||||
|
||||
require_protocol - if set as true isURL will return false if protocol is not present in the URL
|
||||
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
|
||||
protocols - valid protocols can be modified with this option
|
||||
require_host - if set as false isURL will not check if host is present in the URL
|
||||
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
|
||||
|
||||
*/
|
||||
|
||||
|
||||
var default_url_options = {
|
||||
protocols: ['http', 'https', 'ftp'],
|
||||
require_tld: true,
|
||||
require_protocol: false,
|
||||
require_host: true,
|
||||
require_valid_protocol: true,
|
||||
allow_underscores: false,
|
||||
allow_trailing_dot: false,
|
||||
allow_protocol_relative_urls: false
|
||||
};
|
||||
var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
|
||||
|
||||
function isRegExp(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||
}
|
||||
|
||||
function checkHost(host, matches) {
|
||||
for (var i = 0; i < matches.length; i++) {
|
||||
var match = matches[i];
|
||||
|
||||
if (host === match || isRegExp(match) && match.test(host)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isURL(url, options) {
|
||||
(0, _assertString.default)(url);
|
||||
|
||||
if (!url || url.length >= 2083 || /[\s<>]/.test(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (url.indexOf('mailto:') === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
options = (0, _merge.default)(options, default_url_options);
|
||||
var protocol, auth, host, hostname, port, port_str, split, ipv6;
|
||||
split = url.split('#');
|
||||
url = split.shift();
|
||||
split = url.split('?');
|
||||
url = split.shift();
|
||||
split = url.split('://');
|
||||
|
||||
if (split.length > 1) {
|
||||
protocol = split.shift().toLowerCase();
|
||||
|
||||
if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
|
||||
return false;
|
||||
}
|
||||
} else if (options.require_protocol) {
|
||||
return false;
|
||||
} else if (url.substr(0, 2) === '//') {
|
||||
if (!options.allow_protocol_relative_urls) {
|
||||
return false;
|
||||
}
|
||||
|
||||
split[0] = url.substr(2);
|
||||
}
|
||||
|
||||
url = split.join('://');
|
||||
|
||||
if (url === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
split = url.split('/');
|
||||
url = split.shift();
|
||||
|
||||
if (url === '' && !options.require_host) {
|
||||
return true;
|
||||
}
|
||||
|
||||
split = url.split('@');
|
||||
|
||||
if (split.length > 1) {
|
||||
if (options.disallow_auth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auth = split.shift();
|
||||
|
||||
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
hostname = split.join('@');
|
||||
port_str = null;
|
||||
ipv6 = null;
|
||||
var ipv6_match = hostname.match(wrapped_ipv6);
|
||||
|
||||
if (ipv6_match) {
|
||||
host = '';
|
||||
ipv6 = ipv6_match[1];
|
||||
port_str = ipv6_match[2] || null;
|
||||
} else {
|
||||
split = hostname.split(':');
|
||||
host = split.shift();
|
||||
|
||||
if (split.length) {
|
||||
port_str = split.join(':');
|
||||
}
|
||||
}
|
||||
|
||||
if (port_str !== null) {
|
||||
port = parseInt(port_str, 10);
|
||||
|
||||
if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(0, _isIP.default)(host) && !(0, _isFQDN.default)(host, options) && (!ipv6 || !(0, _isIP.default)(ipv6, 6))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
host = host || ipv6;
|
||||
|
||||
if (options.host_whitelist && !checkHost(host, options.host_whitelist)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
module.exports.default = exports.default;
|
||||
},{"./util/assertString":"d3m2","./isFQDN":"KGu6","./isIP":"NHAn","./util/merge":"hxfi"}],"Ph2E":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
|
@ -271,9 +733,26 @@ var _default = (date, options) => {
|
|||
};
|
||||
|
||||
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;
|
||||
},{}],"r4nF":[function(require,module,exports) {
|
||||
"use strict";
|
||||
|
||||
var _isURL = _interopRequireDefault(require("validator/lib/isURL"));
|
||||
|
||||
var _requestCreator = _interopRequireDefault(require("./libs/requestCreator"));
|
||||
|
||||
var _renderTodaysStats = _interopRequireDefault(require("./utils/renderTodaysStats"));
|
||||
|
@ -286,6 +765,8 @@ var _localStorage = require("./utils/localStorage");
|
|||
|
||||
var _formatDate = _interopRequireDefault(require("./utils/formatDate"));
|
||||
|
||||
var _twstats = require("./utils/twstats");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ==UserScript==
|
||||
|
@ -293,7 +774,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.1
|
||||
// @version 0.3
|
||||
// @description Extended Tribe Profile
|
||||
// @author Kichiyaki http://dawid-wysokinski.pl/
|
||||
// @match *://*/game.php*&screen=info_ally*
|
||||
|
@ -303,9 +784,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|||
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!, $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 }\n";
|
||||
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 profileInfoTBody = document.querySelector('#content_value > table:nth-child(3) > tbody > tr > td:nth-child(1) > table > tbody');
|
||||
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');
|
||||
|
||||
const loadDataFromCache = () => {
|
||||
return (0, _localStorage.getItem)(LOCAL_STORAGE_KEY);
|
||||
|
@ -316,7 +798,20 @@ const cacheTribeData = function cacheTribeData() {
|
|||
(0, _localStorage.setItem)(LOCAL_STORAGE_KEY, data);
|
||||
};
|
||||
|
||||
const getMembersIDs = () => {
|
||||
const ids = [];
|
||||
membersContainer.querySelectorAll('a').forEach(a => {
|
||||
const href = a.getAttribute('href');
|
||||
|
||||
if (href.includes('info_player')) {
|
||||
ids.push((0, _getIDFromURL.default)(href));
|
||||
}
|
||||
});
|
||||
return ids;
|
||||
};
|
||||
|
||||
const loadData = async () => {
|
||||
const membersIDs = getMembersIDs();
|
||||
const data = await (0, _requestCreator.default)({
|
||||
query: TRIBE_QUERY,
|
||||
variables: {
|
||||
|
@ -326,6 +821,11 @@ const loadData = async () => {
|
|||
sort: 'createDate DESC',
|
||||
limit: 1,
|
||||
tribeID: [TRIBE_ID]
|
||||
},
|
||||
playerFilter: {
|
||||
sort: 'rank ASC',
|
||||
limit: membersIDs.length,
|
||||
id: membersIDs
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -353,10 +853,56 @@ const renderTr = (_ref) => {
|
|||
tr.children[1].innerHTML = data;
|
||||
};
|
||||
|
||||
const extendMembersData = players => {
|
||||
membersContainer.parentElement.style.width = '100%';
|
||||
const heading = membersContainer.querySelector('tr:first-child');
|
||||
|
||||
if (heading.children.length !== 11) {
|
||||
['ODA', 'ODD', 'ODS', 'OD', 'Daily growth', 'Player links'].forEach(v => {
|
||||
const th = document.createElement('th');
|
||||
th.innerHTML = v;
|
||||
heading.appendChild(th);
|
||||
});
|
||||
}
|
||||
|
||||
membersContainer.querySelectorAll('tr').forEach(tr => {
|
||||
const a = tr.querySelector('a');
|
||||
|
||||
if (!a) {
|
||||
return;
|
||||
}
|
||||
|
||||
const playerID = (0, _getIDFromURL.default)(a.getAttribute('href'));
|
||||
const player = players.items.find(p => p.id === playerID);
|
||||
|
||||
if (player) {
|
||||
[[player.scoreAtt, player.rankAtt], [player.scoreDef, player.rankDef], [player.scoreSup, player.rankSup], [player.scoreTotal, player.rankTotal], player.dailyGrowth, [(0, _twstats.formatPlayerURL)(SERVER, player.id), 'TWStats']].forEach((data, index) => {
|
||||
let td = tr.children[5 + index];
|
||||
|
||||
if (!td) {
|
||||
td = document.createElement('td');
|
||||
tr.appendChild(td);
|
||||
}
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
if (typeof data[0] === 'number') {
|
||||
td.innerHTML = "".concat(data[0].toLocaleString(), " (<strong>").concat(data[1], "</strong>)");
|
||||
} else if ((0, _isURL.default)(data[0])) {
|
||||
td.innerHTML = "<a href=\"".concat(data[0], "\">").concat(data[1], "</a>");
|
||||
}
|
||||
} else if (typeof data === 'number') {
|
||||
td.innerHTML = data.toLocaleString();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const render = (_ref2) => {
|
||||
let {
|
||||
tribe,
|
||||
dailyTribeStats
|
||||
dailyTribeStats,
|
||||
players
|
||||
} = _ref2;
|
||||
[{
|
||||
title: 'Created at:',
|
||||
|
@ -385,10 +931,15 @@ const render = (_ref2) => {
|
|||
if (dailyTribeStats && dailyTribeStats.items.length > 0) {
|
||||
(0, _renderTodaysStats.default)(otherElementsContainer, dailyTribeStats.items[0]);
|
||||
}
|
||||
|
||||
if (players && players.items.length > 0) {
|
||||
extendMembersData(players);
|
||||
}
|
||||
};
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
document.querySelector('#content_value > table:nth-child(3)').style.width = '100%';
|
||||
const dataFromCache = loadDataFromCache();
|
||||
|
||||
if (dataFromCache && dataFromCache.tribe) {
|
||||
|
@ -404,4 +955,4 @@ const render = (_ref2) => {
|
|||
console.log('extended tribe profile', error);
|
||||
}
|
||||
})();
|
||||
},{"./libs/requestCreator":"Ph2E","./utils/renderTodaysStats":"dPMc","./utils/getIDFromURL":"tQUs","./utils/getCurrentServer":"DMkL","./utils/localStorage":"KWxH","./utils/formatDate":"V6Mf"}]},{},["r4nF"], null)
|
||||
},{"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)
|
|
@ -10,7 +10,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"date-fns": "^2.14.0",
|
||||
"parcel": "^1.12.4"
|
||||
"parcel": "^1.12.4",
|
||||
"validator": "^13.1.1"
|
||||
},
|
||||
"browserslist": [
|
||||
"since 2017-06"
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
import isURL from 'validator/lib/isURL';
|
||||
import requestCreator from './libs/requestCreator';
|
||||
import renderTodaysStats from './utils/renderTodaysStats';
|
||||
import getIDFromURL from './utils/getIDFromURL';
|
||||
import getCurrentServer from './utils/getCurrentServer';
|
||||
import { setItem, getItem } from './utils/localStorage';
|
||||
import formatDate from './utils/formatDate';
|
||||
import { formatPlayerURL } from './utils/twstats';
|
||||
|
||||
// ==UserScript==
|
||||
// @name Extended Tribe Profile
|
||||
// @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.1
|
||||
// @version 0.3
|
||||
// @description Extended Tribe Profile
|
||||
// @author Kichiyaki http://dawid-wysokinski.pl/
|
||||
// @match *://*/game.php*&screen=info_ally*
|
||||
|
@ -22,7 +24,7 @@ const SERVER = getCurrentServer();
|
|||
const TRIBE_ID = getIDFromURL(window.location.search);
|
||||
const LOCAL_STORAGE_KEY = 'kichiyaki_extended_tribe_profile' + TRIBE_ID;
|
||||
const TRIBE_QUERY = `
|
||||
query tribe($server: String!, $id: Int!, $dailyTribeStatsFilter: DailyTribeStatsFilter!) {
|
||||
query tribe($server: String!, $id: Int!, $playerFilter: PlayerFilter!, $dailyTribeStatsFilter: DailyTribeStatsFilter!) {
|
||||
tribe(server: $server, id: $id) {
|
||||
id
|
||||
bestRank
|
||||
|
@ -48,6 +50,21 @@ const TRIBE_QUERY = `
|
|||
villages
|
||||
}
|
||||
}
|
||||
players(server: $server, filter: $playerFilter) {
|
||||
items {
|
||||
id
|
||||
rankAtt
|
||||
rankDef
|
||||
rankSup
|
||||
rankTotal
|
||||
scoreAtt
|
||||
scoreAtt
|
||||
scoreDef
|
||||
scoreSup
|
||||
scoreTotal
|
||||
dailyGrowth
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const profileInfoTBody = document.querySelector(
|
||||
|
@ -56,6 +73,9 @@ const profileInfoTBody = document.querySelector(
|
|||
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'
|
||||
);
|
||||
|
||||
const loadDataFromCache = () => {
|
||||
return getItem(LOCAL_STORAGE_KEY);
|
||||
|
@ -65,7 +85,19 @@ const cacheTribeData = (data = {}) => {
|
|||
setItem(LOCAL_STORAGE_KEY, data);
|
||||
};
|
||||
|
||||
const getMembersIDs = () => {
|
||||
const ids = [];
|
||||
membersContainer.querySelectorAll('a').forEach((a) => {
|
||||
const href = a.getAttribute('href');
|
||||
if (href.includes('info_player')) {
|
||||
ids.push(getIDFromURL(href));
|
||||
}
|
||||
});
|
||||
return ids;
|
||||
};
|
||||
|
||||
const loadData = async () => {
|
||||
const membersIDs = getMembersIDs();
|
||||
const data = await requestCreator({
|
||||
query: TRIBE_QUERY,
|
||||
variables: {
|
||||
|
@ -76,6 +108,11 @@ const loadData = async () => {
|
|||
limit: 1,
|
||||
tribeID: [TRIBE_ID],
|
||||
},
|
||||
playerFilter: {
|
||||
sort: 'rank ASC',
|
||||
limit: membersIDs.length,
|
||||
id: membersIDs,
|
||||
},
|
||||
},
|
||||
});
|
||||
cacheTribeData(data);
|
||||
|
@ -95,7 +132,54 @@ const renderTr = ({ title, data, id }) => {
|
|||
tr.children[1].innerHTML = data;
|
||||
};
|
||||
|
||||
const render = ({ tribe, dailyTribeStats }) => {
|
||||
const extendMembersData = (players) => {
|
||||
membersContainer.parentElement.style.width = '100%';
|
||||
const heading = membersContainer.querySelector('tr:first-child');
|
||||
if (heading.children.length !== 11) {
|
||||
['ODA', 'ODD', 'ODS', 'OD', 'Daily growth', 'Player links'].forEach((v) => {
|
||||
const th = document.createElement('th');
|
||||
th.innerHTML = v;
|
||||
heading.appendChild(th);
|
||||
});
|
||||
}
|
||||
membersContainer.querySelectorAll('tr').forEach((tr) => {
|
||||
const a = tr.querySelector('a');
|
||||
if (!a) {
|
||||
return;
|
||||
}
|
||||
const playerID = getIDFromURL(a.getAttribute('href'));
|
||||
const player = players.items.find((p) => p.id === playerID);
|
||||
if (player) {
|
||||
[
|
||||
[player.scoreAtt, player.rankAtt],
|
||||
[player.scoreDef, player.rankDef],
|
||||
[player.scoreSup, player.rankSup],
|
||||
[player.scoreTotal, player.rankTotal],
|
||||
player.dailyGrowth,
|
||||
[formatPlayerURL(SERVER, player.id), 'TWStats'],
|
||||
].forEach((data, index) => {
|
||||
let td = tr.children[5 + index];
|
||||
if (!td) {
|
||||
td = document.createElement('td');
|
||||
tr.appendChild(td);
|
||||
}
|
||||
if (Array.isArray(data)) {
|
||||
if (typeof data[0] === 'number') {
|
||||
td.innerHTML = `${data[0].toLocaleString()} (<strong>${
|
||||
data[1]
|
||||
}</strong>)`;
|
||||
} else if (isURL(data[0])) {
|
||||
td.innerHTML = `<a href="${data[0]}">${data[1]}</a>`;
|
||||
}
|
||||
} else if (typeof data === 'number') {
|
||||
td.innerHTML = data.toLocaleString();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const render = ({ tribe, dailyTribeStats, players }) => {
|
||||
[
|
||||
{
|
||||
title: 'Created at:',
|
||||
|
@ -132,10 +216,17 @@ const render = ({ tribe, dailyTribeStats }) => {
|
|||
if (dailyTribeStats && dailyTribeStats.items.length > 0) {
|
||||
renderTodaysStats(otherElementsContainer, dailyTribeStats.items[0]);
|
||||
}
|
||||
|
||||
if (players && players.items.length > 0) {
|
||||
extendMembersData(players);
|
||||
}
|
||||
};
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
document.querySelector('#content_value > table:nth-child(3)').style.width =
|
||||
'100%';
|
||||
|
||||
const dataFromCache = loadDataFromCache();
|
||||
if (dataFromCache && dataFromCache.tribe) {
|
||||
render(dataFromCache);
|
||||
|
|
|
@ -5080,6 +5080,11 @@ v8-compile-cache@^2.0.0:
|
|||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz#54bc3cdd43317bca91e35dcaf305b1a7237de745"
|
||||
integrity sha512-8OQ9CL+VWyt3JStj7HX7/ciTL2V3Rl1Wf5OL+SNTm0yK1KvtReVulksyeRnCANHHuUxHlQig+JJDlUhBt1NQDQ==
|
||||
|
||||
validator@^13.1.1:
|
||||
version "13.1.1"
|
||||
resolved "https://registry.yarnpkg.com/validator/-/validator-13.1.1.tgz#f8811368473d2173a9d8611572b58c5783f223bf"
|
||||
integrity sha512-8GfPiwzzRoWTg7OV1zva1KvrSemuMkv07MA9TTl91hfhe+wKrsrgVN4H2QSFd/U/FhiU3iWPYVgvbsOGwhyFWw==
|
||||
|
||||
vendors@^1.0.0:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/vendors/-/vendors-1.0.4.tgz#e2b800a53e7a29b93506c3cf41100d16c4c4ad8e"
|
||||
|
|
Reference in New Issue