Neopets : Potato Counter

By w35l3y Last update Nov 10, 2008 — Installed 2,567 times. Daily Installs: 7, 3, 4, 3, 12, 2, 3, 2, 2, 3, 2, 2, 5, 4, 4, 6, 3, 5, 3, 2, 3, 6, 5, 2, 7, 1, 3, 4, 1, 3, 3, 1

There are 2 previous versions of this script.

// ==UserScript==
// @name           Neopets : Potato Counter
// @namespace      http://gm.wesley.eti.br/neopets
// @description    Plays Potato Counter as much as possible
// @include        http://www.neopets.com/medieval/potatocounter.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.1.3
// @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/28364.user.js',
	'name':'Neopets : Potato Counter',
	'namespace':'http://gm.wesley.eti.br/neopets',
	'version':'1.1.3'
});

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

	var nextAction;
	var txtGuess = xpath("//form[contains(@action,'potatocounter.phtml')]/input[@name = 'guess']")[0];
	if (!!txtGuess)
	{	// so guess!
		txtGuess.value = xpath("count(//table/tbody/tr/td/img[contains(@src,'/medieval/potato')])");

		nextAction = function(){txtGuess.form.submit()};
	}
	else
	{
		var btnNew = xpath("//form[contains(@action,'potatocounter.phtml')]/input[@type='submit']")[0];
		if (!!btnNew)
		{	// new game?
			nextAction = function(){btnNew.click()};
		}
		else if (user.close)
		{
			window.close();
		}
	}

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