dailyhwm / Colored_Strength*

// ==UserScript==
// @name Colored_Strength*
// @author Ilovemycomp, xo4yxa
// @version 1.02.1
// @namespace colored
// @description Подсветка прочности вещей артефактов - инвентарь, рынок, "рынок - выставить новый лот", склад боевого клана (в том числе арты 1,2,3,4,5 прочности на складе).
// @homepage http://hwm.xo4yxa.ru/js/coloredstrength

// @include *heroeswm.ru/inventory.php
// @include *heroeswm.ru/sklad_info.php?id=*
// @include *heroeswm.ru/auction.php?*
// @include *heroeswm.ru/auction_new_lot.php
//
// @include *lordswm.com/inventory.php
// @include *lordswm.com/sklad_info.php?id=*
// @include *lordswm.com/auction.php?*
// @include *lordswm.com/auction_new_lot.php

// @license MIT
// ==/UserScript==
(function() {
    var item_hard_regexp, els, el;
	var url_cur = location.pathname;
	// Инвентарь
    function colored() {
        var els = document.getElementsByTagName('li');
		var item_hard_regexp = /: (\d+)\/(\d+)/;
		for (var i = 0; i < els.length; i++) {
            el = els[i];
			if (el.innerHTML.match(/\u041f\u0440\u043e\u0447\u043d\u043ec\u0442\u044c: /)) {
				// console.log(els[i].innerHTML);
				p = item_hard_regexp.exec(el.innerHTML);
				if (p !== null) {
					hard_g = p[2];
					hard_c = p[1];
				} else {
					hard_g = 0;
					hard_c = 0;
				}
                //console.log(hard_c+"/"+hard_g);
				if (hard_c == '0')
					el.parentNode.parentNode.parentNode.style.background = '#FFA07A'; // 0
				else if (hard_c < hard_g * 0.15)
					el.parentNode.parentNode.parentNode.style.background = '#EFC6D1'; // < 15%
				else if (hard_c < hard_g * 0.35)
					el.parentNode.parentNode.parentNode.style.background = '#DED4EF'; // < 35%
				else if (hard_c < hard_g * 0.50)
					el.parentNode.parentNode.parentNode.style.background = '#C6E2EF'; // < 50%
				else if (hard_c < hard_g * 0.80)
					el.parentNode.parentNode.parentNode.style.background = '#D4E8EF'; // < 80%
				else if (hard_c < hard_g * 0.90)
					el.parentNode.parentNode.parentNode.style.background = '#CBEED0'; // < 90%
				else if (hard_c < hard_g * 0.99)
					el.parentNode.parentNode.parentNode.style.background = '#DFF8C7'; // < 99%
				else if (hard_c == hard_g)
					el.parentNode.parentNode.parentNode.style.background = '#F7F7D9'; // < 100%
			}
		}
    }
	if(url_cur.indexOf("inventory.php") >= 0) {
        // Обновление при переключении класов оружия
		//document.getElementById("test").addEventListener("DOMNodeInserted",colored);
        colored();
	}
	// Склад
	if(url_cur.indexOf("sklad_info.php") >= 0) {
		els = document.getElementsByTagName('font');
		item_hard_regexp = /\[(\d+)\/(\d+)\]/;
		for (var i = 0; i < els.length; i++) {
			el = els[i];
			if (el.innerHTML.match(/\[\d+\/\d+\]/)) {
				// console.log(el.innerHTML);
				p = item_hard_regexp.exec(el.innerHTML);
				if (p !== null) {
					hard_g = p[2];
					hard_c = p[1];
				} else {
					hard_g = 0;
					hard_c = 0;
				}
				if (hard_c == '0')
					el.parentNode.style.background = '#FFAF7A'; // 0
				else if (hard_c == '1')
					el.parentNode.style.background = '#7B68EE'; // = 1
				else if (hard_c == '2')
					el.parentNode.style.background = '#6495ED'; // = 1
				else if (hard_c == '3')
					el.parentNode.style.background = '#4169E1'; // = 1
				else if (hard_c == '4')
					el.parentNode.style.background = '#5F9EA0'; // = 1
				else if (hard_c == '5')
					el.parentNode.style.background = '#48D1CC'; // = 1
				else if (hard_c < hard_g * 0.15)
					el.parentNode.style.background = '#EFC6D1'; // < 15%
				else if (hard_c < hard_g * 0.25)
					el.parentNode.style.background = '#DED4EF'; // < 25%
				else if (hard_c < hard_g * 0.50)
					el.parentNode.style.background = '#C6E2EF'; // < 50%
				else if (hard_c < hard_g * 0.80)
					el.parentNode.style.background = '#D4E8EF'; // < 80%
				else if (hard_c < hard_g * 0.90)
					el.parentNode.style.background = '#CBEED0'; // < 90%
				else if (hard_c < hard_g * 0.99)
					el.parentNode.style.background = '#DFF8C7'; // < 99%
				else if (hard_c == hard_g)
					el.parentNode.style.background = '#F7F7D9'; // < 100%
			}
		}
	}
	// Аукцион
	if(url_cur.indexOf("auction.php") >= 0) {
		els = document.getElementsByTagName('a');
		item_hard_regexp = /\: (\d+)\/(\d+)/;
		var item_hard_regexp2 = /<b>(\d+)<\/b><\/font>\/(\d+)/;
		for (var i = 0; i < els.length; i++) {
			el = els[i];
			if (el.href.match(/auction_lot_protocol.php/) && el.href != els[i - 1].href) {
				if ((hard_par = item_hard_regexp.exec(el.parentNode.innerHTML)) || (hard_par = item_hard_regexp2.exec(el.parentNode.innerHTML))) {
				hard_g = hard_par[2];
				hard_c = hard_par[1];
				item = el.parentNode.parentNode.firstChild;
				if (hard_c <= hard_g * 0.15)
					item.parentNode.style.background = '#FFA07A'; // 0
				else if (hard_c <= hard_g * 0.33)
					item.parentNode.style.background = '#DED7EF'; // < 25%
				else if (hard_c <= hard_g * 0.50)
					item.parentNode.style.background = '#C6E2EF'; // < 50%
				else if (hard_c < hard_g * 1)
					item.parentNode.style.background = '#DFF8C7'; // < 100%
				else if (hard_c == hard_g)
					item.parentNode.style.background = '#F7F7D9'; // = 100%
				}
			}
		}
	}
	// Аукцион выставление артов на продажу
	if(url_cur.indexOf("auction_new_lot.php") >= 0) {
		els = document.getElementsByTagName('option');
		item_hard_regexp = / (\d+)\/(\d+)/;
		for (var i = 0; i < els.length; i++) {
			el = els[i];
			if ((hard_par = item_hard_regexp.exec(el.innerHTML))) {
				hard_g = hard_par[2];
				hard_c = hard_par[1];
				item = el;
				if (hard_c <= hard_g * 0.15) {
					item.style.border = '1px solid #F00'; // 0
					item.style.background = '#FFC0CB';
				} else if (hard_c <= hard_g * 0.33) {
					item.style.border = '1px solid #F00'; // < 25%
					item.style.background = '#FFC0CB';
				} else if (hard_c <= hard_g * 0.50) {
					item.style.border = '1px solid #FFD700'; // < 50%
					item.style.background = '#EEE8AA';
				} else if (hard_c < hard_g * 1) {
					item.style.border = '1px solid #00F'; // < 100%
					item.style.background = '#87CEEB';
				} else if (hard_c == hard_g) {
					item.style.border = '1px solid #008000'; // =100%
					item.style.background = '#90EE90';
				}
			}
		}
	}
})();