您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Отображает на странице персонажа общую стоимость ресурсов (дерево, руда, ртуть и т.п.) по цене 170/350 и общую рыночную стоимость элементов, скрывает части артов/отрядов
当前为
// ==UserScript== // @name HWM_Resources_Cost // @description Отображает на странице персонажа общую стоимость ресурсов (дерево, руда, ртуть и т.п.) по цене 170/350 и общую рыночную стоимость элементов, скрывает части артов/отрядов // @namespace Zeleax // @author Zeleax // @include /https?:\/\/(www.heroeswm.ru|178.248.235.15|www.lordswm.com)\/pl_info.php/ // @grant none // @version 2.7 // ==/UserScript== // Цены var resPrices = {"wood": 170, "ore": 170, "mercury": 350, "sulfur": 350, "crystals": 350, "gems": 350} // ресурсы // Ниже ничего не менять! var elPricesTemplate = {"абразив":0, "змеиный яд":0, "клык тигра":0, "ледяной кристалл":0, "лунный камень":0, "огненный кристалл":0, "осколок метеорита":0, "цветок ведьм":0, "цветок ветров":0, "цветок папоротника":0, "ядовитый гриб":0}; // GM functions if (typeof GM_getValue != '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];};} // Восстанавливаем цены в массив var marketPricesSaveDate = GM_getValue('hwmResorcesCost_saveDate',null); var elPrices=JSON.parse(GM_getValue('hwmResorcesCost_elPrices',null)); if (elPrices==null || Object.keys(elPrices).length!=Object.keys(elPricesTemplate).length || elPrices[Object.keys(elPrices)[0]]==0) { elPrices=elPricesTemplate; getElementsPricesFromMarket(); } // Ресурсы var resRow = getE("(//img[contains(@src,'wood.png')])[last()]").parentNode.parentNode; var resArr = resRow.getElementsByTagName('img'); var resSum = 0; var res, imgname, rPrice, elCell; // console.log('resArr',resArr); for(var i=0, el; el=resArr[i]; i++) if((imgname = el.getAttribute('src')) && (res = /([a-z]{1,}).png/.exec(imgname)) && (res[1]) && (rPrice = resPrices[res[1]]) ) resSum += parseInt(el.parentNode.nextSibling.firstChild.innerHTML.replace(',',''), 10) * rPrice; createCell(resRow.insertCell(-1), " = "+resSum, 'resRow'); // Элементы var tdResourcesTitle = getE("//td[b[text()='Ресурсы']]"); // кнопка управления отображением частей var span = document.createElement("SPAN"); span.innerHTML=' '; tdResourcesTitle.appendChild(span); var btnParts = newButton('-', 'Показать/скрыть ресурсы', ()=>{func_swapElementsVisibility()}); tdResourcesTitle.appendChild(btnParts); if(tdResourcesTitle) elCell = tdResourcesTitle.parentNode.nextSibling.firstChild; var myRe = /<b>(\D+)<\D+: (\d+)/g; resArr = []; while (res = myRe.exec(elCell.innerHTML)) resArr[res[1]]=res[2]; RefreshTable(); func_swapElementsVisibility(); function RefreshTable() { // Создаем таблицу с ценами var elSum = 0 var elPosCnt=0, ePrice; var html = []; html.push('<table><tbody><tr><td></td><td>Кол-во</td><td align="right">Цена</td></tr>'); var html1 = []; // spoiler - не элементы var html2 = []; // элементы var obj, classname; for (var key in resArr) { if(ePrice= elPrices[key]) {obj=html2; classname='nospoil';} else {obj=html1; classname='spoil';} obj.push('<tr class="'+classname+'"><td><b>'+key+'<b></td><td align="right">'+resArr[key]+'</td><td align="right">'); if(ePrice= elPrices[key]) // цена { obj.push('<i>'+ePrice+'</i>'); elSum += parseInt(resArr[key])*ePrice; elPosCnt++; } obj.push('</td></tr>'); } html.push(...html1); html.push(...html2); html.push('<tr><td><input type="button" name="btnRefreshPrices" value="Обновить стоимость" /></td><td></td><td align="right" title="Общая стоимость элементов"><b>'+elSum+'</b></td></tr></tbody></table>'); if(elPosCnt>0) { elCell.innerHTML = html.join(""); el=document.getElementsByName('btnRefreshPrices')[0]; el.onclick =function() {getElementsPricesFromMarket(); func_refreshElementsVisibility();} el.title='Цены обновлены '+marketPricesSaveDate; } } function func_refreshElementsVisibility(){ var newStyle= btnParts.value=='+' ? 'none' :'table-row'; // скрываем/отображаем элементы var divsToHide = document.getElementsByClassName("spoil"); for(var i = 0; i < divsToHide.length; i++){ divsToHide[i].style.display = newStyle; } } function func_swapElementsVisibility(){ var newStyle; if(btnParts.value=='+'){ btnParts.value = '-'; newStyle='table-row'; } else{ btnParts.value = '+'; newStyle='none'; } func_refreshElementsVisibility(); } // Загрузить цены на элементы c рынка function getElementsPricesFromMarket() { var docObj = func_getDocumentFromUrl('/auction.php?cat=elements&sort=4&type=0&sbn=1&sau=0'); var tdlist=getL(" //td[a[contains(@href, 'auction_lot_protocol')]]",null,docObj); if(tdlist.snapshotLength>0){ for (var key in elPrices) elPrices[key]=0; // очистка цен var elCnt=Object.keys(elPrices).length; for(var i=0; i<tdlist.snapshotLength && elCnt>0; i++) { el= tdlist.snapshotItem(i).parentNode.parentNode.parentNode.parentNode.parentNode; res=/\d+ - ([^\[]+\S).+\[i.{2,20}сразу!([0-9,]+)/.exec(el.textContent); if ((res) && elPrices[res[1]]==0) { elPrices[res[1]]=parseInt(res[2].replace(',',''),10); elCnt--; } } GM_setValue("hwmResorcesCost_elPrices", JSON.stringify(elPrices)); marketPricesSaveDate=(new Date()).toLocaleString(); GM_setValue("hwmResorcesCost_saveDate", marketPricesSaveDate); RefreshTable(); } else alert('Цены не обновляются при переходе по карте, участии в бою, таверне и т.д.'); return; } // create DIV element and append to the table cell function createCell(cell, text, style) { var div = document.createElement('div'), // create DIV element txt = document.createTextNode(text); // create text node div.appendChild(txt); // append text node to the DIV div.setAttribute('class', style); // set DIV class attribute div.setAttribute('className', style); // set DIV class attribute for IE (?!) cell.appendChild(div); // append DIV to the table cell } function newButton(text, title, func){var btn = document.createElement('input'); btn.type = "button"; btn.className = "btn"; btn.value = text; btn.title=title; btn.onclick = func; return btn; } // получает документ по заданному URL function func_getDocumentFromUrl(urlToLoad){var req=new XMLHttpRequest(); req.open("GET", urlToLoad, false); req.overrideMimeType('text/xml; charset=windows-1251'); req.send(null); var parser = new DOMParser(); return parser.parseFromString(req.responseText, "text/html"); } // доступ по xpath function getE(xpath,el,docObj){return (docObj?docObj:document).evaluate(xpath,(el?el:(docObj?docObj.body:document.body)),null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;} function getL(xpath,el,docObj){return (docObj?docObj:document).evaluate(xpath,(el?el:(docObj?docObj.body:document.body)),null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);}