hwm_inventory_new_lot

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

当前为 2015-11-17 提交的版本,查看 最新版本

  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/uk/scripts/13223-hwm-inventory-new-lot
  8. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  9. // @version 1.71
  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. var version = '1.71';
  28. var str_url = 'https://greasyfork.org/uk/scripts/13223-hwm-inventory-new-lot';
  29. var str_script_name = 'Новый лот из инвентаря';
  30. var str_url_aut = '/sms-create.php?mailto=Pahan&subject=Скрипт: '+str_script_name+' v'+version+'. Найдена ошибка:';
  31.  
  32. // settings
  33. LNewLotDurationDef = '3';
  34. // settings end
  35.  
  36. if (typeof GM_deleteValue != 'function') {
  37. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  38. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  39. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  40.  
  41. this.GM_addStyle=function (key) {
  42. var style = document.createElement('style');
  43. style.textContent = key;
  44. document.querySelector("head").appendChild(style);
  45. }
  46. }
  47. if (typeof GM_listValues != 'function') {
  48. this.GM_listValues=function () {
  49. var values = [];
  50. for (var i=0; i<localStorage.length; i++) {
  51. values.push(localStorage.key(i));
  52. }
  53. return values;
  54. }
  55. }
  56.  
  57. function addEvent(elem, evType, fn) {
  58. // elem["on" + evType] = fn;
  59. if (elem.addEventListener) {
  60. elem.addEventListener(evType, fn, false);
  61. }
  62. else if (elem.attachEvent) {
  63. elem.attachEvent("on" + evType, fn);
  64. }
  65. else {
  66. elem["on" + evType] = fn;
  67. }
  68. }
  69.  
  70. function $(id) { return document.querySelector(id); }
  71.  
  72. function URLAttrValueGet(attr_name, aurl)
  73. {
  74. attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  75. var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
  76. var regex = new RegExp( regexS );
  77. var results = regex.exec( aurl );
  78. if( results == null )
  79. return "";
  80. else
  81. return results[1];
  82. }
  83.  
  84. // -----------------------------------------------
  85. var GlobalCultureName = location.href.match('lordswm') ? "en-US" : "ru-RU",
  86. GlobalStrings = {
  87. "ru-RU" : {
  88. Sell : "Пр-ь:",
  89. _30m : "30м",
  90. _1h : "1ч",
  91. _3h : "3ч",
  92. _6h : "6ч",
  93. _12h : "12ч",
  94. _1d : "1д",
  95. _2d : "2д",
  96. _3d : "3д",
  97. },
  98. "en-US" : {
  99. Sell : "Sell:",
  100. _30m : "30m",
  101. _1h : "1h",
  102. _3h : "3h",
  103. _6h : "6h",
  104. _12h : "12h",
  105. _1d : "1d",
  106. _2d : "2d",
  107. _3d : "3d",
  108. }
  109. },
  110. GlobalLocalizedString = GlobalStrings[GlobalCultureName];
  111. // -----------------------------------------------
  112.  
  113.  
  114. function GetProchkaInfo(ALink)
  115. {
  116. var LElem = ALink.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  117. var regex = /\:\s+(\d+\/\d+)\<br\>/;
  118. var regex_res = regex.exec(LElem.innerHTML);
  119. if(regex_res)
  120. return regex_res[1];
  121. else
  122. return '';
  123. }
  124.  
  125. function CheckCanSell(ALink)
  126. {
  127. var LElem = ALink.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  128. var LLinks = LElem.querySelectorAll('a[href*="art_transfer.php"]');
  129. return (LLinks && (LLinks.length == 1));
  130. }
  131. function AddNewLotHref(ALink, AURL, ADurationDisp, ADuration)
  132. {
  133. ALink.parentNode.appendChild(document.createTextNode(' '));
  134. LNewLotHref = document.createElement('a');
  135. LNewLotHref.href = AURL + '&d=' + ADuration;
  136. LNewLotHref.innerHTML = ADurationDisp;
  137. ALink.parentNode.appendChild(LNewLotHref);
  138. }
  139. function SetTimer_ProcessMain()
  140. {
  141. setTimeout(AddNewLotHrefs, 10);
  142. }
  143.  
  144. function AddNewLotHrefs()
  145. {
  146. var LLinks = document.querySelectorAll('a[href^="art_info.php"]');
  147. var LLink;
  148. if (LLinks)
  149. {
  150. for(i = 0; i < LLinks.length; i++)
  151. {
  152. LLink = LLinks[i];
  153. if (CheckCanSell(LLink))
  154. {
  155. var LName = LLink.children[0].innerHTML + ' ' + GetProchkaInfo(LLink);
  156. var LURL = '/auction_new_lot.php?art=' + encodeURIComponent(LName);
  157. var LLinksTest = LLink.parentNode.querySelectorAll('a[href^="' + LURL + '"]');
  158. if (LLinksTest && (LLinksTest.length > 0))
  159. continue;
  160.  
  161. LLink.parentNode.appendChild(document.createElement('br'));
  162. // LLink.parentNode.appendChild(document.createTextNode('»»'));
  163. LLink.parentNode.appendChild(document.createTextNode(GlobalLocalizedString.Sell));
  164.  
  165. // LNewLotHref = document.createElement('a');
  166. // LNewLotHref.href = LURL;
  167. // LNewLotHref.innerHTML = GlobalLocalizedString.Sell;
  168. // LLink.parentNode.appendChild(LNewLotHref);
  169. AddNewLotHref(LLink, LURL, GlobalLocalizedString._30m, '30m');
  170. AddNewLotHref(LLink, LURL, GlobalLocalizedString._1h, '1h');
  171. AddNewLotHref(LLink, LURL, GlobalLocalizedString._3h, '3h');
  172. AddNewLotHref(LLink, LURL, GlobalLocalizedString._6h, '6h');
  173. AddNewLotHref(LLink, LURL, GlobalLocalizedString._12h, '12h');
  174. AddNewLotHref(LLink, LURL, GlobalLocalizedString._1d, '1d');
  175. AddNewLotHref(LLink, LURL, GlobalLocalizedString._2d, '2d');
  176. AddNewLotHref(LLink, LURL, GlobalLocalizedString._3d, '3d');
  177. }
  178. }
  179. }
  180. }
  181.  
  182. //----------------------------------------
  183.  
  184. function PriceTrimNewLotForm()
  185. {
  186. var LPriceEl = document.forms.f.price;
  187. LPriceEl.value = LPriceEl.value.trim().replace(/[^\d]/g, '');
  188. }
  189.  
  190. function SavePrice()
  191. {
  192. var LSelect = document.forms.f.item;
  193. var LPrice = parseInt(document.forms.f.price.value);
  194. var LName = LSelect.options[LSelect.selectedIndex].text.split(' (')[0].split(' [i]')[0];
  195. if (LName != '')
  196. {
  197. LInfo = document.createTextNode('');
  198. LInfo = $('#save_price_info');
  199. if (!LInfo)
  200. {
  201. LInfo = document.createElement('b');
  202. LInfo.id = 'save_price_info';
  203. $('#id_save_price').parentNode.appendChild(LInfo);
  204. }
  205. if (LPrice && (LPrice != 0) && (LPrice != ''))
  206. {
  207. GM_setValue(LName, LPrice);
  208. LInfo.innerHTML = 'Сохранена цена ' + LPrice + ' для артефакта "' + LName + '"';
  209. }
  210. else
  211. {
  212. GM_deleteValue(LName);
  213. LInfo.innerHTML = 'Удалена цена для артефакта "' + LName + '"';
  214. }
  215. }
  216. }
  217.  
  218. function LoadPrice()
  219. {
  220. var LSelect = document.forms.f.item;
  221. var LPriceEl = document.forms.f.price;
  222. var LName = LSelect.options[LSelect.selectedIndex].text.split(' (')[0].split(' [i]')[0];
  223. LPriceEl.value = GM_getValue(LName, '0');
  224. }
  225.  
  226. function DecrementPrice()
  227. {
  228. var LPriceEl = document.forms.f.price;
  229. LPriceEl.value = parseInt(LPriceEl.value) - 1;
  230. }
  231.  
  232. function IncrementPrice()
  233. {
  234. var LPriceEl = document.forms.f.price;
  235. LPriceEl.value = parseInt(LPriceEl.value) + 1;
  236. }
  237.  
  238. function setCheck(ch) {
  239. if( GM_getValue( ch ) && GM_getValue( ch ) == 1 )
  240. GM_setValue( ch , 0 );
  241. else
  242. GM_setValue( ch , 1 );
  243. }
  244.  
  245. function close_setting_form() {
  246. bg = $('#bgOverlay_inventory_nl') ;
  247. bgc = $('#bgCenter_inventory_nl') ;
  248. if( bg ) {
  249. bg.style.display = bgc.style.display = 'none' ;
  250. }
  251. }
  252.  
  253. function open_setting_form()
  254. {
  255. bg = $('#bgOverlay_inventory_nl') ;
  256. bgc = $('#bgCenter_inventory_nl') ;
  257. if( !bg ) {
  258. bg = document.createElement('div') ;
  259. bg.id = 'bgOverlay_inventory_nl' ;
  260. document.body.appendChild( bg );
  261. bg.style.position = 'absolute' ;
  262. bg.style.left = '0';
  263. bg.style.width = '100%';
  264. bg.style.height = '100%';
  265. bg.style.background = "#000000";
  266. bg.style.opacity = "0.5";
  267. bg.addEventListener( "click", close_setting_form , false );
  268.  
  269. bgc = document.createElement('div') ;
  270. bgc.id = 'bgCenter_inventory_nl' ;
  271. document.body.appendChild( bgc );
  272. bgc.style.position = 'absolute' ;
  273. bgc.style.width = '600px';
  274. bgc.style.background = "#F6F3EA";
  275. bgc.style.left = ( ( document.body.offsetWidth - 400 ) / 2 ) + 'px' ;
  276. bgc.style.zIndex = "1105";
  277. }
  278. bgc.innerHTML =
  279. '<div style="border:1px solid #abc;padding:5px;margin:2px;">' +
  280. ' <div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_close_inventory_nl" title="Закрыть">x</div>' +
  281. ' <center>' +
  282. ' <table>' +
  283. ' <tr>' +
  284. ' <td><b>'+str_script_name+' <font style="color:#0070FF;">'+version+'</font></b><hr/></td>' +
  285. ' </tr>' +
  286. ' <tr>' +
  287. ' <td><b>Настройки:</b></td>' +
  288. ' </tr>' +
  289. ' <tr>' +
  290. ' </tr>' +
  291. ' <tr>' +
  292. ' <td>Пока пусто</td>' +
  293. ' </tr>' +
  294. ' <tr><td><hr/></td></tr>' +
  295. ' <tr>' +
  296. ' <td style="font-weight:bold;font-size:10px;" >' +
  297. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url+'">Проверить обновление скрипта.</a>' +
  298. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url_aut+'">Сообщить автору о найденной ошибке.</a>' +
  299. ' </td>' +
  300. ' </tr>' +
  301. ' <tr>' +
  302. ' <td style="font-weight:bold;font-size:10px;" >' +
  303. ' Автор: <a style="font-weight:bold;font-size:10px;" href="http://www.heroeswm.ru/pl_info.php?id=30547">Pahan.</a>' +
  304. ' </td>' +
  305. ' </tr>' +
  306. ' </table>' +
  307. ' </center>' +
  308. '</div>';
  309. $("#bt_close_inventory_nl").addEventListener( "click", close_setting_form , false );
  310. bg.style.top = (-document.body.scrollTop)+'px';
  311. bgc.style.top = ( document.body.scrollTop + 100 ) + 'px';
  312. bg.style.display = bgc.style.display = 'block' ;
  313. }
  314.  
  315. function InitNewLotForm()
  316. {
  317. if (document.forms.f.sign)
  318. {
  319. if (GM_getValue('one_click', 0) == 1)
  320. document.forms.f.submit();
  321. }
  322. else
  323. {
  324. var LSelect = document.forms.f.item;
  325. addEvent(LSelect, 'change', LoadPrice);
  326. var LArt = decodeURIComponent(URLAttrValueGet('art', location.href));
  327. var LArtFull = '';
  328. if (LArt != '')
  329. {
  330. for(i = 0; i < LSelect.options.length; i++)
  331. {
  332. var LOption = LSelect.options[i];
  333. if (LOption.text.indexOf(LArt) == 0)
  334. {
  335. LArtFull = LOption.text;
  336. LSelect.selectedIndex = LOption.index;
  337. }
  338. }
  339. }
  340. var LCountEl = document.forms.f.count;
  341. var LCount = 1;
  342. if (LArtFull != '')
  343. {
  344. var regex = /\((\d+)\)/;
  345. var regex_res = regex.exec(LArtFull);
  346. if (regex_res)
  347. LCount = Math.min(parseInt(regex_res[1]), 3);
  348. }
  349. LCountEl.value = LCount;
  350. var LPriceEl = document.forms.f.price;
  351. addEvent(LPriceEl, "change", PriceTrimNewLotForm);
  352. addEvent(LPriceEl, "keyup", PriceTrimNewLotForm);
  353. addEvent(LPriceEl, "paste", PriceTrimNewLotForm);
  354. LoadPrice();
  355.  
  356. LNewDiv = document.createElement('b');
  357. LNewDiv.innerHTML = '<input type="button" style="width:80;" id="id_save_price" value="Сохранить">';
  358. LPriceEl.parentNode.insertBefore(LNewDiv, LPriceEl.nextSibling);
  359. addEvent($('#id_save_price'), "click", SavePrice);
  360.  
  361. LNewDiv = document.createElement('b');
  362. LNewDiv.innerHTML =
  363. '<input type="button" style="width:25;height:25;font-size=10px;padding:0;margin:0;" id="id_decrement_price" value="-">' +
  364. '<input type="button" style="width:25;height:25;font-size=10px;padding:0;margin:0;" id="id_increment_price" value="+">';
  365. LPriceEl.parentNode.insertBefore(LNewDiv, LPriceEl.nextSibling);
  366. addEvent($('#id_decrement_price'), "click", DecrementPrice);
  367. addEvent($('#id_increment_price'), "click", IncrementPrice);
  368. var LDurationEl = document.forms.f.duration;
  369. var LDuration = LNewLotDurationDef;
  370. var LDurationParam = URLAttrValueGet('d', location.href);
  371. if (LDurationParam == '30m')
  372. LDuration = 1;
  373. else
  374. if (LDurationParam == '1h')
  375. LDuration = 2;
  376. else
  377. if (LDurationParam == '3h')
  378. LDuration = 3;
  379. else
  380. if (LDurationParam == '6h')
  381. LDuration = 4;
  382. else
  383. if (LDurationParam == '12h')
  384. LDuration = 5;
  385. else
  386. if (LDurationParam == '1d')
  387. LDuration = 6;
  388. else
  389. if (LDurationParam == '2d')
  390. LDuration = 7;
  391. else
  392. if (LDurationParam == '3d')
  393. LDuration = 8;
  394. for(i = 0; i < LDurationEl.options.length; i++)
  395. {
  396. var LOption = LDurationEl.options[i];
  397. if (LOption.value == LDuration)
  398. {
  399. LDurationEl.selectedIndex = LOption.index;
  400. }
  401. }
  402. var LSubmits = document.querySelectorAll('input[type="submit"]');
  403. if (LSubmits && LSubmits.length > 0)
  404. {
  405. var LSubmit = LSubmits[0];
  406. LNewDiv = document.createElement('b');
  407. LNewDiv.innerHTML = '<input type="checkbox" id="id_one_click" title=""> Выставить лот в один клик';
  408. LSubmit.parentNode.insertBefore(LNewDiv, LSubmit.nextSibling);
  409. var check_one_click = $('#id_one_click');
  410. check_one_click.checked = GM_getValue('one_click', 0) == 1 ? 'checked' : '';
  411. addEvent(check_one_click, "click", function(){setCheck('one_click');});
  412.  
  413. LDiv = document.createElement('div');
  414. LDiv.innerHTML = '<div style="text-decoration:underline;cursor:pointer;font-weight:bold;font-size:10px;" id="hwm_hant_options">Настройки</div>';
  415. LSubmit.parentNode.insertBefore(LDiv, LNewDiv.nextSibling);
  416. $("#hwm_hant_options").addEventListener( "click", open_setting_form , false );
  417. }
  418. }
  419. }
  420.  
  421. //----------------------------------------------------
  422.  
  423. function ProcessMain()
  424. {
  425. if (location.href.indexOf('/inventory.php') > -1)
  426. {
  427. AddNewLotHrefs();
  428. if(!$("#click_div"))
  429. {
  430. var add_click_div = document.createElement('div');
  431. add_click_div.id = "click_div";
  432. add_click_div.style.display = "none";
  433. document.querySelector("body").appendChild(add_click_div);
  434. }
  435. addEvent($("#click_div"), "click", SetTimer_ProcessMain);
  436. }
  437. else
  438. if (location.href.indexOf('/auction_new_lot.php') > -1)
  439. {
  440. InitNewLotForm();
  441. }
  442. }
  443.  
  444. ProcessMain();