hwm_work_find

Поиск и установка на работу с любой страницы игры

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

  1. //
  2. // ==UserScript==
  3. // @name hwm_work_find
  4. // @author Pahan https://gf.qytechs.cn/uk/users/18377-pahan
  5. // @namespace hwm_pahan
  6. // @description Поиск и установка на работу с любой страницы игры
  7. // @homepage https://gf.qytechs.cn/uk/scripts/13911-hwm-work-find
  8. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  9. // @version 1.51
  10. // @encoding utf-8
  11. // @include http://www.heroeswm.ru/*
  12. // @include http://qrator.heroeswm.ru/*
  13. // @include http://178.248.235.15/*
  14. // @include http://www.lordswm.com/*
  15. // @exclude */rightcol.php*
  16. // @exclude */ch_box.php*
  17. // @exclude */chat*
  18. // @exclude */ticker.html*
  19. // @exclude */frames*
  20. // @exclude */brd.php*
  21. // @grant GM_deleteValue
  22. // @grant GM_getValue
  23. // @grant GM_listValues
  24. // @grant GM_setValue
  25. // @grant GM_addStyle
  26. // @grant GM_log
  27. // @grant GM_openInTab
  28. // ==/UserScript==
  29.  
  30. var version = '1.51';
  31. var str_url = 'https://gf.qytechs.cn/uk/scripts/13911-hwm-work-find';
  32. var str_script_name = 'Поиск и установка ГР';
  33. var str_url_aut = '/sms-create.php?mailto=Pahan&subject=Скрипт: '+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. // ---------------------------------
  104.  
  105. WorkResultFound = false;
  106.  
  107. function close_find_work_info()
  108. {
  109. bg = $('#bgOverlayFindWork') ;
  110. bgc = $('#bgCenterFindWork') ;
  111. if( bg ) {
  112. bg.style.display = bgc.style.display = 'none' ;
  113. }
  114. }
  115.  
  116. function ShowFindWorkHTML(AFindWorkHTML, AIsResult)
  117. {
  118. WorkResultFound = AIsResult;
  119. bg = $('#bgOverlayFindWork') ;
  120. bgc = $('#bgCenterFindWork') ;
  121. if( !bg ) {
  122. bg = document.createElement('div') ;
  123. bg.id = 'bgOverlayFindWork' ;
  124. document.body.appendChild( bg );
  125. bg.style.position = 'absolute' ;
  126. bg.style.left = '0';
  127. bg.style.width = '100%';
  128. bg.style.height = '100%';
  129. bg.style.background = "#000000";
  130. bg.style.opacity = "0.5";
  131. bg.addEventListener( "click", close_find_work_info , false );
  132.  
  133. bgc = document.createElement('div') ;
  134. bgc.id = 'bgCenterFindWork' ;
  135. document.body.appendChild( bgc );
  136. bgc.style.position = 'absolute' ;
  137. bgc.style.width = '600px';
  138. bgc.style.background = "#F6F3EA";
  139. bgc.style.left = ( ( document.body.offsetWidth - 600 ) / 2 ) + 'px' ;
  140. bgc.style.zIndex = "1105";
  141. }
  142. bgc.innerHTML =
  143. '<div style="border:1px solid #abc;padding:5px;margin:2px;">' +
  144. ' <div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_closeFindWork" title="Закрыть">x</div>' +
  145. ' <center>' +
  146. ' <table>' +
  147. ' <tr>' +
  148. ' <td><b>'+str_script_name+' <font style="color:#0070FF;">'+version+'</font></b><hr/></td>' +
  149. ' </tr>' +
  150. ' <tr>' +
  151. ' <td>' + AFindWorkHTML + '</td>' +
  152. ' </tr>' +
  153. ' <tr><td><hr/></td></tr>' +
  154. ' <tr>' +
  155. ' <td style="font-weight:bold;font-size:10px;" >' +
  156. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url+'">Проверить обновление скрипта.</a>' +
  157. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url_aut+'">Сообщить автору о найденной ошибке.</a>' +
  158. ' </td>' +
  159. ' </tr>' +
  160. ' <tr>' +
  161. ' <td style="font-weight:bold;font-size:10px;" >' +
  162. ' Автор: <a style="font-weight:bold;font-size:10px;" href="http://www.heroeswm.ru/pl_info.php?id=30547">Pahan.</a>' +
  163. ' </td>' +
  164. ' </tr>' +
  165. ' </table>' + '',
  166. ' </center>' +
  167. '</div>';
  168.  
  169. $("#bt_closeFindWork").addEventListener( "click", close_find_work_info , false );
  170. bg.style.top = (-document.body.scrollTop)+'px';
  171. bgc.style.top = ( document.body.scrollTop + 100 ) + 'px';
  172. bg.style.display = bgc.style.display = 'block' ;
  173. }
  174.  
  175. function GetObjectInfo(AObjHTML)
  176. {
  177. var LFirst = AObjHTML.indexOf('Тип:');
  178. var LEnd = AObjHTML.indexOf('Окончание смены');
  179. var LLast = AObjHTML.indexOf('</td>', LEnd);
  180. var LInfo = AObjHTML.substr(LFirst, LLast - LFirst);
  181. var re = /Свободных мест: <b>\d+<\/b>/gim;
  182. LInfo += (res = re.exec(AObjHTML)) ? res[0] : '';
  183.  
  184. return LInfo;
  185. }
  186.  
  187. function ObjectProcess(AObjHTML)
  188. {
  189. AObjHTML = AObjHTML.replace(/[\n\r]/g, ' ').replace(/\s{2,}/g, ' ');
  190. var re = /Вы уже устроены\./gim;
  191. var re2 = /Прошло меньше часа с последнего устройства на работу\. Ждите\./gim;
  192. var res;
  193. if (((res = re.exec(AObjHTML)) != null) || (res = re2.exec(AObjHTML)) != null)
  194. ShowFindWorkHTML(res[0], true);
  195. else
  196. {
  197. re = /Свободных мест\: <b>0<\/b>/gim;
  198. if ((res = re.exec(AObjHTML)) != null)
  199. {}
  200. else
  201. {
  202. // re = /<form[^>]*name="working"[^>]*>.*<\/form>/gim;
  203. re = /<form[^>]*name=working[^>]*>.*<\/form>/gim;
  204. if ((res = re.exec(AObjHTML)) != null)
  205. {
  206. ShowFindWorkHTML(GetObjectInfo(AObjHTML) + res[0], true);
  207. }
  208. }
  209. }
  210. }
  211.  
  212. function FindWorkObject(APlaceIndex, AObjIndex, APlaceHTML)
  213. {
  214. // href="object-info.php?id=163">»»»</a>
  215. var re = /<[^>]*href='([^']*)'[^>]*>&raquo;&raquo;&raquo;<\/a>/gim;
  216. var res;
  217. var LLink;
  218. var LFindCount = 0;
  219. while ((res = re.exec(APlaceHTML)) != null)
  220. {
  221. LLink = res[1];
  222. if (LFindCount == AObjIndex)
  223. {
  224. Ajax('GET', LLink, null,
  225. function(AObjHTML)
  226. {
  227. ObjectProcess(AObjHTML);
  228. if (!WorkResultFound)
  229. FindWorkObject(APlaceIndex, AObjIndex + 1, APlaceHTML);
  230. }
  231. );
  232. }
  233. LFindCount++;
  234. }
  235.  
  236. // $("#find_work").innerHTML = $("#find_work").innerHTML + '<br>' +
  237. // 'AObjIndex: ' + AObjIndex + ', LFindCount: ' + LFindCount;
  238. if (!WorkResultFound && (AObjIndex >= LFindCount))
  239. FindWorkProcess(APlaceIndex + 1);
  240. }
  241.  
  242. function FindWorkProcess(APlaceIndex)
  243. {
  244. var works = ['sh', 'fc', 'mn'];
  245. var names = ['Производства', 'Обработка', 'Добыча'];
  246.  
  247. if (APlaceIndex >= works.length)
  248. {
  249. ShowFindWorkHTML('Поиск работы завершен.<br>' +
  250. 'Все места заняты или недостаточно золота на объектах.<br>' +
  251. 'Смените локацию, или попробуйте позже.', true);
  252. return;
  253. }
  254.  
  255. ShowFindWorkHTML('Сканирование ' + names[APlaceIndex] + '...', false);
  256. Ajax('GET', '/map.php?st=' + works[APlaceIndex], null,
  257. function(AHTML)
  258. {
  259. FindWorkObject(APlaceIndex, 0, AHTML);
  260. }
  261. );
  262. }
  263.  
  264. function AddWorkFindHref()
  265. {
  266. var LLinks = document.querySelectorAll('a[href^="map.php"]');
  267. var LLink;
  268. if (LLinks)
  269. {
  270. for(i = 0; i < LLinks.length; i++)
  271. {
  272. LLink = LLinks[i];
  273. if (LLink.innerHTML == '<b>Карта</b>')
  274. {
  275. LNewHref = document.createElement('a');
  276. LNewHref.href = '#';
  277. LNewHref.style = "text-decoration: none;color: #f5c137;"
  278. LNewHref.innerHTML = '<b>ГР</b>';
  279. LNewHref.title = 'Найти место работы';
  280. LNewHref.id = 'find_work';
  281. LLink.parentNode.appendChild(LNewHref);
  282. addEvent($("#find_work"), "click",
  283. function()
  284. {
  285. WorkResultFound = false;
  286. FindWorkProcess(0);
  287. }
  288. );
  289. }
  290. }
  291. }
  292. }
  293.  
  294. function ProcessMain()
  295. {
  296. AddWorkFindHref();
  297. }
  298.  
  299. ProcessMain();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址