hwm_tavern_new_game

Создание заявки в таверне в один клик

  1. // ==UserScript==
  2. // @name hwm_tavern_new_game
  3. // @author Pahan https://greasyfork.org/uk/users/18377-pahan
  4. // @namespace hwm_pahan
  5. // @description Создание заявки в таверне в один клик
  6. // @homepage https://greasyfork.org/uk/scripts/13534-hwm-tavern-new-game
  7. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  8. // @version 1.33
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/*
  11. // @include http://*lordswm.com/*
  12. // @include http://178.248.235.15/*
  13. // @exclude */rightcol.php*
  14. // @exclude */ch_box.php*
  15. // @exclude */chat*
  16. // @exclude */ticker.html*
  17. // @exclude */frames*
  18. // @exclude */brd.php*
  19. // @grant GM_deleteValue
  20. // @grant GM_getValue
  21. // @grant GM_listValues
  22. // @grant GM_setValue
  23. // @grant GM_addStyle
  24. // @grant GM_log
  25. // @grant GM_openInTab
  26. // @grant GM_xmlhttpRequest
  27. // ==/UserScript==
  28.  
  29. var version = '1.33';
  30. var str_url = 'https://greasyfork.org/uk/scripts/13534-hwm-tavern-new-game';
  31. var str_script_name = 'Таверна, новая игра';
  32. var str_url_aut = '/sms-create.php?mailto=Pahan&subject=Скрипт: '+str_script_name+' v'+version+'. Найдена ошибка:';
  33. var str_url_sps = '/transfer.php?pahan_sps=' + encodeURIComponent('Подарок. Спасибо за скрипт: '+str_script_name+' v'+version+'.');
  34.  
  35. if (typeof GM_deleteValue != 'function') {
  36. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  37. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  38. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  39.  
  40. this.GM_addStyle=function (key) {
  41. var style = document.createElement('style');
  42. style.textContent = key;
  43. document.querySelector("head").appendChild(style);
  44. }
  45. }
  46. if (typeof GM_listValues != 'function') {
  47. this.GM_listValues=function () {
  48. var values = [];
  49. for (var i=0; i<localStorage.length; i++) {
  50. values.push(localStorage.key(i));
  51. }
  52. return values;
  53. }
  54. }
  55.  
  56. function addEvent(elem, evType, fn) {
  57. // elem["on" + evType] = fn;
  58. if (elem.addEventListener) {
  59. elem.addEventListener(evType, fn, false);
  60. }
  61. else if (elem.attachEvent) {
  62. elem.attachEvent("on" + evType, fn);
  63. }
  64. else {
  65. elem["on" + evType] = fn;
  66. }
  67. }
  68.  
  69. function $(id) { return document.querySelector(id); }
  70.  
  71. function URLAttrValueGet(attr_name, aurl)
  72. {
  73. attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  74. var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
  75. var regex = new RegExp( regexS );
  76. var results = regex.exec( aurl );
  77. if( results == null )
  78. return "";
  79. else
  80. return results[1];
  81. }
  82.  
  83. function Ajax(AMethod, AURL, AParams, ACallBackFunc)
  84. {
  85. var LRequest = new XMLHttpRequest();
  86. LRequest.open(AMethod, AURL, true);
  87. LRequest.overrideMimeType('text/html; charset=windows-1251');
  88. LRequest.send(AParams);
  89. LRequest.onreadystatechange = function()
  90. {
  91. if (LRequest.readyState == 4)
  92. {
  93. ACallBackFunc(LRequest.responseText);
  94. }
  95. };
  96. }
  97.  
  98. function Trim(AText)
  99. {
  100. return AText.replace(/^\s+|\s+$|^(&nbsp;)+|(&nbsp;)+$/g, '');
  101. }
  102.  
  103. function DeleteCRLF(AText)
  104. {
  105. return AText.replace(/[\n\r]/g, ' ').replace(/\s{2,}/g, ' ');
  106. }
  107.  
  108. function SpsProcess()
  109. {
  110. if (location.href.indexOf('/transfer.php') > -1)
  111. {
  112. var LSps = decodeURIComponent(URLAttrValueGet('pahan_sps', location.href));
  113. if (LSps != '')
  114. {
  115. document.forms.f.nick.value = 'Pahan';
  116. document.forms.f.gold.value = '500';
  117. document.forms.f.desc.value = LSps;
  118. }
  119. }
  120. }
  121. SpsProcess();
  122.  
  123. // -----------------------------------------------
  124.  
  125. function close_setting_form() {
  126. bg = $('#bgOverlay_tavern_ng') ;
  127. bgc = $('#bgCenter_tavern_ng') ;
  128. if( bg ) {
  129. bg.style.display = bgc.style.display = 'none' ;
  130. }
  131. }
  132.  
  133. function open_setting_form()
  134. {
  135. bg = $('#bgOverlay_tavern_ng') ;
  136. bgc = $('#bgCenter_tavern_ng') ;
  137. if( !bg ) {
  138. bg = document.createElement('div') ;
  139. bg.id = 'bgOverlay_tavern_ng' ;
  140. document.body.appendChild( bg );
  141. bg.style.position = 'absolute' ;
  142. bg.style.left = '0';
  143. bg.style.width = '100%';
  144. bg.style.height = '100%';
  145. bg.style.background = "#000000";
  146. bg.style.opacity = "0.5";
  147. bg.addEventListener( "click", close_setting_form , false );
  148.  
  149. bgc = document.createElement('div') ;
  150. bgc.id = 'bgCenter_tavern_ng' ;
  151. document.body.appendChild( bgc );
  152. bgc.style.position = 'absolute' ;
  153. bgc.style.width = '600px';
  154. bgc.style.background = "#F6F3EA";
  155. bgc.style.left = ( ( document.body.offsetWidth - 400 ) / 2 ) + 'px' ;
  156. bgc.style.zIndex = "1105";
  157. }
  158. bgc.innerHTML =
  159. '<div style="border:1px solid #abc;padding:5px;margin:2px;">' +
  160. ' <div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_close_tavern_ng" title="Закрыть">x</div>' +
  161. ' <center>' +
  162. ' <table>' +
  163. ' <tr>' +
  164. ' <td><b>'+str_script_name+' <font style="color:#0070FF;">'+version+'</font></b><hr/></td>' +
  165. ' </tr>' +
  166. ' <tr>' +
  167. ' <td><b>Настройки:</b></td>' +
  168. ' </tr>' +
  169. ' <tr>' +
  170. ' </tr>' +
  171. ' <tr>' +
  172. ' <td>Пока пусто</td>' +
  173. ' </tr>' +
  174. ' <tr><td><hr/></td></tr>' +
  175. ' <tr>' +
  176. ' <td style="font-weight:bold;font-size:10px;" >' +
  177. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url+'">Обновить</a> ' +
  178. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url_aut+'">Нашли ошибку?</a> ' +
  179. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url_sps+'">Сказать спасибо</a> ' +
  180. ' </td>' +
  181. ' </tr>' +
  182. ' <tr>' +
  183. ' <td style="font-weight:bold;font-size:10px;" >' +
  184. ' Автор: <a style="font-weight:bold;font-size:10px;" href="http://www.heroeswm.ru/pl_info.php?id=30547">Pahan.</a>' +
  185. ' </td>' +
  186. ' </tr>' +
  187. ' </table>' +
  188. ' </center>' +
  189. '</div>';
  190. $("#bt_close_tavern_ng").addEventListener( "click", close_setting_form , false );
  191. bg.style.top = (-document.body.scrollTop)+'px';
  192. bgc.style.top = ( document.body.scrollTop + 100 ) + 'px';
  193. bg.style.display = bgc.style.display = 'block' ;
  194. }
  195.  
  196. function AddNewGameLink()
  197. {
  198. var Golds = [0, 40, 200, 400, 600, 1000, 2000, 3000,
  199. 4000, 5000, 6000, 7000, 10000, 11000, 12000];
  200. var timeout = GM_getValue('timeout', '30');
  201. var ktype = GM_getValue('ktype', '1');
  202. var gold = GM_getValue('gold', '0');
  203. var Lhref = '/create_card_game.php?timeout=' + timeout + '&ktype=' +
  204. ktype + '&gold=' + gold + '';
  205. var Ltitle =
  206. 'Создать заявку\n' +
  207. 'Время: ' + timeout + '\n' +
  208. 'Тип: ' + (ktype == 1 ? 'Одна колода карт' : 'Бесконечная колода карт') + '\n' +
  209. 'Ставка: ' + Golds[gold];
  210.  
  211. var LLinks = document.querySelectorAll('a[href^="/tavern.php?form=1"]');
  212. if (LLinks && (LLinks.length > 0))
  213. {
  214. var LLink = LLinks[0];
  215. var LNewGameHref = document.createElement('a');
  216. LNewGameHref.href = Lhref;
  217. LNewGameHref.title = Ltitle;
  218. LNewGameHref.innerHTML = '<font color="red"><b>Создать заявку(+)</b></font>';
  219. LLink.parentNode.insertBefore(LNewGameHref, LLink);
  220. var LDiv = document.createElement('div');
  221. LDiv.innerHTML = '<div style="text-decoration:underline;cursor:pointer;font-weight:bold;font-size:10px;" id="hwm_hant_options">Настройки';
  222. LLink.parentNode.insertBefore(LDiv, LLink);
  223. $("#hwm_hant_options").addEventListener( "click", open_setting_form , false );
  224.  
  225. var LBR = document.createElement('br');
  226. LLink.parentNode.insertBefore(LBR, LLink);
  227. }
  228. var LLinks = document.querySelectorAll('a[href="tavern.php"]');
  229. if (LLinks && (LLinks.length > 0))
  230. {
  231. var LLink = LLinks[0];
  232. var LNewHref = document.createElement('a');
  233. LNewHref.href = Lhref;
  234. LNewHref.title = Ltitle;
  235. LNewHref.style = "text-decoration: none;color: #f5c137;"
  236. LNewHref.innerHTML = '<b>+</b>';
  237. LLink.parentNode.appendChild(LNewHref);
  238. }
  239. }
  240.  
  241. function SaveSettings()
  242. {
  243. GM_setValue('timeout', document.forms.create.timeout.options[document.forms.create.timeout.selectedIndex].value);
  244. GM_setValue('ktype', document.forms.create.ktype.options[document.forms.create.ktype.selectedIndex].value);
  245. GM_setValue('gold', document.forms.create.gold.options[document.forms.create.gold.selectedIndex].value);
  246. }
  247.  
  248. function InitOneInput(AInput, AName)
  249. {
  250. var LValue = GM_getValue(AName, '');
  251. for(i = 0; i < AInput.options.length; i++)
  252. {
  253. var LOption = AInput.options[i];
  254. if (LOption.value == LValue)
  255. AInput.selectedIndex = LOption.index;
  256. }
  257. addEvent(AInput, 'change', SaveSettings);
  258. }
  259.  
  260. function InitInputs()
  261. {
  262. InitOneInput(document.forms.create.timeout, 'timeout');
  263. InitOneInput(document.forms.create.ktype, 'ktype');
  264. InitOneInput(document.forms.create.gold, 'gold');
  265. }
  266.  
  267.  
  268. if (URLAttrValueGet('form', location.href) == '1')
  269. InitInputs();
  270. AddNewGameLink();