// ==UserScript==
// @name SyndPtsAnalyser
// @namespace https://github.com/MyRequiem/comfortablePlayingInGW
// @description Анализ расхода PTS синдиката. Сортировка данных по купленным гранатам, чипам, выданным званиям и знакам, общему количеству PTS. Вывод переводов синдикатного опыта за PTS.
// @id comfortablePlayingInGW@MyRequiem
// @updateURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/SyndPtsAnalyser/syndPtsAnalyser.meta.js
// @downloadURL https://raw.githubusercontent.com/MyRequiem/comfortablePlayingInGW/master/separatedScripts/SyndPtsAnalyser/syndPtsAnalyser.user.js
// @include https://*gwars*/syndicate.php?id=*
// @grant none
// @license MIT
// @version 2.35-140522
// @author MyRequiem [https://www.gwars.io/info.php?id=2095458]
// ==/UserScript==
/*global unsafeWindow */
/*jslint browser: true, maxlen: 80, vars: true, nomen: true, regexp: true,
plusplus: true, continue: true, devel: true
*/
/*eslint-env browser */
/*eslint no-useless-escape: 'warn', linebreak-style: ['error', 'unix'],
quotes: ['error', 'single'], semi: ['error', 'always'],
eqeqeq: 'error', curly: 'error'
*/
/*jscs:disable requireMultipleVarDecl, requireVarDeclFirst */
/*jscs:disable disallowKeywords, disallowDanglingUnderscores */
/*jscs:disable validateIndentation */
(function () {
'use strict';
/**
* @class General
* @constructor
*/
var General = function () {
/**
* @property root
* @type {Object}
*/
this.root = this.getRoot();
/**
* @property doc
* @type {Object}
*/
this.doc = this.root.document;
/**
* @property loc
* @type {String}
*/
this.loc = this.root.location.href;
/**
* @property imgPath
* @type {String}
*/
this.imgPath = 'https://raw.githubusercontent.com/MyRequiem/' +
'comfortablePlayingInGW/master/imgs/';
/**
* @property domain
* @type {String}
*/
this.domain = this.doc.domain;
};
/**
* @lends General.prototype
*/
General.prototype = {
/**
* @method getRoot
* @return {Object}
*/
getRoot: function () {
var rt = typeof unsafeWindow;
return rt !== 'undefined' ? unsafeWindow : window;
},
/**
* @method $
* @param {String} id
* @return {HTMLElement|null}
*/
$: function (id) {
return this.doc.querySelector('#' + id);
}
};
var general = new General();
/**
* @class AjaxQuery
* @constructor
*/
var AjaxQuery = function () {
/**
* @method init
* @param {String} url
* @param {Function} onsuccess
* @param {Function} onfailure
*/
this.init = function (url, onsuccess, onfailure) {
var xmlHttpRequest = new XMLHttpRequest();
if (!xmlHttpRequest) {
general.root.console.log('Error create xmlHttpRequest !!!');
return;
}
xmlHttpRequest.open('GET', url, true);
xmlHttpRequest.send(null);
var timeout = general.root.setTimeout(function () {
xmlHttpRequest.abort();
}, 10000);
xmlHttpRequest.onreadystatechange = function () {
if (xmlHttpRequest.readyState === 4) {
clearTimeout(timeout);
if (xmlHttpRequest.status === 200) {
onsuccess(xmlHttpRequest);
} else {
onfailure();
}
}
};
};
};
/**
* @class SetPoints
* @constructor
*/
var SetPoints = function () {
/**
* @method init
* @param {String|int} num
* @param {String} separator
* @param {Boolean} flagSign
* @return {String}
*/
this.init = function (num, separator, flagSign) {
var x = +num,
sign = x > 0 && flagSign ? '+' : '',
i;
if (isNaN(x)) {
return 'NaN';
}
x = x.toString().split('').reverse();
for (i = 2; i < x.length; i += 3) {
if (x[i] === '-' || !x[i + 1] || x[i + 1] === '-') {
break;
}
x[i] = separator + x[i];
}
return sign + x.reverse().join('');
};
};
/**
* @class GetTimestamp
* @constructor
*/
var GetTimestamp = function () {
/**
* @method init
* @param {String} val
* @return {int}
*/
this.init = function (val) {
var date = /(\d\d)\.(\d\d)\.(\d\d)/.exec(val);
if (!date) {
return 0;
}
var d = +date[1],
m = +date[2],
y = +date[3];
if (!d || d > 31 || !m || m > 12 || !y) {
return 0;
}
return new Date(2000 + y, m - 1, d).getTime();
};
};
/**
* @class GetStrDate
* @constructor
*/
var GetStrDate = function () {
/**
* @method init
* @param {int|String} time
* @return {String}
*/
this.init = function (time) {
var date = time === 'now' ? new Date() : new Date(time),
month = date.getMonth() + 1,
day = date.getDate();
return (day < 10 ? '0' + day : day) + '.' +
(month < 10 ? '0' + month : month) + '.' +
/20(\d+)/.exec(date.getFullYear().toString())[1];
};
};
/**
* @class SyndPtsAnalyser
* @constructor
*/
var SyndPtsAnalyser = function () {
/**
* @property syndId
* @type {String}
*/
this.syndId = /\?id=(\d+)/.exec(general.loc)[1];
/**
* @property tm
* @type {int}
*/
this.tm = 1500;
/**
* @property mainTable
* @type {Element}
*/
this.mainTable = general.doc.querySelector('center+br+table') ||
general.doc.querySelector('center+br+script+table');
/**
* @property lastDate
* @type {String}
*/
this.lastDate = '';
/**
* @property pers
* @type {Array|null}
*/
this.pers = null;
/**
* @property soExpForPTS
* @type {Array|null}
*/
this.soExpForPTS = null;
/**
* @property from
* @type {int}
*/
this.from = 0;
/**
* @property to
* @type {int}
*/
this.to = 0;
/**
* @property summ
* @type {Array|null}
*/
this.summ = null;
/**
* @property all
* @type {int}
*/
this.all = 0;
/**
* @property control
* @type {int}
*/
this.control = 0;
/**
* @property imgPath
* @type {String}
*/
this.imgPath = general.imgPath + 'SyndPtsAnalyser/';
/**
* @method getLastDate
* @param {String} url
*/
this.getLastDate = function (url) {
var _url = url || 'https://' + general.domain +
'/syndicate.log.php?id=' + this.syndId +
'&ptslog=1&page_id=100500',
counter = general.$('analizePTSCounter'),
_this = this;
if (!url) {
counter.innerHTML = '2/1';
}
new AjaxQuery().init(_url, function (xml) {
var spanContent = general.doc.createElement('span');
spanContent.innerHTML = xml.responseText;
if (!url) {
counter.innerHTML = '2/2';
general.root.setTimeout(function () {
_this.getLastDate(spanContent.
querySelector('tr>td[class="greenbg"]' +
'[onclick*="window.location=\'' +
'/syndicate.log.php?"]:last-child>' +
'a[href*="/syndicate.log.php?id="]').href);
}, _this.tm);
} else {
var fonts = spanContent.
querySelectorAll('nobr>font[color="green"]');
_this.lastDate = /\d+.\d+.\d+/.
exec(fonts[fonts.length - 1].innerHTML)[0];
var inpFrom = general.$('inpDateFrom');
inpFrom.value = _this.lastDate;
inpFrom.disabled = false;
general.$('inpDateTo').disabled = false;
general.$('goPTS').disabled = false;
general.$('ptsPreloader').style.display = 'none';
}
}, function () {
var preloader = general.$('ptsPreloader');
preloader.style.display = 'none';
preloader.parentNode.innerHTML += '
Ошибка ответа сервера...';
});
};
/**
* @method enterPress
* @param {Object} e
*/
this.enterPress = function (e) {
var ev = e || general.root.event;
if (ev.keyCode === 13) {
general.$('goPTS').click();
}
};
/**
* @method showRezult
* @param {String} id
*/
this.showRezult = function (id) {
this.mainTable.removeAttribute('class');
this.mainTable.setAttribute('style', 'border-collapse: ' +
'collapse; background: #D0EED0;');
var str = '