Neopets : Daily Puzzle

By w35l3y Last update Oct 10, 2008 — Installed 1,686 times. Daily Installs: 2, 2, 4, 3, 1, 1, 3, 2, 3, 3, 1, 2, 4, 4, 8, 0, 5, 2, 4, 2, 1, 1, 7, 2, 3, 0, 3, 0, 1, 3, 0, 4

There are 7 previous versions of this script.

// ==UserScript==
// @name           Neopets : Daily Puzzle
// @namespace      http://gm.wesley.eti.br/neopets
// @description    Selects the correct option to Daily Puzzle
// @include        http://www.neopets.com/petcentral.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
// @require        http://gm.wesley.eti.br/neopets/neopets_default.js
// @author         w35l3y
// @email          w35l3y@brasnet.org
// @version        1.2.5
// @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/28365.user.js',
	'name':'Neopets : Daily Puzzle',
	'namespace':'http://gm.wesley.eti.br/neopets',
	'version':'1.2.5'
});

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

	var script = {
		language:Neopets.Language || "en"
	};

	resourceText("http://gm.wesley.eti.br/neopets/DailyPuzzle/getAnswer.php?type=json&r="+Math.random(),function(r)
	{
		r = eval(r.responseText).response;
		if (r.updated || confirm("The answer seems not to be updated.\nContinue anyway ?"))
		{
			translateText(trim(r.answer).toLowerCase(),r.language,script.language,function(e)
			{
				var nextAction;

				var opts = xpath("//form[contains(@action,'petcentral.phtml')]/select[@name = 'trivia_response']/option[position()>1]");
				for ( var i = 0 , t = opts.length ; i < t ; ++i )
				{
					var opt = opts[i];
					if (opt.textContent.toLowerCase() == e.toLowerCase() || opt.textContent.toLowerCase() == trim(r.answer).toLowerCase())
					{
						opt.selected = true;

						nextAction = function()
						{
							if (typeof opt.parentNode.form.submit == 'function')
								opt.parentNode.form.submit();
							else
								opt.parentNode.form.submit.click();
						};

						break;
					}
				}

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