hwm_inventory_new_lot

adds new lot links for all items in inventar

当前为 2015-10-20 提交的版本,查看 最新版本

  1. //
  2. // ==UserScript==
  3. // @name hwm_inventory_new_lot
  4. // @author Pahan https://greasyfork.org/uk/users/18377-pahan
  5. // @namespace hwm_pahan
  6. // @description adds new lot links for all items in inventar
  7. // @homepage https://greasyfork.org/en/users/18377-pahan
  8. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  9. // @version 1.2
  10. // @encoding utf-8
  11. // @include http://*heroeswm.ru/inventory.php*
  12. // @include http://*heroeswm.ru/auction_new_lot.php*
  13. // @include http://*lordswm.com/inventory.php*
  14. // @include http://*lordswm.com/auction_new_lot.php*
  15. // @include http://178.248.235.15/inventory.php*
  16. // @include http://178.248.235.15/auction_new_lot.php*
  17. // @grant GM_deleteValue
  18. // @grant GM_getValue
  19. // @grant GM_listValues
  20. // @grant GM_setValue
  21. // @grant GM_addStyle
  22. // @grant GM_log
  23. // @grant GM_openInTab
  24. // @grant GM_xmlhttpRequest
  25. // ==/UserScript==
  26.  
  27. // settings
  28. LNewLotDurationDef = '3';
  29. // settings end
  30.  
  31. if (typeof GM_deleteValue != 'function') {
  32. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  33. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  34. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  35.  
  36. this.GM_addStyle=function (key) {
  37. var style = document.createElement('style');
  38. style.textContent = key;
  39. document.querySelector("head").appendChild(style);
  40. }
  41. }
  42. if (typeof GM_listValues != 'function') {
  43. this.GM_listValues=function () {
  44. var values = [];
  45. for (var i=0; i<localStorage.length; i++) {
  46. values.push(localStorage.key(i));
  47. }
  48. return values;
  49. }
  50. }
  51.  
  52. function addEvent(elem, evType, fn) {
  53. elem["on" + evType] = fn;
  54. if (elem.addEventListener) {
  55. elem.addEventListener(evType, fn, false);
  56. }
  57. else if (elem.attachEvent) {
  58. elem.attachEvent("on" + evType, fn);
  59. }
  60. else {
  61. elem["on" + evType] = fn;
  62. }
  63. }
  64.  
  65. function $(id) { return document.querySelector("#"+id); }
  66.  
  67. function URLAttrValueGet(attr_name, aurl)
  68. {
  69. attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  70. var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
  71. var regex = new RegExp( regexS );
  72. var results = regex.exec( aurl );
  73. if( results == null )
  74. return "";
  75. else
  76. return results[1];
  77. }
  78.  
  79. // -----------------------------------------------
  80. var GlobalCultureName = location.href.match('lordswm') ? "en-US" : "ru-RU",
  81. GlobalStrings = {
  82. "ru-RU" : {
  83. Sell : "Пр-ь:",
  84. _30m : "30м",
  85. _1h : "1ч",
  86. _3h : "3ч",
  87. _6h : "6ч",
  88. _12h : "12ч",
  89. _1d : "1д",
  90. _2d : "2д",
  91. _3d : "3д",
  92. },
  93. "en-US" : {
  94. Sell : "Sell:",
  95. _30m : "30m",
  96. _1h : "1h",
  97. _3h : "3h",
  98. _6h : "6h",
  99. _12h : "12h",
  100. _1d : "1d",
  101. _2d : "2d",
  102. _3d : "3d",
  103. }
  104. },
  105. GlobalLocalizedString = GlobalStrings[GlobalCultureName];
  106. // -----------------------------------------------
  107.  
  108.  
  109. function GetProchkaInfo(ALink)
  110. {
  111. var LElem = ALink.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  112. var regex = /\:\s+(\d+\/\d+)\<br\>/;
  113. var regex_res = regex.exec(LElem.innerHTML);
  114. if(regex_res)
  115. return regex_res[1];
  116. else
  117. return '';
  118. }
  119.  
  120. function CheckCanSell(ALink)
  121. {
  122. var LElem = ALink.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  123. var LLinks = LElem.querySelectorAll('a[href*="art_transfer.php"]');
  124. return (LLinks && (LLinks.length == 1));
  125. }
  126. function AddNewLotHref(ALink, AURL, ADurationDisp, ADuration)
  127. {
  128. ALink.parentNode.appendChild(document.createTextNode(' '));
  129. LNewLotHref = document.createElement('a');
  130. LNewLotHref.href = AURL + '&d=' + ADuration;
  131. LNewLotHref.innerHTML = ADurationDisp;
  132. ALink.parentNode.appendChild(LNewLotHref);
  133. }
  134. function SetTimer_ProcessMain()
  135. {
  136. setTimeout(AddNewLotHrefs, 10);
  137. }
  138.  
  139. function AddNewLotHrefs()
  140. {
  141. var LLinks = document.querySelectorAll('a[href^="art_info.php"]');
  142. var LLink;
  143. if (LLinks)
  144. {
  145. for(i = 0; i < LLinks.length; i++)
  146. {
  147. LLink = LLinks[i];
  148. if (CheckCanSell(LLink))
  149. {
  150. var LName = LLink.children[0].innerHTML + ' ' + GetProchkaInfo(LLink);
  151. var LURL = '/auction_new_lot.php?art=' + encodeURIComponent(LName);
  152. var LLinksTest = LLink.parentNode.querySelectorAll('a[href^="' + LURL + '"]');
  153. if (LLinksTest && (LLinksTest.length > 0))
  154. continue;
  155.  
  156. LLink.parentNode.appendChild(document.createElement('br'));
  157. // LLink.parentNode.appendChild(document.createTextNode('»»'));
  158. LLink.parentNode.appendChild(document.createTextNode(GlobalLocalizedString.Sell));
  159.  
  160. // LNewLotHref = document.createElement('a');
  161. // LNewLotHref.href = LURL;
  162. // LNewLotHref.innerHTML = GlobalLocalizedString.Sell;
  163. // LLink.parentNode.appendChild(LNewLotHref);
  164. AddNewLotHref(LLink, LURL, GlobalLocalizedString._30m, '30m');
  165. AddNewLotHref(LLink, LURL, GlobalLocalizedString._1h, '1h');
  166. AddNewLotHref(LLink, LURL, GlobalLocalizedString._3h, '3h');
  167. AddNewLotHref(LLink, LURL, GlobalLocalizedString._6h, '6h');
  168. AddNewLotHref(LLink, LURL, GlobalLocalizedString._12h, '12h');
  169. AddNewLotHref(LLink, LURL, GlobalLocalizedString._1d, '1d');
  170. AddNewLotHref(LLink, LURL, GlobalLocalizedString._2d, '2d');
  171. AddNewLotHref(LLink, LURL, GlobalLocalizedString._3d, '3d');
  172. }
  173. }
  174. }
  175. }
  176.  
  177. //----------------------------------------
  178.  
  179. function PriceTrimNewLotForm()
  180. {
  181. var LPriceEl = document.forms.f.price;
  182. LPriceEl.value = LPriceEl.value.trim().replace(/[^\d]/g, '');
  183. }
  184.  
  185. function InitNewLotForm()
  186. {
  187. var LArt = decodeURIComponent(URLAttrValueGet('art', location.href));
  188. var LArtFull = '';
  189. if (LArt != '')
  190. {
  191. var LSelect = document.forms.f.item;
  192. if (LSelect && (LSelect.type != 'hidden'))
  193. {
  194. for(i = 0; i < LSelect.options.length; i++)
  195. {
  196. var LOption = LSelect.options[i];
  197. if (LOption.text.indexOf(LArt) == 0)
  198. {
  199. LArtFull = LOption.text;
  200. LSelect.selectedIndex = LOption.index;
  201. }
  202. }
  203. }
  204. }
  205. var LCountEl = document.forms.f.count;
  206. if (LCountEl && (LCountEl.type != 'hidden'))
  207. {
  208. var LCount = 1;
  209. if (LArtFull != '')
  210. {
  211. var regex = /\((\d+)\)/;
  212. var regex_res = regex.exec(LArtFull);
  213. if (regex_res)
  214. LCount = Math.min(parseInt(regex_res[1]), 3);
  215. }
  216. LCountEl.value = LCount;
  217. }
  218. var LPriceEl = document.forms.f.price;
  219. addEvent(LPriceEl, "change", PriceTrimNewLotForm);
  220. addEvent(LPriceEl, "keyup", PriceTrimNewLotForm);
  221. addEvent(LPriceEl, "paste", PriceTrimNewLotForm);
  222. var LDurationEl = document.forms.f.duration;
  223. if (LDurationEl && (LDurationEl.type != 'hidden'))
  224. {
  225. var LDuration = LNewLotDurationDef;
  226. var LDurationParam = URLAttrValueGet('d', location.href);
  227. if (LDurationParam == '30m')
  228. LDuration = 1;
  229. else
  230. if (LDurationParam == '1h')
  231. LDuration = 2;
  232. else
  233. if (LDurationParam == '3h')
  234. LDuration = 3;
  235. else
  236. if (LDurationParam == '6h')
  237. LDuration = 4;
  238. else
  239. if (LDurationParam == '12h')
  240. LDuration = 5;
  241. else
  242. if (LDurationParam == '1d')
  243. LDuration = 6;
  244. else
  245. if (LDurationParam == '2d')
  246. LDuration = 7;
  247. else
  248. if (LDurationParam == '3d')
  249. LDuration = 8;
  250. for(i = 0; i < LDurationEl.options.length; i++)
  251. {
  252. var LOption = LDurationEl.options[i];
  253. if (LOption.value == LDuration)
  254. {
  255. LDurationEl.selectedIndex = LOption.index;
  256. }
  257. }
  258. }
  259. }
  260.  
  261. //----------------------------------------------------
  262.  
  263. function ProcessMain()
  264. {
  265. if (location.href.indexOf('/inventory.php') > -1)
  266. {
  267. AddNewLotHrefs();
  268. if(!$("click_div"))
  269. {
  270. var add_click_div = document.createElement('div');
  271. add_click_div.id = "click_div";
  272. add_click_div.style.display = "none";
  273. document.querySelector("body").appendChild(add_click_div);
  274. }
  275. addEvent($("click_div"), "click", SetTimer_ProcessMain);
  276. }
  277. else
  278. if (location.href.indexOf('/auction_new_lot.php') > -1)
  279. {
  280. InitNewLotForm();
  281. }
  282. }
  283.  
  284. ProcessMain();