Neopets : Tyranu Evavu

By w35l3y Last update Sep 29, 2008 — Installed 2,541 times. Daily Installs: 2, 6, 8, 5, 9, 7, 1, 11, 5, 3, 1, 5, 6, 6, 3, 8, 1, 2, 3, 4, 5, 4, 5, 5, 2, 2, 0, 4, 13, 3, 7, 2

There are 1 previous version of this script.

// ==UserScript==
// @name           Neopets : Tyranu Evavu
// @namespace      http://gm.wesley.eti.br/neopets
// @description    Plays Tyranu Evavu as much as possible.
// @include        http://www.neopets.com/games/tyranuevavu.phtml*
// @require        http://www.wesley.eti.br/includes/js/php.js
// @require        http://www.wesley.eti.br/includes/js/php2js.js
// @require        http://gm.wesley.eti.br/gm_default.js
// @author         w35l3y
// @email          w35l3y@brasnet.org
// @version        1.0.1
// @copyright      w35l3y 2008
// @license        GNU GPL
// @homepage       http://www.wesley.eti.br
// ==/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/>.

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

checkForUpdate({
	'file':'http://userscripts.org/scripts/source/28580.user.js',
	'name':'Neopets : Tyranu Evavu',
	'namespace':'http://gm.wesley.eti.br/neopets',
	'version':'1.0.1'
});

(function(){	// script scope
	var user = {
		interval:GM_getValue('interval',	'3000-4000').split('-').array_map(parseInt,array_fill(0,2,10)),
		close:GM_getValue('close',		true)
	};

	var nextAction;
	var actionButton = document.evaluate('//form[contains(@action,"tyranuevavu.phtml")]/input[@type="submit"]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
	var currentCard = document.evaluate('//img[contains(@src,"games/cards/")]/@src',document,null,XPathResult.STRING_TYPE,null).stringValue.match(/(\d+)_(\w+)\.gif$/);
	if (!actionButton && currentCard)
	{	// keep playing
		var naipes = "spadeheartclubsdiamo"; // the first 5 caracters of each suit

		var cards = GM_getValue("cards","").split(",");
		if (cards[0] == "") cards.shift();
		cards.push(4*(currentCard[1]-2)+(naipes.indexOf(currentCard[2].substr(0,5))/5));
		cards.sort(function(a,b)
		{
			if ( a == b ) return 0;
			return ( parseInt(a) < parseInt(b) ? -1 : 1 );
		});

		var evavu = 4*(currentCard[1]-1)-1;

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

		GM_setValue("cards",cards.join(","));

		var answerLink = document.evaluate('//a[contains(@href,"'+( evavu-tyranu > 0 ? "lower" : "higher" )+'")]/img[contains(@src,"/prehistoric/")]/..',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);

		nextAction = function(){location.replace(answerLink.href);};
	}
	else
	{
		GM_setValue("cards","");
		if (actionButton)	// start playing OR play again
		{
			nextAction = function(){actionButton.click();};
		}
		else if (user.close)
		{
			window.close();
		}
	}

	if (nextAction)
	{
		setTimeout(nextAction,randomValue(user.interval));
	}
})();