Autostrife

Automatically strifes on the Overseer project.

目前为 2014-10-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Autostrife
  3. // @namespace http://gigapause.com/
  4. // @version 0.7
  5. // @description Automatically strifes on the Overseer project.
  6. // @author capableResistor
  7. // @grant none
  8. // @match http://*.theoverseerproject.com/striferesolve.php
  9. // @match http://*.theoverseerproject.com/strifebegin.php
  10. // @match http://*.theoverseerproject.com/strife.php
  11. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
  12. // ==/UserScript==
  13.  
  14. function strife(){
  15. if($('#aspect').length){
  16. createInput();
  17. var healthcontainer = $('.pined');
  18. var encountercontainer = $('.c3');
  19. var health = healthcontainer.html();
  20. var encounters = encountercontainer.html();
  21. health = health.replace( /^\D+/g, '');
  22. health = health.replace('%','');
  23. encounters = encounters.replace( /^\D+/g, '');
  24. document.title = "H: " + Number(health) + "%" + " E: " + Number(encounters) + ". Overseer";
  25. if (getCookie('autostrife') === "") {
  26. console.log("====> Autostrife cookie not set. Not autostrifing.");
  27. } else if (getCookie('autostrife') == "doStrife" || getCookie('autostrife') == "doGrind") {
  28. if(Number(health) < 20 && getCookie('autostrife') == "doStrife") {
  29. //abscond();
  30. console.log("====> Too dangerous to autostrife (Health below 20%). Manual intervention required.");
  31. } else {
  32. attack();
  33. }
  34. if (Number(health) < 5 && getCookie('autostrife') == "doGrind") {
  35. console.log("====> Looks like you're in trouble. Get healed above 5% before you attempt grinding and sure you're taking on enemies you're very sure you can defeat easily.");
  36. } else {
  37. attack();
  38. }
  39. } else {
  40. console.log("====> Error: Cookie setting mismatch. Resetting cookie.");
  41. unsetCookie('autostrife');
  42. }
  43. } else if ($('#canner a').length > 0 && $.trim($('#canner a').text()) == "Strife again" && getCookie('autostrife') == "doStrife") {
  44. console.log("====> Strife concluded.");
  45. unsetCookie('autostrife');
  46. } else if ($('#canner a').length > 0 && $.trim($('#canner a').text()) == "Strife again" && getCookie('autostrife') == "doGrind") {
  47. console.log("====> Strife concluded, but grind mode is on.");
  48. window.location.href = 'strife.php';
  49. } else if ($('input[type="submit"][value="Fight these enemies again!"]').length && getCookie('autostrife') == "doGrind") {
  50. console.log("====> On strife init page, and autoGrind is on.");
  51. var encountercontainer2 = $('.c3');
  52. var encounters2 = encountercontainer2.html();
  53. encounters2 = encounters2.replace( /^\D+/g, '');
  54. if (Number(encounters2) <= 0) {
  55. console.log("====> However, there are no encounters left. Grinding is over.");
  56. unsetCookie('autostrife');
  57. } else {
  58. console.log("====> We have " + Number(encounters2) + " enounter(s) to work with.");
  59. initiate();
  60. }
  61. } else {
  62. console.log("====> Nothing to do right now.");
  63. }
  64. }
  65.  
  66. function setCookie(cname, cvalue, exdays){
  67. var d = new Date();
  68. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  69. var expires = "expires="+d.toUTCString();
  70. document.cookie = cname + "=" + cvalue + "; " + expires;
  71. }
  72.  
  73. function unsetCookie(cname){
  74. document.cookie = cname + "=''; expires=-1";
  75. }
  76.  
  77. function getCookie(cname){
  78. var name = cname + "=";
  79. var ca = document.cookie.split(';');
  80. for(var i=0; i<ca.length; i++) {
  81. var c = ca[i];
  82. while (c.charAt(0)==' ') c = c.substring(1);
  83. if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
  84. }
  85. return "";
  86. }
  87.  
  88. function createInput(){
  89. var atbutton = $('input[type="submit"][value="Abscond"]');
  90. atbutton.after($('</br><input type="button" id="autostrife" name="astrife" value="autoStrife();"><input type="button" id="autogrind" name="agrind" value="autoGrind();"><input type="button" id="stop" name="stop" value="stop();">'));
  91. document.getElementById('autostrife').addEventListener("click", autoStrife, false);
  92. document.getElementById('autogrind').addEventListener("click", autoGrind, false);
  93. document.getElementById('stop').addEventListener("click", stop, false);
  94. }
  95.  
  96. function attack(){
  97. var atbutton = $('input[type="submit"][value="Attack"]');
  98. atbutton.trigger("click");
  99. }
  100.  
  101. function abscond(){
  102. var abbutton = $('input[type="submit"][value="Abscond"]');
  103. abbutton.trigger("click");
  104. }
  105.  
  106. function initiate(){
  107. var lastbutton = $('input[type="submit"][value="Fight these enemies again!"]');
  108. lastbutton.trigger("click");
  109. }
  110.  
  111. function autoStrife(){
  112. setCookie('autostrife', 'doStrife', '1');
  113. window.location.href = 'strife.php';
  114. }
  115.  
  116. function autoGrind(){
  117. setCookie('autostrife', 'doGrind', '7');
  118. window.location.href = 'strife.php';
  119. }
  120.  
  121. function stop(){
  122. unsetCookie('autostrife');
  123. }
  124.  
  125. setTimeout( strife(), 3000 );