2020-07-17 11:50:29 +00:00
|
|
|
// modules are defined as an array
|
|
|
|
// [ module function, map of requires ]
|
|
|
|
//
|
|
|
|
// map of requires is short require name -> numeric require
|
|
|
|
//
|
|
|
|
// anything defined in a previous bundle is accessed via the
|
|
|
|
// orig method which is the require for previous bundles
|
|
|
|
parcelRequire = (function (modules, cache, entry, globalName) {
|
|
|
|
// Save the require from previous bundle to this closure if any
|
|
|
|
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
|
|
|
|
var nodeRequire = typeof require === 'function' && require;
|
|
|
|
|
|
|
|
function newRequire(name, jumped) {
|
|
|
|
if (!cache[name]) {
|
|
|
|
if (!modules[name]) {
|
|
|
|
// if we cannot find the module within our internal map or
|
|
|
|
// cache jump to the current global require ie. the last bundle
|
|
|
|
// that was added to the page.
|
|
|
|
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
|
|
|
|
if (!jumped && currentRequire) {
|
|
|
|
return currentRequire(name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are other bundles on this page the require from the
|
|
|
|
// previous one is saved to 'previousRequire'. Repeat this as
|
|
|
|
// many times as there are bundles until the module is found or
|
|
|
|
// we exhaust the require chain.
|
|
|
|
if (previousRequire) {
|
|
|
|
return previousRequire(name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try the node require function if it exists.
|
|
|
|
if (nodeRequire && typeof name === 'string') {
|
|
|
|
return nodeRequire(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
var err = new Error('Cannot find module \'' + name + '\'');
|
|
|
|
err.code = 'MODULE_NOT_FOUND';
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
localRequire.resolve = resolve;
|
|
|
|
localRequire.cache = {};
|
|
|
|
|
|
|
|
var module = cache[name] = new newRequire.Module(name);
|
|
|
|
|
|
|
|
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cache[name].exports;
|
|
|
|
|
|
|
|
function localRequire(x){
|
|
|
|
return newRequire(localRequire.resolve(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolve(x){
|
|
|
|
return modules[name][1][x] || x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Module(moduleName) {
|
|
|
|
this.id = moduleName;
|
|
|
|
this.bundle = newRequire;
|
|
|
|
this.exports = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
newRequire.isParcelRequire = true;
|
|
|
|
newRequire.Module = Module;
|
|
|
|
newRequire.modules = modules;
|
|
|
|
newRequire.cache = cache;
|
|
|
|
newRequire.parent = previousRequire;
|
|
|
|
newRequire.register = function (id, exports) {
|
|
|
|
modules[id] = [function (require, module) {
|
|
|
|
module.exports = exports;
|
|
|
|
}, {}];
|
|
|
|
};
|
|
|
|
|
|
|
|
var error;
|
|
|
|
for (var i = 0; i < entry.length; i++) {
|
|
|
|
try {
|
|
|
|
newRequire(entry[i]);
|
|
|
|
} catch (e) {
|
|
|
|
// Save first error but execute all entries
|
|
|
|
if (!error) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry.length) {
|
|
|
|
// Expose entry point to Node, AMD or browser globals
|
|
|
|
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
|
|
|
var mainExports = newRequire(entry[entry.length - 1]);
|
|
|
|
|
|
|
|
// CommonJS
|
|
|
|
if (typeof exports === "object" && typeof module !== "undefined") {
|
|
|
|
module.exports = mainExports;
|
|
|
|
|
|
|
|
// RequireJS
|
|
|
|
} else if (typeof define === "function" && define.amd) {
|
|
|
|
define(function () {
|
|
|
|
return mainExports;
|
|
|
|
});
|
|
|
|
|
|
|
|
// <script>
|
|
|
|
} else if (globalName) {
|
|
|
|
this[globalName] = mainExports;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override the current require with this new one
|
|
|
|
parcelRequire = newRequire;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
// throw error from earlier, _after updating parcelRequire_
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newRequire;
|
|
|
|
})({"Ph2E":[function(require,module,exports) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.default = exports.API_URI = void 0;
|
|
|
|
const API_URI = 'https://api.tribalwarshelp.com/graphql';
|
|
|
|
exports.API_URI = API_URI;
|
|
|
|
|
|
|
|
var _default = function _default() {
|
|
|
|
let {
|
|
|
|
query,
|
|
|
|
variables = {}
|
|
|
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
|
|
return fetch('https://api.tribalwarshelp.com/graphql', {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
query,
|
|
|
|
variables
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}).then(res => {
|
|
|
|
return res.json();
|
|
|
|
}).then((_ref) => {
|
|
|
|
let {
|
|
|
|
data,
|
|
|
|
errors
|
|
|
|
} = _ref;
|
|
|
|
|
|
|
|
if (errors && Array.isArray(errors) && errors.length > 0) {
|
|
|
|
throw new Error(errors[0].message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise(resolve => resolve(data));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.default = _default;
|
2020-07-17 12:16:07 +00:00
|
|
|
},{}],"yQib":[function(require,module,exports) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.default = void 0;
|
|
|
|
|
|
|
|
var _default = v => v === undefined || v === null;
|
|
|
|
|
|
|
|
exports.default = _default;
|
|
|
|
},{}],"dPMc":[function(require,module,exports) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.default = void 0;
|
|
|
|
|
|
|
|
var _isNil = _interopRequireDefault(require("./isNil"));
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
|
|
const getTodaysStatsTdStyle = value => {
|
|
|
|
const statIncreaseStyle = 'color: #000; background-color: #0f0';
|
|
|
|
const statDecreaseStyle = 'color: #000; background-color: #f00';
|
|
|
|
const defaultStyle = 'color: #000; background-color: #808080';
|
|
|
|
return value > 0 ? statIncreaseStyle : value < 0 ? statDecreaseStyle : defaultStyle;
|
|
|
|
};
|
|
|
|
|
|
|
|
var _default = (container, stats) => {
|
|
|
|
let todaysStats = container.querySelector('#todaysStats');
|
|
|
|
|
|
|
|
if (!todaysStats) {
|
|
|
|
todaysStats = document.createElement('div');
|
|
|
|
todaysStats.id = 'todaysStats';
|
|
|
|
todaysStats.width = '100%';
|
|
|
|
container.prepend(todaysStats);
|
|
|
|
}
|
|
|
|
|
|
|
|
const renderODS = !(0, _isNil.default)(stats.rankSup);
|
|
|
|
todaysStats.innerHTML = "\n <table width=\"100%\" class=\"vis\">\n <tbody>\n <tr>\n <th colspan=\"2\">\n Today's stats\n </th>\n </tr>\n <tr>\n <td>\n Points:\n </td>\n <td style=\"".concat(getTodaysStatsTdStyle(stats.points), "\">\n ").concat(Math.abs(stats.points).toLocaleString(), "\n </td>\n </tr>\n <tr>\n <td>\n Rank:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.rank), "\">\n ").concat(Math.abs(stats.rank), "\n </td>\n </tr>\n <tr>\n <td>\n Villages:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.villages), "\">\n ").concat(Math.abs(stats.villages).toLocaleString(), "\n </td>\n </tr>\n <tr>\n <td>\n ODA:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.scoreAtt), "\">\n ").concat(Math.abs(stats.scoreAtt).toLocaleString(), "\n </td>\n </tr>\n <tr>\n <td>\n ODA Rank:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.rankAtt), "\">\n ").concat(Math.abs(stats.rankAtt), "\n </td>\n </tr>\n <tr>\n <td>\n ODD:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.scoreDef), "\">\n ").concat(Math.abs(stats.scoreDef).toLocaleString(), "\n </td>\n </tr>\n <tr>\n <td>\n ODD Rank:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.rankDef), "\">\n ").concat(Math.abs(stats.rankDef), "\n </td>\n </tr>\n ").concat(renderODS ? "<tr>\n <td>\n ODS:\n </td>\n <td style=\"".concat(getTodaysStatsTdStyle(stats.scoreSup), "\">\n ").concat(Math.abs(stats.scoreSup).toLocaleString(), "\n </td>\n </tr>\n <tr>\n <td>\n ODS Rank:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.rankSup), "\">\n ").concat(Math.abs(stats.rankSup), "\n </td>\n </tr>") : '', "\n <tr>\n <td>\n OD:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.scoreTotal), "\">\n ").concat(Math.abs(stats.scoreTotal).toLocaleString(), "\n </td>\n </tr>\n <tr>\n <td>\n OD Rank:\n </td>\n <td style=\"").concat(getTodaysStatsTdStyle(stats.rankTotal), "\">\n ").concat(Math.abs(stats.rankTotal), "\n </td>\n </tr>\n </tbody>\n </table>\n ");
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.default = _default;
|
|
|
|
},{"./isNil":"yQib"}],"tQUs":[function(require,module,exports) {
|
2020-07-17 11:50:29 +00:00
|
|
|
"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;
|
|
|
|
},{}],"KWxH":[function(require,module,exports) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.setItem = exports.getItem = void 0;
|
|
|
|
|
|
|
|
const getItem = key => {
|
|
|
|
const json = localStorage.getItem(key);
|
|
|
|
let obj = {};
|
|
|
|
|
|
|
|
if (json) {
|
|
|
|
obj = JSON.parse(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getItem = getItem;
|
|
|
|
|
|
|
|
const setItem = (key, payload) => {
|
|
|
|
localStorage.setItem(key, JSON.stringify(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;
|
|
|
|
},{}],"r4nF":[function(require,module,exports) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var _requestCreator = _interopRequireDefault(require("./libs/requestCreator"));
|
|
|
|
|
2020-07-17 12:16:07 +00:00
|
|
|
var _renderTodaysStats = _interopRequireDefault(require("./utils/renderTodaysStats"));
|
|
|
|
|
2020-07-17 11:50:29 +00:00
|
|
|
var _getIDFromURL = _interopRequireDefault(require("./utils/getIDFromURL"));
|
|
|
|
|
|
|
|
var _getCurrentServer = _interopRequireDefault(require("./utils/getCurrentServer"));
|
|
|
|
|
|
|
|
var _localStorage = require("./utils/localStorage");
|
|
|
|
|
|
|
|
var _formatDate = _interopRequireDefault(require("./utils/formatDate"));
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
|
|
// ==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
|
|
|
|
// @description Extended Tribe Profile
|
|
|
|
// @author Kichiyaki http://dawid-wysokinski.pl/
|
|
|
|
// @match *://*/game.php*&screen=info_ally*
|
|
|
|
// @grant none
|
|
|
|
// @run-at document-end
|
|
|
|
// ==/UserScript==
|
|
|
|
const SERVER = (0, _getCurrentServer.default)();
|
|
|
|
const TRIBE_ID = (0, _getIDFromURL.default)(window.location.search);
|
|
|
|
const LOCAL_STORAGE_KEY = 'kichiyaki_extended_tribe_profile' + TRIBE_ID;
|
2020-07-17 12:16:07 +00:00
|
|
|
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";
|
2020-07-17 11:50:29 +00:00
|
|
|
const profileInfoTBody = document.querySelector('#content_value > table:nth-child(3) > tbody > tr > td:nth-child(1) > table > tbody');
|
2020-07-17 12:16:07 +00:00
|
|
|
const otherElementsContainer = document.querySelector('#content_value > table:nth-child(3) > tbody > tr > td:nth-child(2)');
|
2020-07-17 11:50:29 +00:00
|
|
|
|
|
|
|
const loadDataFromCache = () => {
|
|
|
|
return (0, _localStorage.getItem)(LOCAL_STORAGE_KEY);
|
|
|
|
};
|
|
|
|
|
|
|
|
const cacheTribeData = function cacheTribeData() {
|
|
|
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
|
|
(0, _localStorage.setItem)(LOCAL_STORAGE_KEY, data);
|
|
|
|
};
|
|
|
|
|
|
|
|
const loadData = async () => {
|
|
|
|
const data = await (0, _requestCreator.default)({
|
|
|
|
query: TRIBE_QUERY,
|
|
|
|
variables: {
|
|
|
|
server: SERVER,
|
2020-07-17 12:16:07 +00:00
|
|
|
id: TRIBE_ID,
|
|
|
|
dailyTribeStatsFilter: {
|
|
|
|
sort: 'createDate DESC',
|
|
|
|
limit: 1,
|
|
|
|
tribeID: [TRIBE_ID]
|
|
|
|
}
|
2020-07-17 11:50:29 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
cacheTribeData(data);
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTr = (_ref) => {
|
|
|
|
let {
|
|
|
|
title,
|
|
|
|
data,
|
|
|
|
id
|
|
|
|
} = _ref;
|
|
|
|
let tr = document.querySelector('#' + id);
|
|
|
|
|
|
|
|
if (!tr) {
|
|
|
|
tr = document.createElement('tr');
|
|
|
|
tr.id = id;
|
|
|
|
tr.appendChild(document.createElement('td'));
|
|
|
|
tr.appendChild(document.createElement('td'));
|
|
|
|
profileInfoTBody.append(tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr.children[0].innerHTML = title;
|
|
|
|
tr.children[1].innerHTML = data;
|
|
|
|
};
|
|
|
|
|
|
|
|
const render = (_ref2) => {
|
|
|
|
let {
|
2020-07-17 12:16:07 +00:00
|
|
|
tribe,
|
|
|
|
dailyTribeStats
|
2020-07-17 11:50:29 +00:00
|
|
|
} = _ref2;
|
|
|
|
[{
|
|
|
|
title: 'Created at:',
|
|
|
|
data: (0, _formatDate.default)(tribe.createdAt),
|
|
|
|
id: 'created_at'
|
|
|
|
}, {
|
|
|
|
title: 'Dominance:',
|
|
|
|
data: tribe.dominance.toFixed(2) + '%',
|
|
|
|
id: 'dominance'
|
|
|
|
}, {
|
|
|
|
title: 'Best rank:',
|
|
|
|
data: tribe.bestRank + ' ' + "(".concat((0, _formatDate.default)(tribe.bestRankAt), ")"),
|
|
|
|
id: 'best_rank'
|
|
|
|
}, {
|
|
|
|
title: 'Most points:',
|
|
|
|
data: tribe.mostPoints.toLocaleString() + ' ' + "(".concat((0, _formatDate.default)(tribe.mostPointsAt), ")"),
|
|
|
|
id: 'most_points'
|
|
|
|
}, {
|
|
|
|
title: 'Most villages:',
|
|
|
|
data: tribe.mostVillages + ' ' + "(".concat((0, _formatDate.default)(tribe.mostVillagesAt), ")"),
|
|
|
|
id: 'most_villages'
|
|
|
|
}].forEach(data => {
|
|
|
|
renderTr(data);
|
|
|
|
});
|
2020-07-17 12:16:07 +00:00
|
|
|
|
|
|
|
if (dailyTribeStats && dailyTribeStats.items.length > 0) {
|
|
|
|
(0, _renderTodaysStats.default)(otherElementsContainer, dailyTribeStats.items[0]);
|
|
|
|
}
|
2020-07-17 11:50:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
(async function () {
|
|
|
|
try {
|
|
|
|
const dataFromCache = loadDataFromCache();
|
|
|
|
|
|
|
|
if (dataFromCache && dataFromCache.tribe) {
|
|
|
|
render(dataFromCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
const dataFromAPI = await loadData();
|
|
|
|
|
|
|
|
if (dataFromAPI) {
|
|
|
|
render(dataFromAPI);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log('extended tribe profile', error);
|
|
|
|
}
|
|
|
|
})();
|
2020-07-17 12:16:07 +00:00
|
|
|
},{"./libs/requestCreator":"Ph2E","./utils/renderTodaysStats":"dPMc","./utils/getIDFromURL":"tQUs","./utils/getCurrentServer":"DMkL","./utils/localStorage":"KWxH","./utils/formatDate":"V6Mf"}]},{},["r4nF"], null)
|