Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created April 9, 2012 14:15
Show Gist options
  • Save jelmervdl/2343731 to your computer and use it in GitHub Desktop.
Save jelmervdl/2343731 to your computer and use it in GitHub Desktop.
Facebook autopoker
// ==UserScript== //
// @name Facebook autopoker
// @version 1.0
// @description Autopoke!
// @include http*://*.facebook.com/*
// @include https://www.facebook.com/
// @match http://*.facebook.com/*
// @match https://*.facebook.com/*
// @exclude http://*.facebook.com/login.php
// @exclude http://*.facebook.com/plugins/*
// ==/UserScript== //
function autoPoke()
{
Array.prototype.forEach.call(
document.querySelectorAll('a[ajaxify].uiIconText'),
function(element) {
// Only click on poke back-links
if (!/poke_inline/.test(element.getAttribute('ajaxify')))
return;
// Don't click on links twice
if (element.hasAttribute('x-poked'))
return;
// Create a mouse event
var event = document.createEvent('MouseEvent');
var options = {
pointerX: 0,
pointerY: 0,
button: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
bubbles: true,
cancelable: true
};
event.initMouseEvent('click', options.bubbles, options.cancelable, document.defaultView,
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
element.dispatchEvent(event);
// Mark link as clicked
element.setAttribute('x-poked', 'yes');
// You know, we have to have some proof that it is working…
console.log('poke!');
});
}
setInterval(function() {
// Only autopoke on the pokes page.
if (document.location.pathname == '/pokes')
autoPoke();
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment