// ==UserScript== // @name Neopets - Kiko Pop Auto-Player // @author Odd // @description Automatically pops a balloon and collects your prize from Kiko Pop. // @match *://*.neopets.com/worlds/kiko/kpop/* // @namespace https://www.scriptneo.com/ // @version 1.0.0 // @grant GM.xmlHttpRequest // @grant GM_xmlhttpRequest // @downloadURL https://www.scriptneo.com/scripts/download.php?id=41 // @updateURL https://www.scriptneo.com/scripts/download.php?id=41 // ==/UserScript== var DelayMax = 5000; var DelayMin = 3000; var Tries = 3; (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.$; if (typeof GM_xmlhttpRequest == "undefined") GM_xmlhttpRequest = GM.xmlHttpRequest; $("#pageDesc").after("


-Kiko Pop Auto-Player-

Auto-start:
Difficulty:





"); var autoStart = (getStoredValue("kikoPop.autoStart") || false); var autoStartCheckbox = $("#kikoPopAutoPlayerAutoStart") .prop("checked", autoStart); var difficulty = Math.max(Math.min((parseInt(getStoredValue("kikoPop.difficulty")) || 2), 3), 1); var difficulty1 = $("#kikoPopAutoPlayerDifficulty1") .prop("checked", (difficulty == 1)); var difficulty2 = $("#kikoPopAutoPlayerDifficulty2") .prop("checked", (difficulty == 2)); var difficulty3 = $("#kikoPopAutoPlayerDifficulty3") .prop("checked", (difficulty == 3)); var options = $("#kikoPopAutoPlayer > tbody > tr:nth-child(3)"); var optionsL23 = 'CHVPqeJq1'; var playing = autoStart; var startStop = $("#kikoPopAutoPlayerStartStop") .val(autoStart ? "Stop" : "Start"); var status = $("#kikoPopAutoPlayer > tbody > tr:nth-child(2) > td"); var timeoutID; if (playing) options.hide(); function radio_onChange() { if (difficulty1.prop("checked")) difficulty = 1; else if (difficulty2.prop("checked")) difficulty = 2; else if (difficulty3.prop("checked")) difficulty = 3; setStoredValue("kikoPop.difficulty", ((difficulty == 2) ? null : difficulty)); } function reset() { playing = false; if (timeoutID) { clearTimeout(timeoutID); timeoutID = null; } options.show(); startStop.val("Start"); status.html(""); } function waitAndPopBalloon() { var tries = Tries; function onAbort() { if (playing) { if (tries) { tries--; status.html("Oops! Trying to pop a balloon again (" + ((Tries - tries) + 1) + " of " + Tries + ")...

"); timeoutID = setTimeout(popBalloon, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); return; } reset(); status.html("Oops! We couldn't pop a balloon because our requests were aborted!


"); } } function onError() { if (playing) { if (tries) { tries--; status.html("Oops! Trying to pop a balloon again (" + ((Tries - tries) + 1) + " of " + Tries + ")...

"); timeoutID = setTimeout(popBalloon, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); return; } reset(); status.html("Oops! We couldn't pop a balloon due to an unexpected error!


"); } } function onTimeout() { if (playing) { if (tries) { tries--; status.html("Oops! Trying to pop a balloon again (" + ((Tries - tries) + 1) + " of " + Tries + ")...

"); timeoutID = setTimeout(popBalloon, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); return; } reset(); status.html("Oops! We couldn't pop a balloon because our requests timed out!


"); } } function popBalloon() { GM_xmlhttpRequest({ data: ("difficulty=" + difficulty), headers: { "Content-Type": "application/x-www-form-urlencoded", Referer: location.href }, method: "POST", onabort: onAbort, onerror: onError, onload: function (response) { if (playing) { if (response && response.responseText && (response = JSON.parse(response.responseText))) { startStop.hide(); if (response.success) { if (response.prize) { status.html(("
" + $("#popupPrize").html() + "
") .replace(/]*class\=\"button120\"[^>]*>.*<\/div>\s*/i, "") .replace(/]*id\=\"prizeImage\"[^>]*>\s*<\/div>/i, "
") .replace(/]*id\=\"prizeName\"[^>]*>\s*]*>\s*<\/b>\s*<\/div>/i, "
" + response.prize.name + "
")); } if (prize.avatar) { $("#avatarDisplay").show() .after("

"); startStop.next() .remove(); } return; } status.html("
Whoa, careful there! You're trying to hit a balloon, not take out one of the Kikos swimming in the lake. Maybe you'll have better luck tomorrow?
"); return; } reset(); status.html("Oops! We couldn't pop a balloon due to an unrecognized response!


"); } }, ontimeout: onTimeout, timeout: 30000, url: (location.origin + "/worlds/kiko/kpop/ajax/prize.php") }); } status.html("Popping a balloon...

"); timeoutID = setTimeout(popBalloon, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); } function waitAndSelectDifficulty() { var tries = Tries; function onAbort() { if (playing) { if (tries) { tries--; status.html("Oops! Trying to select a difficulty again (" + ((Tries - tries) + 1) + " of " + Tries + ")...

"); timeoutID = setTimeout(selectDifficulty, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); return; } reset(); status.html("Oops! We couldn't select a difficulty because our requests were aborted!


"); } } function onError() { if (playing) { if (tries) { tries--; status.html("Oops! Trying to select a difficulty again (" + ((Tries - tries) + 1) + " of " + Tries + ")...

"); timeoutID = setTimeout(selectDifficulty, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); return; } reset(); status.html("Oops! We couldn't select a difficulty due to an unexpected error!


"); } } function onTimeout() { if (playing) { if (tries) { tries--; status.html("Oops! Trying to select a difficulty again (" + ((Tries - tries) + 1) + " of " + Tries + ")...

"); timeoutID = setTimeout(selectDifficulty, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); return; } reset(); status.html("Oops! We couldn't select a difficulty because our requests timed out!


"); } } function selectDifficulty() { GM_xmlhttpRequest({ data: ("difficulty=" + difficulty), headers: { "Content-Type": "application/x-www-form-urlencoded", Referer: location.href }, method: "POST", onabort: onAbort, onerror: onError, onload: function (response) { if (playing) waitAndPopBalloon(); }, ontimeout: onTimeout, timeout: 30000, url: (location.origin + "/worlds/kiko/kpop/ajax/difficulty.php") }); } status.html("Selecting difficulty...

"); timeoutID = setTimeout(selectDifficulty, Math.round((Math.random() * (DelayMax - DelayMin)) + DelayMin)); } //GreaseMonkey compatible change document.getElementById(autoStartCheckbox.attr("id")) .addEventListener("change", function () { setStoredValue("kikoPop.autoStart", ((autoStart = autoStartCheckbox.prop("checked")) || null)); }); document.getElementById(difficulty1.attr("id")) .addEventListener("change", radio_onChange); document.getElementById(difficulty2.attr("id")) .addEventListener("change", radio_onChange); document.getElementById(difficulty3.attr("id")) .addEventListener("change", radio_onChange); //GreaseMonkey compatible click document.getElementById(startStop.attr("id")) .addEventListener("click", function () { if (playing = !playing) { options.hide(); startStop.val("Stop"); waitAndSelectDifficulty(); } else { reset(); } }); if (playing) { if (!$("#difficultyForm").length) { startStop.hide(); status.html("You've already played today!
"); return; } waitAndSelectDifficulty(); } })();