hwm_inventory_new_lot

adds new lot links for all items in inventar

Versione datata 20/10/2015. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

//
// ==UserScript==
// @name           hwm_inventory_new_lot
// @author         Pahan https://greasyfork.org/uk/users/18377-pahan
// @namespace      hwm_pahan
// @description    adds new lot links for all items in inventar
// @homepage       https://greasyfork.org/en/users/18377-pahan
// @icon           http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
// @version        1.3
// @encoding 	   utf-8
// @include        http://*heroeswm.ru/inventory.php*
// @include        http://*heroeswm.ru/auction_new_lot.php*                
// @include        http://*lordswm.com/inventory.php*
// @include        http://*lordswm.com/auction_new_lot.php*                
// @include        http://178.248.235.15/inventory.php*
// @include        http://178.248.235.15/auction_new_lot.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==

// settings
LNewLotDurationDef = '3';
// settings end

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) {
    elem["on" + 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];
}

// -----------------------------------------------
var GlobalCultureName = location.href.match('lordswm') ? "en-US" : "ru-RU",
    GlobalStrings = {
        "ru-RU" : {
            Sell : "Пр-ь:",
            _30m : "30м",
            _1h : "1ч",
            _3h : "3ч",
            _6h : "6ч",
            _12h : "12ч",
            _1d : "1д",
            _2d : "2д",
            _3d : "3д",
        },
        "en-US" : {
            Sell : "Sell:",
            _30m : "30m",
            _1h : "1h",
            _3h : "3h",
            _6h : "6h",
            _12h : "12h",
            _1d : "1d",
            _2d : "2d",
            _3d : "3d",
        }
    },
    GlobalLocalizedString = GlobalStrings[GlobalCultureName];
// -----------------------------------------------


  
function GetProchkaInfo(ALink)
{
  var LElem = ALink.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  var regex = /\:\s+(\d+\/\d+)\<br\>/;
  var regex_res = regex.exec(LElem.innerHTML);
  if(regex_res)
    return regex_res[1];
  else
    return '';
}

function CheckCanSell(ALink)
{
  var LElem = ALink.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode; 
  var LLinks = LElem.querySelectorAll('a[href*="art_transfer.php"]');
  return (LLinks && (LLinks.length == 1));
}
  
function AddNewLotHref(ALink, AURL, ADurationDisp, ADuration)
{    
  ALink.parentNode.appendChild(document.createTextNode(' '));  	  
  LNewLotHref = document.createElement('a');
  LNewLotHref.href = AURL + '&d=' + ADuration;
  LNewLotHref.innerHTML = ADurationDisp;
  ALink.parentNode.appendChild(LNewLotHref);
}
  
function SetTimer_ProcessMain()
{
  setTimeout(AddNewLotHrefs, 10);
}

function AddNewLotHrefs()
{              
  var LLinks = document.querySelectorAll('a[href^="art_info.php"]');
  var LLink; 
  if (LLinks)
  {                
    for(i = 0; i < LLinks.length; i++)
    {                   
      LLink = LLinks[i];
      
      if (CheckCanSell(LLink))
      {
        var LName = LLink.children[0].innerHTML + ' ' + GetProchkaInfo(LLink);
        var LURL = '/auction_new_lot.php?art=' + encodeURIComponent(LName);
        
        var LLinksTest = LLink.parentNode.querySelectorAll('a[href^="' + LURL + '"]');
        if (LLinksTest && (LLinksTest.length > 0))
          continue;

                
        LLink.parentNode.appendChild(document.createElement('br'));
//        LLink.parentNode.appendChild(document.createTextNode('»»'));
        LLink.parentNode.appendChild(document.createTextNode(GlobalLocalizedString.Sell));

//        LNewLotHref = document.createElement('a');
//        LNewLotHref.href = LURL;
//        LNewLotHref.innerHTML = GlobalLocalizedString.Sell;
//        LLink.parentNode.appendChild(LNewLotHref);
        
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._30m, '30m');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._1h, '1h');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._3h, '3h');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._6h, '6h');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._12h, '12h');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._1d, '1d');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._2d, '2d');
        AddNewLotHref(LLink, LURL, GlobalLocalizedString._3d, '3d');
      }                                   
    }
  }
}

//----------------------------------------

function PriceTrimNewLotForm()
{
  var LPriceEl = document.forms.f.price;
  LPriceEl.value = LPriceEl.value.trim().replace(/[^\d]/g, '');
}

function InitNewLotForm()
{
  var LArt = decodeURIComponent(URLAttrValueGet('art', location.href));
  var LArtFull = '';
  if (LArt != '')
  {                    
    var LSelect = document.forms.f.item; 
    if (LSelect && (LSelect.type != 'hidden'))
    {
      for(i = 0; i < LSelect.options.length; i++)
      {                    
        var LOption = LSelect.options[i];
        if (LOption.text.indexOf(LArt) == 0)
        {
          LArtFull = LOption.text;
          LSelect.selectedIndex = LOption.index;
        }
      }
    }
  }
  
  var LCountEl = document.forms.f.count;
  if (LCountEl && (LCountEl.type != 'hidden'))
  {
    var LCount = 1;
    if (LArtFull != '')
    {
      var regex = /\((\d+)\)/;
      var regex_res = regex.exec(LArtFull);
      if (regex_res)
        LCount = Math.min(parseInt(regex_res[1]), 3);
    }
    LCountEl.value = LCount;
  }
  
  var LPriceEl = document.forms.f.price;    
  addEvent(LPriceEl, "change", PriceTrimNewLotForm);
  addEvent(LPriceEl, "keyup", PriceTrimNewLotForm);
  addEvent(LPriceEl, "paste", PriceTrimNewLotForm);
    
  var LDurationEl = document.forms.f.duration;
  if (LDurationEl && (LDurationEl.type != 'hidden'))
  {
    var LDuration = LNewLotDurationDef;
    var LDurationParam = URLAttrValueGet('d', location.href);
    if (LDurationParam == '30m')
      LDuration = 1;
    else
    if (LDurationParam == '1h')
      LDuration = 2;
    else
    if (LDurationParam == '3h')
      LDuration = 3;
    else
    if (LDurationParam == '6h')
      LDuration = 4;
    else
    if (LDurationParam == '12h')
      LDuration = 5;
    else
    if (LDurationParam == '1d')
      LDuration = 6;
    else
    if (LDurationParam == '2d')
      LDuration = 7;
    else
    if (LDurationParam == '3d')
      LDuration = 8;
    
    for(i = 0; i < LDurationEl.options.length; i++)
    {                    
      var LOption = LDurationEl.options[i];
      if (LOption.value == LDuration)
      {
        LDurationEl.selectedIndex = LOption.index;
      }
    }
  }
}

//----------------------------------------------------

function ProcessMain()
{
  if (location.href.indexOf('/inventory.php') > -1)
  {                  
    AddNewLotHrefs();
      
    if(!$("#click_div"))
    {
      var add_click_div = document.createElement('div');
      add_click_div.id = "click_div";
      add_click_div.style.display = "none";
      document.querySelector("body").appendChild(add_click_div);
    }
    addEvent($("#click_div"), "click", SetTimer_ProcessMain);    
  }
  else
  if (location.href.indexOf('/auction_new_lot.php') > -1)
  {                  
    InitNewLotForm();       
  }
}

ProcessMain();