Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @author Odd
- // @description Automatically calculates the phase of Kreludor from the Lunar Temple.
- // @include /http\:\/\/www\.neopets\.com\/\/?shenkuu\/lunar(?!\/results\.phtml)/
- // @name Lunar Temple Auto-Completer
- // @namespace Odd@Clraik
- // @version 1.0
- // ==/UserScript==
- var DelayMax = 5000;
- var DelayMin = 3000;
- (function () {
- function getStoredValue(key, defaultValue) {
- var value = localStorage.getItem(key);
- if (value != null) {
- if (typeof value == "string") {
- try { return JSON.parse(value); }
- catch (ex) { }
- }
- return value;
- }
- return defaultValue;
- }
- function setStoredValue(key, value) {
- if (value == null || value === undefined) localStorage.removeItem(key);
- else {
- if (typeof value != "number" && typeof value != "string") value = JSON.stringify(value);
- localStorage.setItem(key, value);
- }
- }
- if (typeof $ == "undefined") $ = unsafeWindow.$;
- 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>")
- .html())
- .match(/new\x20+swfobject\(\'([^\']+)\'/i);
- var autoStart = (getStoredValue("lunarTemple.autoStart") || false);
- var autoStartCheckbox = $("#lunarTempleAutoCompleterAutoStart")
- .prop("checked", autoStart);
- var completing = (autoStart || getStoredValue("lunarTemple.startOnce", false));
- var options = $("#lunarTempleAutoCompleter > tbody > tr:nth-child(3)");
- var startStop = $("#lunarTempleAutoCompleterStartStop")
- .val(autoStart ? "Stop" : "Start");
- var status = $("#lunarTempleAutoCompleter > tbody > tr:nth-child(2) > td");
- var timeoutID;
- if (completing) options.hide();
- setStoredValue("lunarTemple.startOnce");
- function complete() {
- var form = $(".content form:has(input[name='submitted'][value='false'])")[0];
- if (form) {
- var phase = parseInt(match[1].match(/anglekreludor\=(\d+)/i)[1], 10);
- if ((phase = Math.round((phase > 180) ? ((phase - 157.5) / 22.5) : ((phase + 202.5) / 22.5))) == 17) phase = 1;
- form.phase_choice[(phase - 1)].checked = true;
- 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>");
- timeoutID = setTimeout(function () { form.submit(); }, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin));
- return;
- }
- var a = $(".content a[href*='show=puzzle']")[0];
- if (a) {
- if (!autoStart) setStoredValue("lunarTemple.startOnce", true);
- status.html("Accepting challenge...<br><br>");
- timeoutID = setTimeout(function () { a.click(); }, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin));
- return;
- }
- reset();
- status.html("Done!<br><br>");
- }
- function reset() {
- completing = false;
- if (timeoutID) {
- clearTimeout(timeoutID);
- timeoutID = null;
- }
- options.show();
- startStop.val("Start");
- status.html("");
- }
- //GreaseMonkey compatible change
- document.getElementById(autoStartCheckbox.attr("id"))
- .addEventListener("change", function () {
- setStoredValue("lunarTemple.autoStart", ((autoStart = autoStartCheckbox.prop("checked")) || null));
- });
- //GreaseMonkey compatible click
- document.getElementById(startStop.attr("id"))
- .addEventListener("click", function () {
- if (completing = !completing) {
- options.hide();
- startStop.val("Stop");
- complete();
- }
- else {
- reset();
- }
- });
- if (completing) complete();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement