Skip to content

Instantly share code, notes, and snippets.

@shnjp
Created January 24, 2010 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shnjp/285161 to your computer and use it in GitHub Desktop.
Save shnjp/285161 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name MouseHunt Horn bot
// @namespace adachinko
// @include http://apps.facebook.com/mousehunt/index.php
// @include http://apps.facebook.com/mousehunt/
// ==/UserScript==
(function() {
function getFirstElementByXPath(xpath, node) {
var node = node || document
var doc = node.ownerDocument ? node.ownerDocument : node
var result = doc.evaluate(xpath, node, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null)
return result.singleNodeValue ? result.singleNodeValue : null
}
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle;
function sound_the_horn() {
var puzzle = getFirstElementByXPath('//form[@class="puzzleform"]');
if(puzzle) {
GM_log('puzzle found. ');
alert('puzzle found');
return;
}
GM_log('check the horn.');
var horn = getFirstElementByXPath('//*[@class="hornarea"]/a')
if(horn) {
// check hidden
var defaultView = horn.ownerDocument.defaultView;
if(!defaultView)
return
var computedStyle = defaultView.getComputedStyle(horn, null);
if(computedStyle.display == 'none') {
GM_log('horn is hidden');
return;
}
GM_log('sound the horn');
var clickEvent = window.document.createEvent("MouseEvent");
clickEvent.initEvent("click", false, true);
horn.dispatchEvent(clickEvent);
}
}
window.addEventListener('load', function() {
sound_the_horn();
setInterval(sound_the_horn, 30 * 1000);
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment