Neopets : Tyranu Evavu

By w35l3y Last update Nov 27, 2011 — Installed 6,572 times.

There are 3 previous versions of this script.

// ==UserScript==
// @name           Neopets : Tyranu Evavu
// @namespace      http://gm.wesley.eti.br/neopets
// @description    Plays Tyranu Evavu as much as possible.
// @author         w35l3y
// @email          w35l3y@brasnet.org
// @copyright      2011+, w35l3y (http://gm.wesley.eti.br)
// @license        GNU GPL
// @homepage       http://gm.wesley.eti.br
// @version        2.0.0.1
// @language       en
// @include        http://www.neopets.com/games/tyranuevavu.phtml*
// @icon           http://www.gravatar.com/avatar.php?gravatar_id=81269f79d21e612f9f307d16b09ee82b&r=PG&s=92&default=identicon
// @resource       meta http://userscripts.org/scripts/source/28580.meta.js
// @resource       i18n http://pastebin.com/download.php?i=ULrVTsSg
// @require        http://userscripts.org/scripts/source/63808.user.js
// @require        http://userscripts.org/scripts/source/85618.user.js
// @require        http://userscripts.org/scripts/source/87940.user.js
// @require        http://userscripts.org/scripts/source/87942.user.js
// @uso:version    version
// @history        2.0.0.1 Fixed @resource i18n
// ==/UserScript==

/**************************************************************************

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

**************************************************************************/

(function () {	// script scope
	var user = {
		"interval" : JSON.parse(GM_getValue("interval", "[3000, 2000]"))
	},
	actionButton = xpath(".//form[contains(@action, 'tyranuevavu.phtml')]/input[@type = 'submit']")[0],
	currentCard = xpath("string(.//img[contains(@src, 'games/cards/')]/@src[contains(., '_')])");

	function nextAction (f) {
		setTimeout(f, user.interval[0] + Math.floor(Math.random() * user.interval[1]));
	}

	if (!actionButton && /(\d+)_(\w+)/.test(currentCard)) {	// keep playing
		var evavu = 4 * (RegExp.$1 - 1) - 1,
		tyranu = 55,
		suit = {
			"spades" : 0,
			"hearts" : 1,
			"clubs" : 2,
			"diamonds" : 3
		}[RegExp.$2],
		cards = eval(GM_getValue("cards", "[]"))||[];

		cards.push(4 * (RegExp.$1 - 2) + suit);
		cards.sort(function(a, b) {
			if (a == b) return 0;
			return (a < b ? -1 : 1);
		});

		// number of cards lower than or equal to the current card
		for (var ai = 0, cf = 0, at = cards.length ; ai < at && cards[ai] <= evavu ; ++ai) {
			if (3 + cards[ai] >= evavu) { ++cf;	}	// correction factor
		}
		evavu -= ai - 1;
		tyranu -= evavu - 1 + at + cf;

		var answerLink = xpath(".//a[contains(@href, '" + (evavu - tyranu > 0 ? "lower" : "higher") + "') and img[contains(@src, '/prehistoric/')]]")[0];

		GM_setValue("cards", uneval(cards));

		nextAction(function() {
			location.replace(answerLink.href);
		});
	} else {
		GM_setValue("cards", "[]");

		if (actionButton) {	// start playing OR play again
			nextAction(function() {
				actionButton.click();
			});
		}
	}
})();