add warStatsGenerator.js

This commit is contained in:
Dawid Wysokiński 2020-08-14 13:34:14 +02:00
parent a4cd38466b
commit 1088e237f4
12 changed files with 668 additions and 9 deletions

View File

@ -414,9 +414,10 @@ exports.default = _default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.default = exports.POPUP_SELECTOR = void 0;
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
const POPUP_SELECTOR = '#inline_popup';
exports.POPUP_SELECTOR = POPUP_SELECTOR;
var _default = function _default() {
let {

View File

@ -1222,9 +1222,10 @@ exports.default = _default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.default = exports.POPUP_SELECTOR = void 0;
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
const POPUP_SELECTOR = '#inline_popup';
exports.POPUP_SELECTOR = POPUP_SELECTOR;
var _default = function _default() {
let {

View File

@ -660,9 +660,10 @@ exports.default = _default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.default = exports.POPUP_SELECTOR = void 0;
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
const POPUP_SELECTOR = '#inline_popup';
exports.POPUP_SELECTOR = POPUP_SELECTOR;
var _default = function _default() {
let {

View File

@ -164,9 +164,10 @@ exports.default = _default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.default = exports.POPUP_SELECTOR = void 0;
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
const POPUP_SELECTOR = '#inline_popup';
exports.POPUP_SELECTOR = POPUP_SELECTOR;
var _default = function _default() {
let {

View File

@ -13,7 +13,7 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcel
},{}],"yrCm":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=a(require("../i18n/renderTodaysStats")),n=a(require("../utils/isNil"));function a(t){return t&&t.__esModule?t:{default:t}}const c=(0,t.default)(),o=t=>{return t>0?"color: #000; background-color: #0f0":t<0?"color: #000; background-color: #f00":"color: #000; background-color: #808080"};var r=(t,a)=>{let r=t.querySelector("#todaysStats");r||((r=document.createElement("div")).id="todaysStats",r.width="100%",t.prepend(r));const d=!(0,n.default)(a.rankSup);r.innerHTML='\n <table width="100%" class="vis">\n <tbody>\n <tr>\n <th colspan="2">\n '.concat(c.title,"\n </th>\n </tr>\n <tr>\n <td>\n ").concat(c.points,':\n </td>\n <td style="').concat(o(a.points),'">\n ').concat(Math.abs(a.points).toLocaleString(),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.rank,':\n </td>\n <td style="').concat(o(a.rank),'">\n ').concat(Math.abs(a.rank),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.villages,':\n </td>\n <td style="').concat(o(a.villages),'">\n ').concat(Math.abs(a.villages).toLocaleString(),"\n </td>\n </tr>\n ").concat(d?"":"<tr>\n <td>\n ".concat(c.members,':\n </td>\n <td style="').concat(o(a.members),'">\n ').concat(Math.abs(a.members),"\n </td>\n </tr>"),"\n <tr>\n <td>\n ").concat(c.oda,':\n </td>\n <td style="').concat(o(a.scoreAtt),'">\n ').concat(Math.abs(a.scoreAtt).toLocaleString(),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.odaRank,':\n </td>\n <td style="').concat(o(a.rankAtt),'">\n ').concat(Math.abs(a.rankAtt),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.odd,':\n </td>\n <td style="').concat(o(a.scoreDef),'">\n ').concat(Math.abs(a.scoreDef).toLocaleString(),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.oddRank,':\n </td>\n <td style="').concat(o(a.rankDef),'">\n ').concat(Math.abs(a.rankDef),"\n </td>\n </tr>\n ").concat(d?"<tr>\n <td>\n ".concat(c.ods,':\n </td>\n <td style="').concat(o(a.scoreSup),'">\n ').concat(Math.abs(a.scoreSup).toLocaleString(),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.odsRank,':\n </td>\n <td style="').concat(o(a.rankSup),'">\n ').concat(Math.abs(a.rankSup),"\n </td>\n </tr>"):"","\n <tr>\n <td>\n ").concat(c.od,':\n </td>\n <td style="').concat(o(a.scoreTotal),'">\n ').concat(Math.abs(a.scoreTotal).toLocaleString(),"\n </td>\n </tr>\n <tr>\n <td>\n ").concat(c.odRank,':\n </td>\n <td style="').concat(o(a.rankTotal),'">\n ').concat(Math.abs(a.rankTotal),"\n </td>\n </tr>\n </tbody>\n </table>\n ")};exports.default=r;
},{"../i18n/renderTodaysStats":"l9PO","../utils/isNil":"yQib"}],"chDM":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e=".popup_helper",t="#inline_popup";var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=document.querySelector(t);i&&(i.style.width="auto",i.style.maxWidth="1000px"),i.classList.contains("show")?(i.querySelector("#inline_popup_title").innerHTML=o,i.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const p=document.querySelector(".popup_helper");p&&(p.style.width="auto",p.style.position="fixed",p.style.zIndex="50001")};exports.default=o;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.POPUP_SELECTOR=void 0;const e=".popup_helper",t="#inline_popup";exports.POPUP_SELECTOR=t;var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const p=document.querySelector(t);p&&(p.style.width="auto",p.style.maxWidth="1000px"),p.classList.contains("show")?(p.querySelector("#inline_popup_title").innerHTML=o,p.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const i=document.querySelector(".popup_helper");i&&(i.style.width="auto",i.style.position="fixed",i.style.zIndex="50001")};exports.default=o;
},{}],"tKRp":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e={pl_PL:{date:"Data",newOwner:"Nowy właściciel",oldOwner:"Stary właściciel",village:"Wioska",title:"Przejęcia"},en_DK:{date:"Date",newOwner:"New owner",oldOwner:"Old owner",village:"Village",title:"Ennoblements"}};var a=()=>e[window.game_data.locale]||e.en_DK;exports.default=a;
},{}],"fCHX":[function(require,module,exports) {

View File

@ -35,7 +35,7 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcel
},{"../i18n/renderTodaysStats":"l9PO","../utils/isNil":"yQib"}],"tKRp":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e={pl_PL:{date:"Data",newOwner:"Nowy właściciel",oldOwner:"Stary właściciel",village:"Wioska",title:"Przejęcia"},en_DK:{date:"Date",newOwner:"New owner",oldOwner:"Old owner",village:"Village",title:"Ennoblements"}};var a=()=>e[window.game_data.locale]||e.en_DK;exports.default=a;
},{}],"chDM":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e=".popup_helper",t="#inline_popup";var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=document.querySelector(t);i&&(i.style.width="auto",i.style.maxWidth="1000px"),i.classList.contains("show")?(i.querySelector("#inline_popup_title").innerHTML=o,i.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const p=document.querySelector(".popup_helper");p&&(p.style.width="auto",p.style.position="fixed",p.style.zIndex="50001")};exports.default=o;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.POPUP_SELECTOR=void 0;const e=".popup_helper",t="#inline_popup";exports.POPUP_SELECTOR=t;var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const p=document.querySelector(t);p&&(p.style.width="auto",p.style.maxWidth="1000px"),p.classList.contains("show")?(p.querySelector("#inline_popup_title").innerHTML=o,p.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const i=document.querySelector(".popup_helper");i&&(i.style.width="auto",i.style.position="fixed",i.style.zIndex="50001")};exports.default=o;
},{}],"V6Mf":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=(e,t)=>new Date(e).toLocaleDateString(window.game_data.locale.replace("_","-"),t||{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});exports.default=e;
},{}],"fHHP":[function(require,module,exports) {

View File

@ -31,7 +31,7 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcel
},{"date-fns/differenceInMinutes":"oGJj"}],"tKRp":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e={pl_PL:{date:"Data",newOwner:"Nowy właściciel",oldOwner:"Stary właściciel",village:"Wioska",title:"Przejęcia"},en_DK:{date:"Date",newOwner:"New owner",oldOwner:"Old owner",village:"Village",title:"Ennoblements"}};var a=()=>e[window.game_data.locale]||e.en_DK;exports.default=a;
},{}],"chDM":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e=".popup_helper",t="#inline_popup";var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=document.querySelector(t);i&&(i.style.width="auto",i.style.maxWidth="1000px"),i.classList.contains("show")?(i.querySelector("#inline_popup_title").innerHTML=o,i.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const p=document.querySelector(".popup_helper");p&&(p.style.width="auto",p.style.position="fixed",p.style.zIndex="50001")};exports.default=o;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.POPUP_SELECTOR=void 0;const e=".popup_helper",t="#inline_popup";exports.POPUP_SELECTOR=t;var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const p=document.querySelector(t);p&&(p.style.width="auto",p.style.maxWidth="1000px"),p.classList.contains("show")?(p.querySelector("#inline_popup_title").innerHTML=o,p.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const i=document.querySelector(".popup_helper");i&&(i.style.width="auto",i.style.position="fixed",i.style.zIndex="50001")};exports.default=o;
},{}],"vNT1":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=l(require("../i18n/showEnnoblementsPopup")),e=require("../utils/pagination"),n=l(require("../utils/showPopup")),a=l(require("../utils/formatDate")),o=require("../utils/tribalwars");function l(t){return t&&t.__esModule?t:{default:t}}const r="ennoblementsPagination",i=(0,t.default)(),c=(t,e)=>t?'<td><a href="'.concat((0,o.formatPlayerURL)(t.id),'">').concat(t.name," (").concat(e?'<a href="'.concat((0,o.formatTribeURL)(e.id),'">').concat(e.tag,"</a>"):"-",")</a></td>"):"<td>-</td>";var d=function(t,l){let{limit:d=0,currentPage:s=1,onPageChange:u=(()=>{})}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const g=(0,e.generatePaginationItems)({total:l.total,limit:d,currentPage:s}),m='\n <div style="'.concat((0,e.getContainerStyles)(),'" id="').concat(r,'">\n ').concat(g.join(""),'\n </div>\n <table class="vis" style="border-collapse: separate; border-spacing: 2px; width: 100%;">\n <tbody>\n <tr>\n <th>\n ').concat(i.date,"\n </th>\n <th>\n ").concat(i.village,"\n </th>\n <th>\n ").concat(i.newOwner,"\n </th>\n <th>\n ").concat(i.oldOwner,"\n </th>\n </tr>\n ").concat(l.items.map(t=>{let e="<tr>"+"<td>".concat((0,a.default)(t.ennobledAt),"</td>");return t.village?e+='<td><a href="'.concat((0,o.formatVillageURL)(t.village.id),'">').concat((0,o.formatVillageName)(t.village.name,t.village.x,t.village.y),"</a></td>"):e+="<td>-</td>",e+=c(t.newOwner,t.newOwnerTribe),(e+=c(t.oldOwner,t.oldOwnerTribe))+"</tr>"}).join(""),"\n </tbody>\n </table>\n ");(0,n.default)({e:t,title:i.title,id:"ennoblements",html:m}),document.querySelectorAll("#ennoblementsPagination a").forEach(t=>{t.addEventListener("click",u)})};exports.default=d;
},{"../i18n/showEnnoblementsPopup":"tKRp","../utils/pagination":"fCHX","../utils/showPopup":"chDM","../utils/formatDate":"V6Mf","../utils/tribalwars":"fHHP"}],"UdfQ":[function(require,module,exports) {

View File

@ -1,7 +1,7 @@
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"Ph2E":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.API_URI=void 0;const e="https://api.tribalwarshelp.com/graphql";exports.API_URI=e;var r=function(){let{query:r,variables:t={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return fetch(e,{method:"POST",body:JSON.stringify({query:r,variables:t}),headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{let{data:r,errors:t}=e;if(t&&Array.isArray(t)&&t.length>0)throw new Error(t[0].message);return new Promise(e=>e(r))})};exports.default=r;
},{}],"chDM":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const e=".popup_helper",t="#inline_popup";var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=document.querySelector(t);i&&(i.style.width="auto",i.style.maxWidth="1000px"),i.classList.contains("show")?(i.querySelector("#inline_popup_title").innerHTML=o,i.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const p=document.querySelector(".popup_helper");p&&(p.style.width="auto",p.style.position="fixed",p.style.zIndex="50001")};exports.default=o;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.POPUP_SELECTOR=void 0;const e=".popup_helper",t="#inline_popup";exports.POPUP_SELECTOR=t;var o=function(){let{e:e,title:o,html:n,id:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const p=document.querySelector(t);p&&(p.style.width="auto",p.style.maxWidth="1000px"),p.classList.contains("show")?(p.querySelector("#inline_popup_title").innerHTML=o,p.querySelector("#inline_popup_content").innerHTML=n):inlinePopup(e,l,null,{offset_x:0,offset_y:0},n,o);const i=document.querySelector(".popup_helper");i&&(i.style.width="auto",i.style.position="fixed",i.style.zIndex="50001")};exports.default=o;
},{}],"DMkL":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=()=>window.location.host.split(".")[0];exports.default=e;
},{}],"V6Mf":[function(require,module,exports) {

9
dist/quickbar/warStatsGenerator.js vendored Normal file

File diff suppressed because one or more lines are too long

391
dist/warStatsGenerator.js vendored Normal file
View File

@ -0,0 +1,391 @@
// 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(API_URI, {
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;
},{}],"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;
},{}],"chDM":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.POPUP_SELECTOR = void 0;
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
const POPUP_SELECTOR = '#inline_popup';
exports.POPUP_SELECTOR = POPUP_SELECTOR;
var _default = function _default() {
let {
e,
title,
html,
id
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const popup = document.querySelector(POPUP_SELECTOR);
if (popup) {
popup.style.width = 'auto';
popup.style.maxWidth = '1000px';
}
if (popup.classList.contains('show')) {
popup.querySelector('#inline_popup_title').innerHTML = title;
popup.querySelector('#inline_popup_content').innerHTML = html;
} else {
inlinePopup(e, id, null, {
offset_x: 0,
offset_y: 0
}, html, title);
}
const popupWrapper = document.querySelector(POPUP_WRAPPER_SELECTOR);
if (popupWrapper) {
popupWrapper.style.width = 'auto';
popupWrapper.style.position = 'fixed';
popupWrapper.style.zIndex = '50001';
}
};
exports.default = _default;
},{}],"H9GS":[function(require,module,exports) {
"use strict";
var _requestCreator = _interopRequireDefault(require("./libs/requestCreator"));
var _getCurrentServer = _interopRequireDefault(require("./utils/getCurrentServer"));
var _showPopup = _interopRequireWildcard(require("./utils/showPopup"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// ==UserScript==
// @name War Stats Generator
// @namespace https://github.com/tribalwarshelp/scripts
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/warStatsGenerator.js
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/warStatsGenerator.js
// @version 0.2.0
// @description War Stats Generator
// @author Kichiyaki http://dawid-wysokinski.pl/
// @match *://*/game.php*screen=ranking*mode=wars*
// @grant none
// @run-at document-end
// ==/UserScript==
const SERVER = (0, _getCurrentServer.default)();
const SIDE_ONE_BUTTON_ID = 'sideOneAdd';
const SIDE_ONE_INPUT_CONTAINER_ID = 'sideOneInputs';
const SIDE_TWO_BUTTON_ID = 'sideTwoAdd';
const SIDE_TWO_INPUT_CONTAINER_ID = 'sideTwoInputs';
const TO_INPUT_ID = 'to';
const FROM_INPUT_ID = 'from';
const RESULT_CONTAINER_ID = 'warStatsResult';
const TRIBES_QUERY = "\n query tribes($server: String!, $filter: TribeFilter) {\n tribes(server: $server, filter: $filter) {\n items {\n id\n tag\n }\n }\n }\n";
const ENNOBLEMENTS_QUERY = "\n query ennoblements($server: String!, $filter: EnnoblementFilter) {\n ennoblements(server: $server, filter: $filter) {\n total\n }\n }\n";
const showResult = function showResult() {
let sideOne = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let sideTwo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
const html = "\n <div>\n <h3>Conquers:</h3>\n <p style=\"margin: 0;\"><strong>Side one: ".concat(sideOne, "</strong></p>\n <p style=\"margin: 0;\"><strong>Side two: ").concat(sideTwo, "</strong></p>\n <p style=\"margin: 0;\"><strong>Difference: ").concat(Math.abs(sideOne - sideTwo), "</strong></p>\n <hr style=\"margin: 10px 0;\" />\n </div>\n ");
document.querySelector('#' + RESULT_CONTAINER_ID).innerHTML = html;
};
const createAddTribeHandler = container => {
return () => {
const div = document.createElement('div');
div.innerHTML = "\n <label>Tribe tag: </label>\n <input type=\"text\" required />\n <button type=\"button\" class=\"btn\">Delete</button>\n ";
div.querySelector('button').addEventListener('click', () => {
div.remove();
});
container.appendChild(div);
};
};
const handleFormSubmit = async e => {
e.preventDefault();
const sideOneTags = [];
const sideTwoTags = [];
e.target.querySelectorAll("#".concat(SIDE_ONE_INPUT_CONTAINER_ID, " input")).forEach(el => {
if (el.value.trim()) {
sideOneTags.push(el.value.trim());
}
});
e.target.querySelectorAll("#".concat(SIDE_TWO_INPUT_CONTAINER_ID, " input")).forEach(el => {
if (el.value.trim()) {
sideTwoTags.push(el.value.trim());
}
});
console.log('sideOneTags', sideOneTags, 'sideTwoTags', sideTwoTags);
if (sideOneTags.length === 0) return UI.ErrorMessage('Not enough tribes added to the side one.');
if (sideTwoTags.length === 0) return UI.ErrorMessage('Not enough tribes added to the side two.');
const fromInputs = document.querySelectorAll("".concat(_showPopup.POPUP_SELECTOR, " form #").concat(FROM_INPUT_ID, " input"));
let ennobledAtGTE;
if (fromInputs.length === 2 && fromInputs[0].value && fromInputs[1].value) {
ennobledAtGTE = new Date("".concat(fromInputs[0].value, "T").concat(fromInputs[1].value, ":00"));
}
const toInputs = document.querySelectorAll("".concat(_showPopup.POPUP_SELECTOR, " form #").concat(TO_INPUT_ID, " input"));
let ennobledAtLTE;
if (toInputs.length === 2 && toInputs[0].value && toInputs[1].value) {
ennobledAtLTE = new Date("".concat(toInputs[0].value, "T").concat(toInputs[1].value, ":00"));
}
e.target.querySelectorAll('button').forEach(button => {
button.disabled = true;
});
try {
const {
tribes
} = await (0, _requestCreator.default)({
query: TRIBES_QUERY,
variables: {
server: SERVER,
filter: {
tag: [...sideOneTags, ...sideTwoTags]
}
}
});
const sideOneTribes = tribes.items.filter(item => sideOneTags.some(tag => item.tag === tag)).map(tribe => tribe.id);
const sideTwoTribes = tribes.items.filter(item => sideTwoTags.some(tag => item.tag === tag)).map(tribe => tribe.id);
console.log(sideOneTribes, sideTwoTribes);
const {
ennoblements: sideOneEnnoblements
} = await (0, _requestCreator.default)({
query: ENNOBLEMENTS_QUERY,
variables: {
server: SERVER,
filter: {
newOwnerTribeID: sideOneTribes,
oldOwnerTribeID: sideTwoTribes,
ennobledAtGTE,
ennobledAtLTE
}
}
});
const {
ennoblements: sideTwoEnnoblements
} = await (0, _requestCreator.default)({
query: ENNOBLEMENTS_QUERY,
variables: {
server: SERVER,
filter: {
newOwnerTribeID: sideTwoTribes,
oldOwnerTribeID: sideOneTribes,
ennobledAtGTE,
ennobledAtLTE
}
}
});
console.log('sideOneEnnoblements', sideOneEnnoblements, 'sideTwoEnnoblements', sideTwoEnnoblements);
showResult(sideOneEnnoblements.total, sideTwoEnnoblements.total);
} catch (error) {
console.log('handleFormSubmit', error);
}
e.target.querySelectorAll('button').forEach(button => {
button.disabled = false;
});
};
const showWarStatsForm = e => {
const html = "\n <form>\n <div id=\"".concat(RESULT_CONTAINER_ID, "\">\n </div>\n <div style=\"margin-bottom: 10px;\">\n <div id=\"").concat(FROM_INPUT_ID, "\">\n <label>From: </label>\n <input type=\"date\" required />\n <input type=\"time\" required />\n </div>\n <div id=\"").concat(TO_INPUT_ID, "\">\n <label>To: </label>\n <input type=\"date\" required />\n <input type=\"time\" required />\n </div>\n </div>\n <div style=\"display: flex; justify-content: space-between; margin-bottom: 10px;\">\n <div>\n <h3>Side one</h3>\n <div id=\"").concat(SIDE_ONE_INPUT_CONTAINER_ID, "\">\n </div>\n <button id=\"").concat(SIDE_ONE_BUTTON_ID, "\" class=\"btn\" type=\"button\">Add Tribe</button>\n </div>\n <div style=\"margin: 0 5px;\"></div>\n <div>\n <h3>Side two</h3>\n <div id=\"").concat(SIDE_TWO_INPUT_CONTAINER_ID, "\">\n </div>\n <button id=\"").concat(SIDE_TWO_BUTTON_ID, "\" class=\"btn\" type=\"button\">Add tribe</button>\n </div>\n </div>\n <div style=\"text-align: center;\">\n <button class=\"btn\" type=\"submit\">Generate war stats</button>\n </div>\n </form>\n ");
(0, _showPopup.default)({
title: 'War Stats Generator',
id: 'warStats',
html,
e
});
document.querySelector("".concat(_showPopup.POPUP_SELECTOR, " form #").concat(SIDE_ONE_BUTTON_ID)).addEventListener('click', createAddTribeHandler(document.querySelector('#' + SIDE_ONE_INPUT_CONTAINER_ID)));
document.querySelector("".concat(_showPopup.POPUP_SELECTOR, " form #").concat(SIDE_TWO_BUTTON_ID)).addEventListener('click', createAddTribeHandler(document.querySelector('#' + SIDE_TWO_INPUT_CONTAINER_ID)));
document.querySelector("".concat(_showPopup.POPUP_SELECTOR, " form")).addEventListener('submit', handleFormSubmit);
};
const renderUI = () => {
const div = document.createElement('div');
const button = document.createElement('button');
button.innerHTML = 'Generate war stats';
button.addEventListener('click', showWarStatsForm);
div.appendChild(button);
document.querySelector('#wars_ranking_table').parentElement.prepend(div);
};
(function () {
try {
renderUI();
} catch (error) {
console.log('war stats', error);
}
})();
},{"./libs/requestCreator":"Ph2E","./utils/getCurrentServer":"DMkL","./utils/showPopup":"chDM"}]},{},["H9GS"], null)

View File

@ -1,5 +1,5 @@
const POPUP_WRAPPER_SELECTOR = '.popup_helper';
const POPUP_SELECTOR = '#inline_popup';
export const POPUP_SELECTOR = '#inline_popup';
export default ({ e, title, html, id } = {}) => {
const popup = document.querySelector(POPUP_SELECTOR);

255
src/warStatsGenerator.js Normal file
View File

@ -0,0 +1,255 @@
import requestCreator from './libs/requestCreator';
import getServer from './utils/getCurrentServer';
import showPopup, { POPUP_SELECTOR } from './utils/showPopup';
// ==UserScript==
// @name War Stats Generator
// @namespace https://github.com/tribalwarshelp/scripts
// @updateURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/warStatsGenerator.js
// @downloadURL https://raw.githubusercontent.com/tribalwarshelp/scripts/master/dist/warStatsGenerator.js
// @version 0.2.0
// @description War Stats Generator
// @author Kichiyaki http://dawid-wysokinski.pl/
// @match *://*/game.php*screen=ranking*mode=wars*
// @grant none
// @run-at document-end
// ==/UserScript==
const SERVER = getServer();
const SIDE_ONE_BUTTON_ID = 'sideOneAdd';
const SIDE_ONE_INPUT_CONTAINER_ID = 'sideOneInputs';
const SIDE_TWO_BUTTON_ID = 'sideTwoAdd';
const SIDE_TWO_INPUT_CONTAINER_ID = 'sideTwoInputs';
const TO_INPUT_ID = 'to';
const FROM_INPUT_ID = 'from';
const RESULT_CONTAINER_ID = 'warStatsResult';
const TRIBES_QUERY = `
query tribes($server: String!, $filter: TribeFilter) {
tribes(server: $server, filter: $filter) {
items {
id
tag
}
}
}
`;
const ENNOBLEMENTS_QUERY = `
query ennoblements($server: String!, $filter: EnnoblementFilter) {
ennoblements(server: $server, filter: $filter) {
total
}
}
`;
const showResult = (sideOne = 0, sideTwo = 0) => {
const html = `
<div>
<h3>Conquers:</h3>
<p style="margin: 0;"><strong>Side one: ${sideOne}</strong></p>
<p style="margin: 0;"><strong>Side two: ${sideTwo}</strong></p>
<p style="margin: 0;"><strong>Difference: ${Math.abs(
sideOne - sideTwo
)}</strong></p>
<hr style="margin: 10px 0;" />
</div>
`;
document.querySelector('#' + RESULT_CONTAINER_ID).innerHTML = html;
};
const createAddTribeHandler = (container) => {
return () => {
const div = document.createElement('div');
div.innerHTML = `
<label>Tribe tag: </label>
<input type="text" required />
<button type="button" class="btn">Delete</button>
`;
div.querySelector('button').addEventListener('click', () => {
div.remove();
});
container.appendChild(div);
};
};
const handleFormSubmit = async (e) => {
e.preventDefault();
const sideOneTags = [];
const sideTwoTags = [];
e.target
.querySelectorAll(`#${SIDE_ONE_INPUT_CONTAINER_ID} input`)
.forEach((el) => {
if (el.value.trim()) {
sideOneTags.push(el.value.trim());
}
});
e.target
.querySelectorAll(`#${SIDE_TWO_INPUT_CONTAINER_ID} input`)
.forEach((el) => {
if (el.value.trim()) {
sideTwoTags.push(el.value.trim());
}
});
console.log('sideOneTags', sideOneTags, 'sideTwoTags', sideTwoTags);
if (sideOneTags.length === 0)
return UI.ErrorMessage('Not enough tribes added to the side one.');
if (sideTwoTags.length === 0)
return UI.ErrorMessage('Not enough tribes added to the side two.');
const fromInputs = document.querySelectorAll(
`${POPUP_SELECTOR} form #${FROM_INPUT_ID} input`
);
let ennobledAtGTE;
if (fromInputs.length === 2 && fromInputs[0].value && fromInputs[1].value) {
ennobledAtGTE = new Date(
`${fromInputs[0].value}T${fromInputs[1].value}:00`
);
}
const toInputs = document.querySelectorAll(
`${POPUP_SELECTOR} form #${TO_INPUT_ID} input`
);
let ennobledAtLTE;
if (toInputs.length === 2 && toInputs[0].value && toInputs[1].value) {
ennobledAtLTE = new Date(`${toInputs[0].value}T${toInputs[1].value}:00`);
}
e.target.querySelectorAll('button').forEach((button) => {
button.disabled = true;
});
try {
const { tribes } = await requestCreator({
query: TRIBES_QUERY,
variables: {
server: SERVER,
filter: {
tag: [...sideOneTags, ...sideTwoTags],
},
},
});
const sideOneTribes = tribes.items
.filter((item) => sideOneTags.some((tag) => item.tag === tag))
.map((tribe) => tribe.id);
const sideTwoTribes = tribes.items
.filter((item) => sideTwoTags.some((tag) => item.tag === tag))
.map((tribe) => tribe.id);
console.log(sideOneTribes, sideTwoTribes);
const { ennoblements: sideOneEnnoblements } = await requestCreator({
query: ENNOBLEMENTS_QUERY,
variables: {
server: SERVER,
filter: {
newOwnerTribeID: sideOneTribes,
oldOwnerTribeID: sideTwoTribes,
ennobledAtGTE,
ennobledAtLTE,
},
},
});
const { ennoblements: sideTwoEnnoblements } = await requestCreator({
query: ENNOBLEMENTS_QUERY,
variables: {
server: SERVER,
filter: {
newOwnerTribeID: sideTwoTribes,
oldOwnerTribeID: sideOneTribes,
ennobledAtGTE,
ennobledAtLTE,
},
},
});
console.log(
'sideOneEnnoblements',
sideOneEnnoblements,
'sideTwoEnnoblements',
sideTwoEnnoblements
);
showResult(sideOneEnnoblements.total, sideTwoEnnoblements.total);
} catch (error) {
console.log('handleFormSubmit', error);
}
e.target.querySelectorAll('button').forEach((button) => {
button.disabled = false;
});
};
const showWarStatsForm = (e) => {
const html = `
<form>
<div id="${RESULT_CONTAINER_ID}">
</div>
<div style="margin-bottom: 10px;">
<div id="${FROM_INPUT_ID}">
<label>From: </label>
<input type="date" required />
<input type="time" required />
</div>
<div id="${TO_INPUT_ID}">
<label>To: </label>
<input type="date" required />
<input type="time" required />
</div>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 10px;">
<div>
<h3>Side one</h3>
<div id="${SIDE_ONE_INPUT_CONTAINER_ID}">
</div>
<button id="${SIDE_ONE_BUTTON_ID}" class="btn" type="button">Add Tribe</button>
</div>
<div style="margin: 0 5px;"></div>
<div>
<h3>Side two</h3>
<div id="${SIDE_TWO_INPUT_CONTAINER_ID}">
</div>
<button id="${SIDE_TWO_BUTTON_ID}" class="btn" type="button">Add tribe</button>
</div>
</div>
<div style="text-align: center;">
<button class="btn" type="submit">Generate war stats</button>
</div>
</form>
`;
showPopup({ title: 'War Stats Generator', id: 'warStats', html, e });
document
.querySelector(`${POPUP_SELECTOR} form #${SIDE_ONE_BUTTON_ID}`)
.addEventListener(
'click',
createAddTribeHandler(
document.querySelector('#' + SIDE_ONE_INPUT_CONTAINER_ID)
)
);
document
.querySelector(`${POPUP_SELECTOR} form #${SIDE_TWO_BUTTON_ID}`)
.addEventListener(
'click',
createAddTribeHandler(
document.querySelector('#' + SIDE_TWO_INPUT_CONTAINER_ID)
)
);
document
.querySelector(`${POPUP_SELECTOR} form`)
.addEventListener('submit', handleFormSubmit);
};
const renderUI = () => {
const div = document.createElement('div');
const button = document.createElement('button');
button.innerHTML = 'Generate war stats';
button.addEventListener('click', showWarStatsForm);
div.appendChild(button);
document.querySelector('#wars_ranking_table').parentElement.prepend(div);
};
(function () {
try {
renderUI();
} catch (error) {
console.log('war stats', error);
}
})();