Created
January 24, 2010 11:35
-
-
Save shnjp/285161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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