Created
October 26, 2010 10:21
-
-
Save aerith/646655 to your computer and use it in GitHub Desktop.
JSDeferred 使って書き直さないとちゃんと動かないんじゃないかな?
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 FaceBook Auto Poke | |
// @namespace ns.aerith.sc | |
// @include http://www.facebook.com/* | |
// ==/UserScript== | |
(function () { | |
var target_id = 'pagelet_netego_pokes'; | |
var container = document.getElementById(target_id); | |
function onPokeBackNodeInserted (event) { | |
var element = event.target; | |
var links = element.getElementsByTagName('a'); | |
for (var i= 0; i < links.length; i++) { | |
var link = links[i] | |
if (link.getAttribute('rel') == 'async-post' && link.className.length == 0) { | |
simulateClicking(link); | |
} | |
} | |
} | |
function onPokeDialogNodeInserted (event) { | |
var element = event.target; | |
if ((element.className || '').match(/\bgeneric\_dialog\b/)) { | |
element.addEventListener('DOMNodeInserted', onPokeButtonNodeInserted, false); | |
} | |
} | |
function onPokeButtonNodeInserted (event) { | |
var element = event.target; | |
var buttons = element.getElementsByTagName('input'); | |
for (var i= 0; i < buttons.length; i++) { | |
var button = buttons[i]; | |
if (button.type == 'button') { | |
simulateClicking(button); | |
break; | |
} | |
} | |
} | |
function simulateClicking(element) { | |
var event = document.createEvent("MouseEvents"); | |
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
element.dispatchEvent(event); | |
} | |
if (container != null) { | |
window.addEventListener('DOMNodeInserted', onPokeDialogNodeInserted, false); | |
container.addEventListener('DOMNodeInserted', onPokeBackNodeInserted, false); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment