hwm_inventory_new_lot

Выставление лота из инвентаря, сохранение цены для предмета

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

  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 Выставление лота из инвентаря, сохранение цены для предмета
  7. // @homepage https://greasyfork.org/en/users/18377-pahan
  8. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  9. // @version 1.6
  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 SavePrice()
  186. {
  187. var LSelect = document.forms.f.item;
  188. var LPriceEl = document.forms.f.price;
  189. var LName = LSelect.options[LSelect.selectedIndex].text.split(' (')[0].split(' [i]')[0];
  190. GM_setValue(LName, LPriceEl.value);
  191. LInfo = document.createTextNode('<b>Сохранена цена ' + LPriceEl.value + ' для артефакта "' + LName + '"<b>');
  192.  
  193. LInfo = $('#save_price_info');
  194. if (!LInfo)
  195. {
  196. LInfo = document.createElement('b');
  197. LInfo.id = 'save_price_info';
  198. $('#id_save_price').parentNode.appendChild(LInfo);
  199. }
  200. LInfo.innerHTML = 'Сохранена цена ' + LPriceEl.value + ' для артефакта "' + LName + '"';
  201. }
  202.  
  203. function LoadPrice()
  204. {
  205. var LSelect = document.forms.f.item;
  206. var LPriceEl = document.forms.f.price;
  207. var LName = LSelect.options[LSelect.selectedIndex].text.split(' (')[0].split(' [i]')[0];
  208. LPriceEl.value = GM_getValue(LName, '0');
  209. }
  210.  
  211. function DecrementPrice()
  212. {
  213. var LPriceEl = document.forms.f.price;
  214. LPriceEl.value = parseInt(LPriceEl.value) - 1;
  215. }
  216.  
  217. function IncrementPrice()
  218. {
  219. var LPriceEl = document.forms.f.price;
  220. LPriceEl.value = parseInt(LPriceEl.value) + 1;
  221. }
  222.  
  223. function setCheck(ch) {
  224. if( GM_getValue( ch ) && GM_getValue( ch ) == 1 )
  225. GM_setValue( ch , 0 );
  226. else
  227. GM_setValue( ch , 1 );
  228. }
  229.  
  230. function OneClickFormRefresh()
  231. {
  232. // if (GM_getValue('one_click', 0) == 1)
  233. //item=dragon_shield%40283657731&count=2&atype=1&price=8999&duration=4
  234. //sign=4e0ff8b42df1310cca913346be0185db&item=dragon_shield%40283657731&count=2&atype=1&price=8999&duration=4
  235. //document.forms.f.action = 'auction_accept_new_lot.php';
  236. //else
  237. // document.forms.f.action = 'auction_new_lot.php';
  238. }
  239.  
  240. function InitNewLotForm()
  241. {
  242. if (document.forms.f.sign)
  243. {
  244. if (GM_getValue('one_click', 0) == 1)
  245. document.forms.f.submit();
  246. }
  247. else
  248. {
  249. var LSelect = document.forms.f.item;
  250. addEvent(LSelect, 'change', LoadPrice);
  251. var LArt = decodeURIComponent(URLAttrValueGet('art', location.href));
  252. var LArtFull = '';
  253. if (LArt != '')
  254. {
  255. for(i = 0; i < LSelect.options.length; i++)
  256. {
  257. var LOption = LSelect.options[i];
  258. if (LOption.text.indexOf(LArt) == 0)
  259. {
  260. LArtFull = LOption.text;
  261. LSelect.selectedIndex = LOption.index;
  262. }
  263. }
  264. }
  265. var LCountEl = document.forms.f.count;
  266. var LCount = 1;
  267. if (LArtFull != '')
  268. {
  269. var regex = /\((\d+)\)/;
  270. var regex_res = regex.exec(LArtFull);
  271. if (regex_res)
  272. LCount = Math.min(parseInt(regex_res[1]), 3);
  273. }
  274. LCountEl.value = LCount;
  275. var LPriceEl = document.forms.f.price;
  276. addEvent(LPriceEl, "change", PriceTrimNewLotForm);
  277. addEvent(LPriceEl, "keyup", PriceTrimNewLotForm);
  278. addEvent(LPriceEl, "paste", PriceTrimNewLotForm);
  279. LoadPrice();
  280.  
  281. LNewDiv = document.createElement('b');
  282. LNewDiv.innerHTML = '<input type="button" style="width:80;" id="id_save_price" value="Сохранить">';
  283. LPriceEl.parentNode.insertBefore(LNewDiv, LPriceEl.nextSibling);
  284. addEvent($('#id_save_price'), "click", SavePrice);
  285.  
  286. LNewDiv = document.createElement('b');
  287. LNewDiv.innerHTML =
  288. '<input type="button" style="width:25;height:25;font-size=10px;padding:0;margin:0;" id="id_decrement_price" value="-">' +
  289. '<input type="button" style="width:25;height:25;font-size=10px;padding:0;margin:0;" id="id_increment_price" value="+">';
  290. LPriceEl.parentNode.insertBefore(LNewDiv, LPriceEl.nextSibling);
  291. addEvent($('#id_decrement_price'), "click", DecrementPrice);
  292. addEvent($('#id_increment_price'), "click", IncrementPrice);
  293. var LDurationEl = document.forms.f.duration;
  294. var LDuration = LNewLotDurationDef;
  295. var LDurationParam = URLAttrValueGet('d', location.href);
  296. if (LDurationParam == '30m')
  297. LDuration = 1;
  298. else
  299. if (LDurationParam == '1h')
  300. LDuration = 2;
  301. else
  302. if (LDurationParam == '3h')
  303. LDuration = 3;
  304. else
  305. if (LDurationParam == '6h')
  306. LDuration = 4;
  307. else
  308. if (LDurationParam == '12h')
  309. LDuration = 5;
  310. else
  311. if (LDurationParam == '1d')
  312. LDuration = 6;
  313. else
  314. if (LDurationParam == '2d')
  315. LDuration = 7;
  316. else
  317. if (LDurationParam == '3d')
  318. LDuration = 8;
  319. for(i = 0; i < LDurationEl.options.length; i++)
  320. {
  321. var LOption = LDurationEl.options[i];
  322. if (LOption.value == LDuration)
  323. {
  324. LDurationEl.selectedIndex = LOption.index;
  325. }
  326. }
  327. var LSubmits = document.querySelectorAll('input[type="submit"]');
  328. if (LSubmits && LSubmits.length > 0)
  329. {
  330. var LSubmit = LSubmits[0];
  331. LNewDiv = document.createElement('b');
  332. LNewDiv.innerHTML = '<input type="checkbox" id="id_one_click" title=""> Выставить лот в один клик';
  333. LSubmit.parentNode.insertBefore(LNewDiv, LSubmit.nextSibling);
  334. var check_one_click = $('#id_one_click');
  335. check_one_click.checked = GM_getValue('one_click', 0) == 1 ? 'checked' : '';
  336. OneClickFormRefresh();
  337. addEvent(check_one_click, "click", function(){setCheck('one_click');OneClickFormRefresh()});
  338. }
  339. }
  340. }
  341.  
  342. //----------------------------------------------------
  343.  
  344. function ProcessMain()
  345. {
  346. if (location.href.indexOf('/inventory.php') > -1)
  347. {
  348. AddNewLotHrefs();
  349. if(!$("#click_div"))
  350. {
  351. var add_click_div = document.createElement('div');
  352. add_click_div.id = "click_div";
  353. add_click_div.style.display = "none";
  354. document.querySelector("body").appendChild(add_click_div);
  355. }
  356. addEvent($("#click_div"), "click", SetTimer_ProcessMain);
  357. }
  358. else
  359. if (location.href.indexOf('/auction_new_lot.php') > -1)
  360. {
  361. InitNewLotForm();
  362. }
  363. }
  364.  
  365. ProcessMain();