Last active
December 17, 2015 01:08
-
-
Save feildmaster/5525755 to your computer and use it in GitHub Desktop.
Script for candies.aniwey.net.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Candy script | |
| // @namespace http://feildmaster.com | |
| // @include http://candies.aniwey.net/index.php?pass=* | |
| // @version 1.1a | |
| // ==/UserScript== | |
| var config = { | |
| quest: { | |
| repeat: true, // true/false : auto repeats quest | |
| }, | |
| save: { | |
| auto: true, // true/false : auto saves | |
| interval: 5 // number in minutes | |
| }, | |
| }; | |
| /* *\ | |
| |* End of Configuration *| | |
| \* */ | |
| function auto_quest() { | |
| if (!quest.weAreQuestingRightNow) { // Not questing? | |
| if (quest.tiredTime == 0 && quest.tiredFound == 0) { // Not tired are we? | |
| quest.begin(true); // Begin the current quest! | |
| } | |
| } | |
| } | |
| function auto_save() { | |
| var p_alert = window.alert; | |
| window.alert = function(message) {set_notice(message);}; | |
| save(); | |
| $(document).ajaxComplete(function(event, xml, options) { | |
| if (options.url == "scripts/save.php") { | |
| window.alert = p_alert; | |
| } | |
| }); | |
| } | |
| function run_save() { | |
| if (config.save.auto) { | |
| auto_save(); | |
| } | |
| setTimeout(run_save, config.save.interval * 60000); | |
| } | |
| function run_quest() { | |
| if (config.quest.repeat) { | |
| auto_quest(); | |
| } | |
| if (quest.tiredTime != 0) { | |
| var timeout = quest.tiredTime * 1000; | |
| if (objects.list.pinkRing.have) { | |
| timeout /= 2; | |
| } | |
| setTimeout(run_quest, timeout * 1000); // Wait at least "tired" seconds | |
| } else { | |
| setTimeout(run_quest, 1000); | |
| } | |
| } | |
| function set_notice(message) { | |
| $("div#notice").text(message); | |
| } | |
| function get_hp() { | |
| if (quest.weAreQuestingRightNow) { | |
| var index = quest.getCharacterIndex(); | |
| return quest.things[index].hp + "/" + quest.things[index].max_hp; | |
| } else { | |
| var maxHP = quest.getCharacterMaxHp(); | |
| return maxHP + "/" + maxHP; | |
| } | |
| } | |
| function quest_status() { | |
| if (quest.weAreQuestingRightNow) { | |
| return land.list[quest.currentLandIndex].name; | |
| } else if (quest.tiredTime > 0) { | |
| return "Waiting " + quest.tiredTime; | |
| } else { | |
| return "Nothing" | |
| } | |
| } | |
| function get_speed() { | |
| switch (quest.getSpeed()) { | |
| case 500: | |
| default: return "normal"; | |
| case 250: return "fast"; | |
| case 125: return "fastest"; | |
| } | |
| } | |
| function update_counts() { | |
| var c = candies.nbrOwned; | |
| var l = lollipops.nbrOwned; | |
| var b = chocolateBars.nbrOwned; | |
| $("div#counts").html( | |
| "Candy: " + addCommas(c) + " Lollipops: " + addCommas(l) + " Chocolate Bars: " + addCommas(b) + "<br />"+ | |
| "--Quest ("+quest_status()+")--<br />"+ | |
| "HP: " + get_hp() + "<br />"+ | |
| "Speed: " + get_speed()); | |
| setTimeout(update_counts, 500); | |
| } | |
| var elements = { | |
| notice: document.createElement("div"), | |
| info: document.createElement("div"), | |
| counts: document.createElement("div"), | |
| style: document.createElement('style'), | |
| }; | |
| function addCommas(nStr) { | |
| nStr += ''; | |
| x = nStr.split('.'); | |
| x1 = x[0]; | |
| x2 = x.length > 1 ? '.' + x[1] : ''; | |
| var rgx = /(\d+)(\d{3})/; | |
| while (rgx.test(x1)) { | |
| x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
| } | |
| return x1 + x2; | |
| } | |
| elements.style.type = 'text/css'; | |
| elements.style.innerHTML = 'div#info {clear:both;}'; | |
| document.getElementsByTagName('head')[0].appendChild(elements.style); | |
| elements.info.id = "info"; | |
| elements.notice.id = "notice"; | |
| elements.notice.style.cssFloat = "right"; | |
| elements.counts.id = "counts"; | |
| elements.info.appendChild(elements.counts); | |
| elements.info.appendChild(elements.notice); | |
| $('body').children().last().prepend(elements.info); | |
| update_counts(); | |
| setTimeout(run_save, config.save.interval * 60000); | |
| setTimeout(run_quest, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment