By Jack Hsu
Has no other scripts.
// ==UserScript==
// @name facebook poke all
// @namespace facebook
// @include http://facebook.com/home.php*
// @include http://*.facebook.com/home.php*
// ==/UserScript==
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://code.jquery.com/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { unsafeWindow.jQuery.noConflict(); letsJQuery(); }
}
GM_wait();
// All your GM code must be inside this function
function letsJQuery() {
var $j = unsafeWindow.jQuery;
var pokes = $j(".sidebar_item.pokes");
if ( pokes.length > 0 ) {
// Message and button to add to the Pokes sidebar element
var msg = document.createElement("p");
var pokeAllBtn = document.createElement("input");
var pokeSelectedBtn = document.createElement("input");
// Keep track of all pokees
var pokees = [];
var unpoked = {};
var total = 0;
var idRegex = /profile.php\?id=(\d+)/;
$j(".sidebar_item.pokes").children(".sidebar_item_body").children(".ind_poke").each( function(i, a) {
var option = $j(a).children(".poke_option");
var url = $j(option).children("a:first").attr("href");
var userLink = $j(a).children("a");
var pokee = $j(userLink).text();
var pageUrl = $j(userLink).attr("href");
var id = idRegex.exec(pageUrl)[1];
unpoked[id] = { div: a, pokeUrl: url, name: pokee, pageUrl: pageUrl };
++total;
} );
// Set up Buttons
$j(pokeAllBtn).attr("value","Poke All!").attr("type","button").addClass("inputsubmit").css( {
"margin-top": "3px",
padding: "2px 5px 3px"
} ).attr("id","pokeAllButton").click( function () {
pokees = [];
// Disable the button
$j("#pokeAllButton").attr("disabled","disabled");
// Loop through each pokee and poke them!
$j(".sidebar_item.pokes").children(".sidebar_item_body").children(".ind_poke").each( function(i, a) {
var userLink = $j(a).children("a");
var pageUrl = $j(userLink).attr("href");
var id = idRegex.exec(pageUrl)[1];
var user = unpoked[id];
// Add pokee to the array
pokees.push( '<a href="'+user.pageUrl+'">'+user.name+'</a>' );
// We'll send a request for the facebook poke page
$j.ajax( {
type: "GET",
url: user.pokeUrl,
success: function(html) { // Let's parse the response!
var formIdRegex = /name="post_form_id" value="(\w+)"/;
var formId = formIdRegex.exec(html)[1];
// Now we can sent a POST request to actually poke the pokee
$j.ajax({
type: "POST",
url: "poke.php",
data: "post_form_id=" + formId + "&id=" + id + "&confirmed=1&pokeback=1"
});
}
} );
$j(user.div).slideUp().remove();
--total;
} );
$j("#pokeConfirm").slideUp().html("You have just poked the following users.<br/><br/>"+pokees.join(", ")).slideDown();
if ( total === 0 ) {
// Show the close option for Pokes
var closepokeAllBtn = document.createElement("div");
var closeLink = document.createElement("a");
$j(closeLink).attr("href","#").text("close").click( function () {
$j(".sidebar_item.pokes").slideUp();
return false;
} );
$j(closepokeAllBtn).addClass("option").append(closeLink);
$j(".sidebar_item.pokes").children(".sidebar_item_header").append(closepokeAllBtn);
$j("#poke_sidebar_header").text("No one left to poke.");
// Hide poke all
$j("#pokeAll").slideUp();
}
} );
$j(pokeSelectedBtn).attr("value","Poke Selected!").attr("type","button").addClass("inputsubmit").css( {
"margin-top": "3px",
padding: "2px 5px 3px",
"margin-left": "3px"
} ).attr("id","pokeAllButton").click( function () {
var toPoke = $j(".pokeCheckbox:checked");
if ( toPoke.length > 0 ) {
// Keep track of all pokees
var pokees = [];
$j(toPoke).each( function( i, a ) {
var id = $j(a).attr("value");
var user = unpoked[id];
// Add pokee to the array
pokees.push( '<a href="'+user.pageUrl+'">'+user.name+'</a>' );
// We'll send a request for the facebook poke page
$j.ajax( {
type: "GET",
url: user.pokeUrl,
success: function(html) { // Let's parse the response!
var formIdRegex = /name="post_form_id" value="(\w+)"/;
var formId = formIdRegex.exec(html)[1];
// Now we can sent a POST request to actually poke the pokee
$j.ajax({
type: "POST",
url: "poke.php",
data: "post_form_id=" + formId + "&id=" + id + "&confirmed=1&pokeback=1"
});
}
} );
$j(user.div).slideUp().remove();
--total;
} );
$j("#pokeConfirm").slideUp().html("You have just poked the following users.<br/><br/>"+pokees.join(", ")).slideDown();
if ( total === 0 ) {
// Show the close option for Pokes
var closepokeAllBtn = document.createElement("div");
var closeLink = document.createElement("a");
$j(closeLink).attr("href","#").text("close").click( function () {
$j(".sidebar_item.pokes").slideUp();
return false;
} );
$j(closepokeAllBtn).addClass("option").append(closeLink);
$j(".sidebar_item.pokes").children(".sidebar_item_header").append(closepokeAllBtn);
$j("#poke_sidebar_header").text("No one left to poke.");
// Hide poke all
$j("#pokeAll").slideUp();
}
} else {
$j("#pokeErrorMsg").fadeIn(500).fadeTo(2000, 1).fadeOut(500);
}
} );
$j(msg).text("Do you want to poke everyone?").css( {
padding: "0 10px"
} ).append(pokeAllBtn).append(pokeSelectedBtn).attr("id","pokeAll");
// Add checkbox to each pokee
$j(".sidebar_item.pokes").children(".sidebar_item_body").children(".ind_poke").each( function(i, a) {
var option = $j(a).children(".poke_option");
var userLink = $j(a).children("a");
var pokee = $j(userLink).text();
var pageUrl = $j(userLink).attr("href");
var id = idRegex.exec(pageUrl)[1];
var checkBox = document.createElement("div");
$j(checkBox).attr("id",id+"Poke").css( {
float: "right"
} ).html('<input style="vertical-align: middle" value="'+id+'" type="checkbox" id="'+id+'" class="pokeCheckbox" /><label title="Include '+pokee+' in Poke Selected!" style="font-size: 9px; font-weight: normal" for="'+id+'">?</label>');
$j(userLink).css( { float: "left", display: "block", width: "60%" } ).after(checkBox);
$j(option).css( { clear: "both" } );
} );
$j(pokes.children(".sidebar_item_header.clearfix")).after(msg);
var error = document.createElement("div");
$j(error).css( {
position: "absolute",
left: "50%",
top: "100px",
"margin-left": "-190px",
width: "380px",
height: "40px",
"padding-top": "20px",
"background-color": "black",
color: "white",
"font-size": "16px",
"font-weight": "bold",
"text-align": "center",
display: "none",
"z-index": "10000"
} ).attr("id","pokeErrorMsg").text("There are no users selected to be poked!");
$j("body").append(error);
// Show results
var results = document.createElement("p");
$j(results).html( pokees.join(", ") ).css( {
padding: "0 10px",
color: "#666666",
display: "none",
margin: "5px",
"background-color": "#E9E9E9",
border: "1px solid #EEEEEE"
} ).attr("id","pokeConfirm");
$j("#pokeAll").after(results);
}
}
// GUIID: d06f3736-52ad-47eb-8a26-65bc29a06855