hwmangryworker

помощник в устройстве на работу, скрипт для ГВД

当前为 2015-03-23 提交的版本,查看 最新版本

  1. // (c) 2015, Ded Moroz
  2. //
  3. // ==UserScript==
  4. // @name hwmangryworker
  5. // @namespace ded_moroz
  6. // @description помощник в устройстве на работу, скрипт для ГВД
  7. // @version 1.0.1
  8. // @homepage https://greasyfork.org/users/7571-ded-moroz
  9. // @include http://www.heroeswm.ru/object-info.php*
  10. // @include http://www.heroeswm.ru/object_do.php*
  11. // @include http://www.lordswm.com/object-info.php*
  12. // @include http://www.lordswm.com/object_do.php*
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_deleteValue
  16. // ==/UserScript==
  17.  
  18. if (typeof GM_getValue != 'function')
  19. {
  20. this.GM_getValue = function (key, def) {return localStorage[key] || def;};
  21. this.GM_setValue = function (key, value) {return localStorage[key] = value;};
  22. this.GM_deleteValue = function (key) {return delete localStorage[key];};
  23. }
  24.  
  25. var eng = location.hostname.contains('lordswm') ? true : false;
  26.  
  27. var coop = '<center style="font-size:10px;">&#169; <a href="mailto:ded_moroz@mail.com" style="font-size:10px;" target="_top">Ded Moroz</a> <a href="https://greasyfork.org/users/7571-ded-moroz" style="font-size:10px;">hwm angry worker</a> v. ' + GM_info.script.version + '</center>';
  28.  
  29. /* get player's id */
  30. var player_id = '';
  31. links = document.getElementsByTagName('a');
  32. for (i = 0; i < links.length; i++)
  33. {
  34. if (links[i].getAttribute('href').contains('pl_hunter_stat'))
  35. {
  36. player_id = links[i].getAttribute('href').split('=')[1];
  37. break;
  38. }
  39. }
  40.  
  41. var div = document.createElement('div');
  42. div.innerHTML = '<br>' + coop;
  43. links[links.length - 1].parentNode.appendChild(div);
  44.  
  45. var GM_ARGS = 'hwm_angry_worker_args' + player_id;
  46.  
  47. if (eng)
  48. {
  49. var pass_msg1 = 'gold'; // 'Not enough gold in facility'
  50. var pass_msg2 = 'No vacancies'; // 'No vacancies'
  51. var fail_msg1 = 'You'; // 'You have successfully enrolled' && 'You are already employed'
  52. var fail_msg2 = 'Invalid code'; // 'Invalid code. Please try again'
  53. }
  54. else
  55. {
  56. var pass_msg1 = 'недостаточно золота';
  57. var pass_msg2 = 'Нет рабочих мест';
  58. var fail_msg1 = 'устроены';
  59. var fail_msg2 = 'неправильный код';
  60. }
  61.  
  62. if (location.toString().contains('object_do'))
  63. {
  64. // get the result string
  65. msg = document.getElementsByTagName('font');
  66. msg = msg[msg.length - 1];
  67. if (msg.innerHTML.contains(pass_msg1) || msg.innerHTML.contains(pass_msg2))
  68. {
  69. // save url with captcha to use later
  70. GM_setValue(GM_ARGS, location.search);
  71. }
  72. else if (msg.innerHTML.contains(fail_msg1) || msg.innerHTML.contains(fail_msg2))
  73. {
  74. // url is no longer valid
  75. GM_deleteValue(GM_ARGS);
  76. }
  77. }
  78. else if (location.toString().contains('object-info'))
  79. {
  80. args = GM_getValue(GM_ARGS);
  81. if (args)
  82. {
  83. code_id = '';
  84.  
  85. // get new code_id
  86. flash = document.getElementsByTagName('embed');
  87. for (i = 0; i < flash.length; i++)
  88. {
  89. if (flash[i].getAttribute('src').contains('workcode'))
  90. {
  91. code_id = flash[i].getAttribute('FlashVars').split('|')[2];
  92. break;
  93. }
  94. }
  95.  
  96. // quit if cant work here
  97. if (code_id == '') return;
  98.  
  99. arg_pair = args.split('&');
  100. arg = [];
  101.  
  102. // get url arguments from saved url
  103. for (i = 0; i < arg_pair.length; i++)
  104. {
  105. arg[i] = arg_pair[i].split('=');
  106. }
  107. // set new code_id
  108. if (arg[2][0] != 'code_id') return;
  109. arg[2][1] = code_id;
  110.  
  111. // make new url
  112. url = 'http://' + location.hostname + '/object_do.php' + location.search;
  113. for (i = 1; i < arg_pair.length; i++)
  114. {
  115. url += '&' + arg[i][0] + '=' + arg[i][1];
  116. }
  117. // apply for work
  118. location.href = url;
  119. }
  120. }