Neopets : Daily Puzzle

By w35l3y Last update Aug 13, 2011 — Installed 4,066 times.

There are 8 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
// @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.0
// @language       en
// @include        http://www.neopets.com/petcentral.phtml
// @icon           http://www.gravatar.com/avatar.php?gravatar_id=81269f79d21e612f9f307d16b09ee82b&r=PG&s=92&default=identicon
// @resource       meta http://userscripts.org/scripts/source/28365.meta.js
// @resource       i18n http://pastebin.com/download.php?i=1F0jQb5L
// @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
// @require        http://userscripts.org/scripts/source/56489.user.js
// @require        http://userscripts.org/scripts/source/85618.user.js
// @cfu:version    version
// @contributor    jellyneo (http://www.jellyneo.net/?go=dailypuzzle)
// ==/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 interval = eval(GM_getValue("interval",	"[2000, 1000]")),
	language = xpath("string(.//select[@name = 'lang']/option[@selected]/@value)") || "en";
	
	HttpRequest.open({
		"method" : "get",
		"url" : "http://www.jellyneo.net/?go=dailypuzzle",
		"onsuccess" : function (xhr) {
			var answer = xpath("string(id('contentshell')/div/center/div/span/text())", xhr.response.xml);

			Translate.execute(answer, "en", language, function (result) {
				for each (var option in xpath(".//form[contains(@action, 'petcentral.phtml')]/select[@name = 'trivia_response']/option[position() > 1]")) {
					if (option.textContent.toLowerCase() == result.translation.toLowerCase() || option.textContent.toLowerCase() == answer.replace(/^\s+|\s+$/g, "").toLowerCase()) {
						option.selected = true;

						setTimeout(function() {
							option.parentNode.form.submit();
						}, interval[0] + Math.floor(interval[1] * Math.random()));

						break;
					}
				}
			});
		}
	}).send();
})();