// ==UserScript==
// @name InfoPerk
// @namespace perk
// @autor Sweag
// @description Perk table -> homepage
// @include https://www.heroeswm.ru/home.php*
// @include https://www.lordswm.com/home.php*
// @include http://178.248.235.15/home.php*
// @homepage https://gf.qytechs.cn/en/scripts/378276-infoperk
// @version 1.6.1
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
// fix by CheckT: include, мелкие правки, рефакторинг, настройки
// old homepage https://gf.qytechs.cn/ru/scripts/25129-infoperk
(function(){
var url_cur = location.href;
var url = location.protocol+'//'+location.hostname+'/';
var gm_prefix = 'hwmip_';
initGm();
var isLords = (location.hostname == 'www.lordswm.com');
var show_kukla = gm_get('kukla', '1');
var show_perks = gm_get('perks', '2');
get_table(url+'pl_info.php?id='+getPlayerId());
return; //only functions below
function find_place_center(){
var mana = (isLords?'Mana:':'Мана:');
var b = document.getElementsByTagName('B');
for(var i=0; i<b.length; i++){
if(b[i].innerHTML == mana)
return b[i].parentNode;
}
return null;
}
function find_place_right(){
var last_battle = (isLords?'Last combat':'Последний бой');
var b = document.getElementsByTagName('B');
for(var i=0; i<b.length; i++){
if(b[i].innerHTML == last_battle)
return b[i].parentNode.parentNode;
}
return null;
}
function insert_table(_perk_, _kukla_){
var td_place_right = find_place_right();
var td_place_center = find_place_center();
td_place_center.innerHTML += '<br/><span title="Настроки отображения перков и куклы" style="cursor:pointer;text-decoration: underline;" id="'+gm_prefix+'set">позиция куклы</span><br/>' ;
switch(show_kukla){
case '1':
td_place_center.innerHTML += _kukla_;
break;
case '2':
td_place_right.innerHTML += _kukla_;
break;
default:
}
switch(show_perks){
case '1':
td_place_center.innerHTML += _perk_;
break;
case '2':
td_place_right.innerHTML += _perk_;
break;
default:
}
addClickEvent_GM('set', setting_show);
}
function get_table(href) {
var xhr = new XMLHttpRequest();
xhr.open("GET", href, true);
xhr.overrideMimeType('text/html; charset=windows-1251');
xhr.send();
xhr.onreadystatechange = function() { process_xhr(xhr); }
}
function process_xhr(xhr){
if (xhr.readyState != 4)
return;
if (xhr.status == 200) {
var table_perk = "<";
var table_kukla = "<";
var text = xhr.responseText.split('table');
for(var i=1; i<text.length; i++){
if(text[i].indexOf('showperkinfo.php') > -1){
table_perk += "table" + text[i-1] + "table" + text[i];
}
if(text[i].indexOf('kukla') > -1){
table_kukla += "table" + text[i-1] + "table" + text[i];
}
}
table_perk += "table>";
table_kukla += "table></table>";
insert_table(table_perk, table_kukla);
}
}
//------------
function setting_show(){
var bg = $$GM('overlay');
var bgc = $$GM('center');
var bg_height = ScrollHeight();
var width = 500;
if ( !bg ){
bg = document.createElement('div');
document.body.appendChild( bg );
bgc = document.createElement('div');
document.body.appendChild( bgc );
bg.id = gm_prefix+'overlay';
bg.style.position = 'absolute';
bg.style.left = '0px';
bg.style.width = '100%';
bg.style.background = "#000000";
bg.style.opacity = "0.5";
bg.style.zIndex = "7";
bgc.id = gm_prefix+'center';
bgc.style.position = 'absolute';
bgc.style.width = width+'px';
bgc.style.background = "#F6F3EA";
bgc.style.zIndex = "8";
}
bgc.style.left = ( ( ClientWidth() - width ) / 2 ) + 'px';
addEvent(bg, "click", setting_hide);
//Настройки
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="'+gm_prefix+'s_close" title="Close">x</div>'
+ '<table width=100% height=100%>'
+ '<tr><th colspan="2">После изменения перезагрузите страницу</td></tr><tr>'
+ '<tr><td align="center">Кукла персонажа</td><td align="center">Перки персонажа</td></tr><tr>'
+ '<td align="center">'
+ 'Слева:'+html_add_radio('kukla', '1', show_kukla)
+ ' Справа:'+html_add_radio('kukla', '2', show_kukla)
+ ' Скрыта:'+html_add_radio('kukla', '0', show_kukla)
+ '</td><td align="center">'
+ 'Слева:'+html_add_radio('perks', '1', show_perks)
+ ' Справа:'+html_add_radio('perks', '2', show_perks)
+ ' Скрыты:'+html_add_radio('perks', '0', show_perks)
+ '</td></tr>'
+ '<tr><td style="text-align:center" colspan="2">'
+ '<input type="button" id="'+gm_prefix+'s_close2" value="Close" title="Закрыть окно"/>'
+ '</td></tr></table></div>';
addClickEvent_GM("s_close", setting_hide);
addClickEvent_GM("s_close2", setting_hide);
addClickEvent_GM("kukla0", set_type);
addClickEvent_GM("kukla1", set_type);
addClickEvent_GM("kukla2", set_type);
addClickEvent_GM("perks0", set_type);
addClickEvent_GM("perks1", set_type);
addClickEvent_GM("perks2", set_type);
bg.style.top = '0px';
bg.style.height = bg_height + 'px';
bgc.style.top = ( window.pageYOffset + 150 ) + 'px';
bg.style.display = '';
bgc.style.display = '';
}
function setting_hide(){
var bg = $$GM('overlay');
var bgc = $$GM('center');
bg.parentNode.removeChild(bg);
bgc.parentNode.removeChild(bgc);
}
function set_type(e) {
if (e.target.checked) {
var checked_radio_id = e.target.getAttribute('id');
var checked_radio_name = e.target.getAttribute('name');
//<input type="radio" id="hwmip_kukla1" name="hwmip_kukla" value="1" checked="on">
if(checked_radio_id && checked_radio_name){
var value = checked_radio_id.substring(checked_radio_name.length);
GM_setValue(checked_radio_name, value);
}
}
}
function html_add_id(id){
return ' id="'+gm_prefix+id+'"';
}
function html_add_radio(name, value, currvalue){
return '<input type="radio"'+html_add_id(name+value)
+' name="'+gm_prefix+html_null_to_empty(name)+'"'
+' value="'+html_null_to_empty(value)+'"'
+(currvalue==value?' checked="on"':'')+'/>';
}
function html_null_to_empty(val){
return (val || val===false) ? val : '';
}
function getPlayerId(){
var hunter_ref = getI("//a[contains(@href, 'pl_hunter_stat')]");
//min 2 для home; min 1 для остальных - если включены выпадающие вкладки
//min 1 для home; min 0 для остальных - если отключены выпадающие вкладки
if ( !hunter_ref || hunter_ref.snapshotLength == 0 || (hunter_ref.snapshotLength == 1 && location.pathname == '/home.php') ) {
//отключены вкладки или разлогин
} else {
return hunter_ref.snapshotItem(0).href.split('?id=')[1];
}
}
function addClickEvent_GM(id, func){
addEvent($$GM(id), "click", func);
}
function addEvent(elem, evType, fn) {
if(elem && fn){
if (elem.addEventListener)
elem.addEventListener(evType, fn, false);
else if (elem.attachEvent)
elem.attachEvent("on" + evType, fn);
else
elem["on" + evType] = fn;
}
}
function getI(xpath,elem){return document.evaluate(xpath,(elem?elem:document),null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);}
function $$(id) { return document.getElementById(id); }
function $$GM(id) { return $$(gm_prefix+id); }
function gm_get(key, def){
return GM_getValue(gm_prefix+key, def);
}
function gm_set(key, val){
return GM_setValue(gm_prefix+key, val);
}
function initGm(){
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
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];
};
}
if (!this.GM_listValues || (this.GM_listValues.toString && this.GM_listValues.toString().indexOf("not supported")>-1)) {
this.GM_listValues=function () {
var keys=[];
for (var key in localStorage){
keys.push(key);
}
return keys;
};
}
}
function ClientWidth(){
return document.compatMode=='CSS1Compat' && document.documentElement?document.documentElement.clientWidth:document.body.clientWidth;
}
function ScrollHeight(){
return Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
}
})();