HWM_Resources_Cost

Отображает общую стоимость ресурсов (дерево, руда, рутть и т.п.) на странице персонажа по цене 170/350

目前為 2015-03-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name HWM_Resources_Cost
// @description   Отображает общую стоимость ресурсов (дерево, руда, рутть и т.п.) на странице персонажа по цене 170/350
// @namespace  ResourcesCost
// @author  Zeleax
// @include http://www.heroeswm.ru/pl_info.php*
// @include http://178.248.235.15/pl_info.php*
// @include http://www.lordswm.com/pl_info.php*
// @grant   none
// @version 1.0
// ==/UserScript==
var prices = ["wood", 170, "ore", 170, "mercury", 350, "sulfur", 350, "crystal", 350, "gem", 350 ]; // ore.gif
var row =  getElementByXpath("/html/body/center/table/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/table/tbody/tr");
var totalcost = 0;

var el = row.firstChild;
while(el != null)
{
	//console.log(el.firstChild.getAttribute('src'));	
  var imgname = el.firstChild.getAttribute('src');
  var res = /([a-z]{1,}).gif/.exec(imgname); 
	
	if(res[1]==null) break;
	
  for(var i=0; i<prices.length; i += 2){
    if(prices[i]==res[1])
  	{
			var kolvo = el.nextSibling;
			totalcost += parseInt(kolvo.firstChild.innerHTML.replace(',',''), 10) * prices[i+1];
	  	break;
  	}
  }
  el = el.nextSibling.nextSibling;
}
console.log("Total cost: "+ totalcost);
createCell(row.insertCell(-1), " = "+totalcost, 'row');

// 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 getElementByXpath (path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}