//
// ==UserScript==
// @name hwm_exp_ability
// @author Pahan https://gf.qytechs.cn/uk/users/18377-pahan
// @namespace hwm_pahan
// @description Высчитывание экспоумки для взятия ап умки на своем уровне
// @homepage https://gf.qytechs.cn/uk/scripts/13724-hwm-exp-ability
// @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
// @version 1.12
// @encoding utf-8
// @include http://*.heroeswm.ru/home.php*
// @include http://*lordswm.com/home.php*
// @include http://178.248.235.15/home.php*
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_setValue
// @grant GM_addStyle
// @grant GM_log
// @grant GM_openInTab
// @grant GM_xmlhttpRequest
// ==/UserScript==
var version = '1.12';
var str_url = 'https://gf.qytechs.cn/uk/scripts/13724-hwm-exp-ability';
var str_script_name = 'Експоумка';
var str_url_aut = '/sms-create.php?mailto=Pahan&subject=Скрипт: '+str_script_name+' v'+version+'. Найдена ошибка:';
if (typeof GM_deleteValue != 'function') {
this.GM_getValue=function (key,def) {return localStorage[key] || def;};
this.GM_setValue=function (key,value) {return localStorage[key]=value;};
this.GM_deleteValue=function (key) {return delete localStorage[key];};
this.GM_addStyle=function (key) {
var style = document.createElement('style');
style.textContent = key;
document.querySelector("head").appendChild(style);
}
}
if (typeof GM_listValues != 'function') {
this.GM_listValues=function () {
var values = [];
for (var i=0; i<localStorage.length; i++) {
values.push(localStorage.key(i));
}
return values;
}
}
function addEvent(elem, evType, fn) {
if (elem.addEventListener) {
elem.addEventListener(evType, fn, false);
}
else if (elem.attachEvent) {
elem.attachEvent("on" + evType, fn);
}
else {
elem["on" + evType] = fn;
}
}
function $(id) { return document.querySelector(id); }
function URLAttrValueGet(attr_name, aurl)
{
attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( aurl );
if( results == null )
return "";
else
return results[1];
}
function Assert(ACondition, AMessage)
{
if (ACondition)
return;
localStorage['trade.status'] = 'Stoped';
alert('ERROR: ' + AMessage);
throw new Error(AMessage);
}
function Trim(AText)
{
return AText.replace(/^\s+|\s+$|^( )+|( )+$/g, '');
}
function FloatFormat(AFloat)
{
return Math.round(AFloat).toString();
}
var expelem;
function GetExp()
{
res = -1;
var list = document.getElementsByTagName("b");
for(var i = 0; i < list.length; i++)
{
var elem = list[i];
if (elem.innerHTML.indexOf('\u0411\u043E\u0435\u0432\u043E\u0439\u0020\u0443\u0440\u043E\u0432\u0435\u043D\u044C') === 0)
{
var subindex = Array.prototype.indexOf.call(elem.parentNode.childNodes, elem);
expelem = elem.parentNode.childNodes[subindex + 2];
res = parseInt(expelem.innerHTML.replace(/,/g, ''));
break;
}
}
return res;
}
function GetCurrentFractAbility(AElem)
{
var sublist = AElem.getElementsByTagName("b");
if (sublist.length > 0)
{
var subitem = sublist[0];
var subindex = Array.prototype.indexOf.call(subitem.parentNode.childNodes, subitem);
var regex = /\((\d+.\d+)\)/;
var regex_res = regex.exec(subitem.parentNode.childNodes[subindex + 1].textContent);
if (regex_res)
{
var LAbility = parseFloat(regex_res[1]);
var LAbilityToUp = parseFloat(subitem.parentNode.childNodes[subindex + 2].innerHTML);
var LArray = subitem.parentNode.childNodes[subindex].innerHTML.split(': ');
var LFration = LArray[0];
var LAbilityLevel = parseInt(LArray[1]);
return {Ability: LAbility, AbilityToUp: LAbilityToUp, Fraction: LFration,
AbilityLevel: LAbilityLevel, IsCurrent: true, IsMain: false};
}
}
}
function GetAllFractions()
{
var LTD = GetTD();
var LResult = new Array(GetCurrentFractAbility(LTD));
var LMaxAbl = LResult[0];
for(i = 0; i < LTD.childNodes.length; i++)
{
var cur_el = LTD.childNodes[i];
var html = Trim(cur_el.textContent);
var regex = /\: \d+ \((\d+.\d+)\)/;
var regex_res = regex.exec(html);
if(regex_res)
{
cur_abil = parseFloat(regex_res[1]);
if (html.indexOf('\u0413\u0438\u043B\u044C\u0434\u0438\u044F') === -1)
{
var next_el = cur_el.parentNode.childNodes[i + 1];
if (next_el.tagName == 'FONT')
{
var LAbility = cur_abil;
var LAbilityToUp = parseFloat(next_el.innerHTML);
var LArray = Trim(next_el.previousSibling.textContent).split(': ');
var LFration = LArray[0];
var LAbilityLevel = parseInt(LArray[1].split(' (')[0]);
var LNew = {Ability: LAbility, AbilityToUp: LAbilityToUp, Fraction: LFration,
AbilityLevel: LAbilityLevel, IsCurrent: false, IsMain: false};
LResult.push(LNew);
if (LMaxAbl.Ability < LNew.Ability)
LMaxAbl = LNew;
}
}
}
}
LMaxAbl.IsMain = true;
return LResult;
}
function GetTD()
{
var list = document.getElementsByTagName("td");
for(var i = 0; i < list.length; i++)
{
var elem = list[i];
// alert(elem.innerHTML);
if( (Trim(elem.innerHTML).indexOf('\u0420\u044B\u0446\u0430\u0440\u044C\u003A') === 0)
|| (Trim(elem.innerHTML).indexOf('<b>\u0420\u044B\u0446\u0430\u0440\u044C\u003A') === 0)
)
{
return elem;
}
}
}
function GetAbilityToUpInfo()
{
var LFract = GetFraction(GM_getValue('selected_fract', ''), GetAllFractions());
if (LFract.AbilityLevel < 12)
{
var LSelectedLevel = Math.max(parseInt(GM_getValue('selected_level', 0)), (LFract.AbilityLevel + 1));
//Умение фракции (12 уровней)
var racial_skill_lvl = [20,50,90,160,280,500,900,1600,2900,5300,9600,17300];
var LAbilityToUp = racial_skill_lvl[LSelectedLevel - 1] - LFract.Ability;
return {AbilityToUp: LAbilityToUp, Fraction: LFract.Fraction, Level: LSelectedLevel};
}
}
function close_setting_form() {
bg = $('#bgOverlayEA') ;
bgc = $('#bgCenterEA') ;
if( bg ) {
bg.style.display = bgc.style.display = 'none' ;
}
MainProcess();
}
function abil_fractions_changed()
{
GM_setValue('selected_fract', $("#hwm_exp_abil_fractions").value);
GM_deleteValue('selected_level');
UpdateAbilLevels();
}
function GetFraction(AName, AAllFractions)
{
for(i = 0; i < AAllFractions.length; i++)
{
var LFract = AAllFractions[i];
if ((AName == '') && LFract.IsMain || (AName != '') && (LFract.Fraction == AName))
return LFract;
}
}
function UpdateAbilLevels()
{
var LSelect = $("#hwm_exp_abil_levels");
LSelect.innerHTML = '';
var LFract = GetFraction($("#hwm_exp_abil_fractions").value, GetAllFractions());
var LSelectedLevel = parseInt(GM_getValue('selected_level', 0));
for(i = LFract.AbilityLevel + 1; i <= 12; i++)
{
var option = document.createElement("option");
option.value = i;
option.text = i;
if (i == LSelectedLevel)
option.selected = '1';
LSelect.add(option);
}
}
function abil_levels_changed()
{
GM_setValue('selected_level', $("#hwm_exp_abil_levels").value);
}
function open_setting_form()
{
bg = $('#bgOverlayEA') ;
bgc = $('#bgCenterEA') ;
if( !bg ) {
bg = document.createElement('div') ;
bg.id = 'bgOverlayEA' ;
document.body.appendChild( bg );
bg.style.position = 'absolute' ;
bg.style.left = '0';
bg.style.width = '100%';
bg.style.height = '100%';
bg.style.background = "#000000";
bg.style.opacity = "0.5";
bg.addEventListener( "click", close_setting_form , false );
bgc = document.createElement('div') ;
bgc.id = 'bgCenterEA' ;
document.body.appendChild( bgc );
bgc.style.position = 'absolute' ;
bgc.style.width = '600px';
bgc.style.background = "#F6F3EA";
bgc.style.left = ( ( document.body.offsetWidth - 400 ) / 2 ) + 'px' ;
bgc.style.zIndex = "1105";
}
bgc.innerHTML =
'<div style="border:1px solid #abc;padding:5px;margin:2px;">' +
' <div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_closeEA" title="Закрыть">x</div>' +
' <center>' +
' <table>' +
' <tr>' +
' <td colspan="2"><b>'+str_script_name+' <font style="color:#0070FF;">'+version+'</font></b><hr/></td>' +
' </tr>' +
' <tr>' +
' <td colspan="2"><b>Настройки:</b></td>' +
' </tr>' +
' <tr>' +
' </tr>' +
' <tr>' +
' <td colspan="2"><b>Выберите фракцию и уровень умелки который хотите взять на этом уровне:</b></td>' +
' </tr>' +
' <tr>' +
' <td>Фракция</td>' +
' <td>' +
' <select style="width:220;" id="hwm_exp_abil_fractions"></select>' +
' </td>' +
' </tr>' +
' <tr>' +
' <td>Уровень умелки</td>' +
' <td>' +
' <select style="width:220;" id="hwm_exp_abil_levels"></select>' +
' </td>' +
' </tr>' +
' <tr><td colspan="2"><hr/></td></tr>' +
' <tr>' +
' <td colspan="2" style="font-weight:bold;font-size:10px;" >' +
' <a style="font-weight:bold;font-size:10px;" href="'+str_url+'">Проверить обновление скрипта.</a>' +
' <a style="font-weight:bold;font-size:10px;" href="'+str_url_aut+'">Сообщить автору о найденной ошибке.</a>' +
' </td>' +
' </tr>' +
' <tr>' +
' <td colspan="2" style="font-weight:bold;font-size:10px;" >' +
' Автор: <a style="font-weight:bold;font-size:10px;" href="http://www.heroeswm.ru/pl_info.php?id=30547">Pahan.</a>' +
' </td>' +
' </tr>' +
' </table>' +
' </center>' +
'</div>';
$("#bt_closeEA").addEventListener( "click", close_setting_form , false );
bg.style.top = (-document.body.scrollTop)+'px';
bgc.style.top = ( document.body.scrollTop + 100 ) + 'px';
bg.style.display = bgc.style.display = 'block' ;
var LFractSelect = $("#hwm_exp_abil_fractions");
addEvent(LFractSelect, 'change', abil_fractions_changed);
var LAllFractions = GetAllFractions();
var LSelectedFract = GM_getValue('selected_fract', '');
for(i = 0; i < LAllFractions.length; i++)
{
var LFract = LAllFractions[i];
var option = document.createElement("option");
option.value = LFract.Fraction;
option.text = LFract.Fraction + (LFract.IsMain ? ' (Основа)' : '') +
(!LFract.IsMain && LFract.IsCurrent ? ' (Играете сейчас)' : '');
if ((LSelectedFract == '') && LFract.IsMain
|| (LSelectedFract != '') && (LFract.Fraction == LSelectedFract)
)
{
option.selected = '1';
}
LFractSelect.add(option);
}
var LLevelSelect = $("#hwm_exp_abil_levels");
addEvent(LLevelSelect, 'change', abil_levels_changed);
UpdateAbilLevels();
}
function MainProcess()
{
var LAbilityToUpInfo = GetAbilityToUpInfo();
if (LAbilityToUpInfo)
{
var expoability = FloatFormat(GetExp() / LAbilityToUpInfo.AbilityToUp);
if (expelem)
{
if (!$("#hwm_exp_abil_options"))
{
expelem.innerHTML = expelem.innerHTML + ' ' +
'<a style="text-decoration:none;cursor:pointer;font-weight:bold;font-size:8px;" id="hwm_exp_abil_options">(' +
'<font color="red">' +
'<span id="hwm_exp_abil_el" />' +
'</font>)' +
'</a>';
}
$("#hwm_exp_abil_options").addEventListener( "click", open_setting_form , false );
var LEl = $("#hwm_exp_abil_el");
LEl.innerHTML = expoability;
LEl.title =
'Что б взять ' + LAbilityToUpInfo.Level + 'ю умелку фракции ' + LAbilityToUpInfo.Fraction + ' до апа уровня\n'+
'Вам нужно набрать ' + LAbilityToUpInfo.AbilityToUp + ' умения с соотношением ' + expoability;
}
}
}
window.addEventListener('load', MainProcess, false);