Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. // ==UserScript==
  2. // @author Odd
  3. // @description Automatically calculates the phase of Kreludor from the Lunar Temple.
  4. // @include /http\:\/\/www\.neopets\.com\/\/?shenkuu\/lunar(?!\/results\.phtml)/
  5. // @name Lunar Temple Auto-Completer
  6. // @namespace Odd@Clraik
  7. // @version 1.0
  8. // ==/UserScript==
  9.  
  10. var DelayMax = 5000;
  11. var DelayMin = 3000;
  12.  
  13. (function () {
  14.  
  15. function getStoredValue(key, defaultValue) {
  16.  
  17. var value = localStorage.getItem(key);
  18.  
  19. if (value != null) {
  20.  
  21. if (typeof value == "string") {
  22.  
  23. try { return JSON.parse(value); }
  24. catch (ex) { }
  25. }
  26.  
  27. return value;
  28. }
  29.  
  30. return defaultValue;
  31. }
  32.  
  33. function setStoredValue(key, value) {
  34.  
  35. if (value == null || value === undefined) localStorage.removeItem(key);
  36. else {
  37.  
  38. if (typeof value != "number" && typeof value != "string") value = JSON.stringify(value);
  39.  
  40. localStorage.setItem(key, value);
  41. }
  42. }
  43.  
  44. if (typeof $ == "undefined") $ = unsafeWindow.$;
  45.  
  46. var match = ($(".content script:contains(SWFObject)").before("<table id=\"lunarTempleAutoCompleter\" style=\"margin: 0 auto; text-align: center; width: 450px;\"><tr><td><br><b>-Lunar Temple Auto-Completer-</b><br><br></td></tr><tr><td></td></tr><tr><td><table cellpadding=\"0\" cellspacing=\"0\" style=\"margin: 0 auto;\"><tr><td><b>Auto-start:</b></td><td style=\"padding-left: 16px;\"><input id=\"lunarTempleAutoCompleterAutoStart\" style=\"margin: 0;\" type=\"checkbox\"></td></tr></table><br><br></td></tr><tr><td><input id=\"lunarTempleAutoCompleterStartStop\" type=\"button\"><br><br><br><br></td></tr></table>")
  47. .html())
  48. .match(/new\x20+swfobject\(\'([^\']+)\'/i);
  49.  
  50. var autoStart = (getStoredValue("lunarTemple.autoStart") || false);
  51. var autoStartCheckbox = $("#lunarTempleAutoCompleterAutoStart")
  52. .prop("checked", autoStart);
  53. var completing = (autoStart || getStoredValue("lunarTemple.startOnce", false));
  54. var options = $("#lunarTempleAutoCompleter > tbody > tr:nth-child(3)");
  55. var startStop = $("#lunarTempleAutoCompleterStartStop")
  56. .val(autoStart ? "Stop" : "Start");
  57. var status = $("#lunarTempleAutoCompleter > tbody > tr:nth-child(2) > td");
  58. var timeoutID;
  59.  
  60. if (completing) options.hide();
  61.  
  62. setStoredValue("lunarTemple.startOnce");
  63.  
  64. function complete() {
  65.  
  66. var form = $(".content form:has(input[name='submitted'][value='false'])")[0];
  67.  
  68. if (form) {
  69.  
  70. var phase = parseInt(match[1].match(/anglekreludor\=(\d+)/i)[1], 10);
  71.  
  72. if ((phase = Math.round((phase > 180) ? ((phase - 157.5) / 22.5) : ((phase + 202.5) / 22.5))) == 17) phase = 1;
  73.  
  74. form.phase_choice[(phase - 1)].checked = true;
  75.  
  76. status.html("Selecting<br><br><img src=\"http://images.neopets.com/shenkuu/lunar/phases/" + (phase - 1) + ".gif\" style=\"height: 60px; margin-bottom: 4px; width: 60px;\"><br><sub>(Phase " + phase + ")</sub><br><br>");
  77.  
  78. timeoutID = setTimeout(function () { form.submit(); }, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin));
  79.  
  80. return;
  81. }
  82.  
  83. var a = $(".content a[href*='show=puzzle']")[0];
  84.  
  85. if (a) {
  86.  
  87. if (!autoStart) setStoredValue("lunarTemple.startOnce", true);
  88.  
  89. status.html("Accepting challenge...<br><br>");
  90.  
  91. timeoutID = setTimeout(function () { a.click(); }, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin));
  92.  
  93. return;
  94. }
  95.  
  96. reset();
  97.  
  98. status.html("Done!<br><br>");
  99. }
  100.  
  101. function reset() {
  102.  
  103. completing = false;
  104.  
  105. if (timeoutID) {
  106.  
  107. clearTimeout(timeoutID);
  108.  
  109. timeoutID = null;
  110. }
  111.  
  112. options.show();
  113.  
  114. startStop.val("Start");
  115.  
  116. status.html("");
  117. }
  118.  
  119. //GreaseMonkey compatible change
  120. document.getElementById(autoStartCheckbox.attr("id"))
  121. .addEventListener("change", function () {
  122.  
  123. setStoredValue("lunarTemple.autoStart", ((autoStart = autoStartCheckbox.prop("checked")) || null));
  124. });
  125.  
  126. //GreaseMonkey compatible click
  127. document.getElementById(startStop.attr("id"))
  128. .addEventListener("click", function () {
  129.  
  130. if (completing = !completing) {
  131.  
  132. options.hide();
  133.  
  134. startStop.val("Stop");
  135.  
  136. complete();
  137. }
  138. else {
  139.  
  140. reset();
  141. }
  142. });
  143.  
  144. if (completing) complete();
  145. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement