Skip to content

Instantly share code, notes, and snippets.

@FiloSottile
Last active November 3, 2022 08:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save FiloSottile/4215248 to your computer and use it in GitHub Desktop.
Save FiloSottile/4215248 to your computer and use it in GitHub Desktop.
Krumiro, a bookmarklet to send a message to all your FB friends.
javascript:(function(){var msg_m_prompt='Insert the message for males. I\'ll replace %name with the recipient name.';var msg_f_prompt='Insert the message for females. I\'ll replace %name with the recipient name.';var throttle_prompt='Insert the pause in milliseconds between a friend and the next.';var exclude_prompt='Insert the list of friends to ignore, comma separated.';var exerror_alert='%s is not in your friends, you might have made a mistake. Do you want to continue?';var time_alert='The script will take %s seconds!';var done='Done!';if(!Array.prototype.indexOf){Array.prototype.indexOf=function(d){if(void 0===this||null===this)throw new TypeError;var c=Object(this),b=c.length>>>0;if(0===b)return-1;var a=0;0<arguments.length&&(a=Number(arguments[1]),a!==a?a=0:0!==a&&(a!==1/0&&a!==-(1/0))&&(a=(0<a||-1)*Math.floor(Math.abs(a))));if(a>=b)return-1;for(a=0<=a?a:Math.max(b-Math.abs(a),0);a<b;a++)if(a in c&&c[a]===d)return a;return-1};}function size(obj){var s=0,key;for(key in obj){if(obj.hasOwnProperty(key))s++;}return s;}function sleep(milliseconds){var start=new Date().getTime();for(var i=0;i<1e7;i++){if((new Date().getTime()-start)>milliseconds){break;}}}function send(msg,to){function serialize(obj){var str=[];for(var p in obj)str.push(p+"="+encodeURIComponent(obj[p]));return str.join("&");}function random(len){var min=Math.pow(10,len-1);var max=Math.pow(10,len);return Math.floor(Math.random()*(max-min+1))+min;}function generatePhstamp(qs,dtsg){var input_len=qs.length;numeric_csrf_value='';for(var ii=0;ii<dtsg.length;ii++){numeric_csrf_value+=dtsg.charCodeAt(ii);}return '1'+numeric_csrf_value+input_len;}var fbid=window.require('Env').user;var d=new Date();var data={"message_batch[0][timestamp_relative]":""+('0'+d.getHours()).slice(-2)+":"+('0'+d.getMinutes()).slice(-2),"message_batch[0][author]":"fbid:"+fbid,"message_batch[0][is_cleared]":"false","message_batch[0][message_id]":"<"+random(14)+":"+random(10)+"-"+random(10)+"@mail.projektitan.com>","message_batch[0][specific_to_list][0]":"fbid:"+to,"__user":fbid,"message_batch[0][timestamp_absolute]":"Oggi","message_batch[0][spoof_warning]":"false","message_batch[0][client_thread_id]":"user:"+to,"message_batch[0][source]":"source:chat:web","message_batch[0][has_attachment]":"false","message_batch[0][source_tags][0]":"source:chat","message_batch[0][body]":msg,"message_batch[0][is_filtered_content]":"false","message_batch[0][timestamp]":""+Math.round(new Date().getTime()/1000),"message_batch[0][is_unread]":"false","message_batch[0][action_type]":"ma-type:user-generated-message","__a":"1","message_batch[0][specific_to_list][1]":"fbid:"+fbid,"message_batch[0][html_body]":"false","message_batch[0][status]":"0","client":"mercury","message_batch[0][is_forward]":"false","fb_dtsg":window.require('Env').fb_dtsg};var req=serialize(data);req+="&phstamp="+generatePhstamp(req,data.fb_dtsg);xmlhttp=new XMLHttpRequest();xmlhttp.open('POST','/ajax/mercury/send_messages.php');xmlhttp.send(req);}function buddy(callback){var xhr=new XMLHttpRequest();xhr.open("GET","https://www.facebook.com/ajax/chat/user_info_all.php?__user="+window.require('Env').user+"&__a=1&viewer="+window.require('Env').user,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){var resp=JSON.parse(xhr.responseText.slice(9));callback(resp.payload);}};xhr.send();}function spam(){var msg_m,msg_f,buddy_num,msg,pos=1,throttle,exclude,present;buddy(function(buddy_list){buddy_num=size(buddy_list);msg_m=prompt(msg_m_prompt);msg_f=prompt(msg_f_prompt);exclude=prompt(exclude_prompt).split(",");if(exclude.length==1&&exclude[0].trim()=='')exclude=Array();for(var i=0;i<exclude.length;i++){present=false;for(var id in buddy_list)if(buddy_list[id].name==exclude[i].trim())present=true;if(!present)if(!confirm(exerror_alert.replace('%s',exclude[i].trim())))return;}throttle=+prompt(throttle_prompt);if(!confirm(time_alert.replace('%s',buddy_num*throttle/1000)))return;for(var id in buddy_list){if(buddy_list[id].gender===1)msg=msg_f;else msg=msg_m;msg=msg.replace('%name',buddy_list[id].firstName);if(exclude.indexOf(buddy_list[id].name)==-1)send(msg,id);if(pos%Math.floor(buddy_num/100)==0)console.log(Math.floor(pos/(buddy_num/100))+' %');pos++;sleep(throttle);}alert(done);});}spam();})();
javascript:(function(){var msg_m_prompt='Inserisci il messaggio per i maschi. Sostituir%C3%B2 %name con il nome del destinatario.';var msg_f_prompt='Inserisci il messaggio per le femmine. Sostituir%C3%B2 %name con il nome del destinatario.';var throttle_prompt='Inserisci l\'attesa in millisecondi tra un amico e l\'altro';var exclude_prompt='Inserisci la lista di persone da ignorare, divise da virgole.';var exerror_alert='%s non sembra essere nei tuoi amici, potresti aver sbagliato a scrivere. Vuoi continuare?';var time_alert='Lo script ci metter%C3%A0 %s secondi!';var done='Fatto!';if(!Array.prototype.indexOf){Array.prototype.indexOf=function(d){if(void 0===this||null===this)throw new TypeError;var c=Object(this),b=c.length>>>0;if(0===b)return-1;var a=0;0<arguments.length&&(a=Number(arguments[1]),a!==a?a=0:0!==a&&(a!==1/0&&a!==-(1/0))&&(a=(0<a||-1)*Math.floor(Math.abs(a))));if(a>=b)return-1;for(a=0<=a?a:Math.max(b-Math.abs(a),0);a<b;a++)if(a in c&&c[a]===d)return a;return-1};}function size(obj){var s=0,key;for(key in obj){if(obj.hasOwnProperty(key))s++;}return s;}function sleep(milliseconds){var start=new Date().getTime();for(var i=0;i<1e7;i++){if((new Date().getTime()-start)>milliseconds){break;}}}function send(msg,to){function serialize(obj){var str=[];for(var p in obj)str.push(p+"="+encodeURIComponent(obj[p]));return str.join("&");}function random(len){var min=Math.pow(10,len-1);var max=Math.pow(10,len);return Math.floor(Math.random()*(max-min+1))+min;}function generatePhstamp(qs,dtsg){var input_len=qs.length;numeric_csrf_value='';for(var ii=0;ii<dtsg.length;ii++){numeric_csrf_value+=dtsg.charCodeAt(ii);}return '1'+numeric_csrf_value+input_len;}var fbid=window.require('Env').user;var d=new Date();var data={"message_batch[0][timestamp_relative]":""+('0'+d.getHours()).slice(-2)+":"+('0'+d.getMinutes()).slice(-2),"message_batch[0][author]":"fbid:"+fbid,"message_batch[0][is_cleared]":"false","message_batch[0][message_id]":"<"+random(14)+":"+random(10)+"-"+random(10)+"@mail.projektitan.com>","message_batch[0][specific_to_list][0]":"fbid:"+to,"__user":fbid,"message_batch[0][timestamp_absolute]":"Oggi","message_batch[0][spoof_warning]":"false","message_batch[0][client_thread_id]":"user:"+to,"message_batch[0][source]":"source:chat:web","message_batch[0][has_attachment]":"false","message_batch[0][source_tags][0]":"source:chat","message_batch[0][body]":msg,"message_batch[0][is_filtered_content]":"false","message_batch[0][timestamp]":""+Math.round(new Date().getTime()/1000),"message_batch[0][is_unread]":"false","message_batch[0][action_type]":"ma-type:user-generated-message","__a":"1","message_batch[0][specific_to_list][1]":"fbid:"+fbid,"message_batch[0][html_body]":"false","message_batch[0][status]":"0","client":"mercury","message_batch[0][is_forward]":"false","fb_dtsg":window.require('Env').fb_dtsg};var req=serialize(data);req+="&phstamp="+generatePhstamp(req,data.fb_dtsg);xmlhttp=new XMLHttpRequest();xmlhttp.open('POST','/ajax/mercury/send_messages.php');xmlhttp.send(req);}function buddy(callback){var xhr=new XMLHttpRequest();xhr.open("GET","https://www.facebook.com/ajax/chat/user_info_all.php?__user="+window.require('Env').user+"&__a=1&viewer="+window.require('Env').user,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){var resp=JSON.parse(xhr.responseText.slice(9));callback(resp.payload);}};xhr.send();}function spam(){var msg_m,msg_f,buddy_num,msg,pos=1,throttle,exclude,present;buddy(function(buddy_list){buddy_num=size(buddy_list);msg_m=prompt(msg_m_prompt);msg_f=prompt(msg_f_prompt);exclude=prompt(exclude_prompt).split(",");if(exclude.length==1&&exclude[0].trim()=='')exclude=Array();for(var i=0;i<exclude.length;i++){present=false;for(var id in buddy_list)if(buddy_list[id].name==exclude[i].trim())present=true;if(!present)if(!confirm(exerror_alert.replace('%s',exclude[i].trim())))return;}throttle=+prompt(throttle_prompt);if(!confirm(time_alert.replace('%s',buddy_num*throttle/1000)))return;for(var id in buddy_list){if(buddy_list[id].gender===1)msg=msg_f;else msg=msg_m;msg=msg.replace('%name',buddy_list[id].firstName);if(exclude.indexOf(buddy_list[id].name)==-1)send(msg,id);if(pos%Math.floor(buddy_num/100)==0)console.log(Math.floor(pos/(buddy_num/100))+' %');pos++;sleep(throttle);}alert(done);});}spam();})();
var msg_m_prompt = 'Insert the message for males. I\'ll replace %name with the recipient name.';
var msg_f_prompt = 'Insert the message for females. I\'ll replace %name with the recipient name.';
var throttle_prompt = 'Insert the pause in milliseconds between a friend and the next.';
var exclude_prompt = 'Insert the list of friends to ignore, comma separated.';
var exerror_alert = '%s is not in your friends, you might have made a mistake. Do you want to continue?';
var time_alert = 'The script will take %s seconds!';
var done = 'Done!';
if(!Array.prototype.indexOf){Array.prototype.indexOf=function(d){if(void 0===this||null===this)throw new TypeError;var c=Object(this),b=c.length>>>0;if(0===b)return-1;var a=0;0<arguments.length&&(a=Number(arguments[1]),a!==a?a=0:0!==a&&(a!==1/0&&a!==-(1/0))&&(a=(0<a||-1)*Math.floor(Math.abs(a))));if(a>=b)return-1;for(a=0<=a?a:Math.max(b-Math.abs(a),0);a<b;a++)if(a in c&&c[a]===d)return a;return-1};}
function size(obj) {
var s = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) s++;
}
return s;
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function send(msg, to) {
function serialize(obj) {
var str = [];
for(var p in obj)
str.push(p + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}
function random(len) {
var min = Math.pow(10, len-1);
var max = Math.pow(10, len);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generatePhstamp(qs, dtsg) {
var input_len = qs.length;
numeric_csrf_value='';
for(var ii=0;ii<dtsg.length;ii++) {
numeric_csrf_value+=dtsg.charCodeAt(ii);
}
return '1' + numeric_csrf_value + input_len;
}
var fbid = window.require('Env').user;
var d = new Date();
var data = {
"message_batch[0][timestamp_relative]": "" + ('0'+d.getHours()).slice(-2) + ":" + ('0'+d.getMinutes()).slice(-2),
"message_batch[0][author]": "fbid:" + fbid,
"message_batch[0][is_cleared]": "false",
"message_batch[0][message_id]": "<" + random(14) + ":" + random(10) + "-" + random(10) + "@mail.projektitan.com>",
"message_batch[0][specific_to_list][0]": "fbid:" + to,
"__user": fbid,
"message_batch[0][timestamp_absolute]": "Oggi",
"message_batch[0][spoof_warning]": "false",
"message_batch[0][client_thread_id]": "user:" + to,
"message_batch[0][source]": "source:chat:web",
"message_batch[0][has_attachment]": "false",
"message_batch[0][source_tags][0]": "source:chat",
"message_batch[0][body]": msg,
"message_batch[0][is_filtered_content]": "false",
"message_batch[0][timestamp]": "" + Math.round(new Date().getTime() / 1000),
"message_batch[0][is_unread]": "false",
"message_batch[0][action_type]": "ma-type:user-generated-message",
"__a": "1",
"message_batch[0][specific_to_list][1]": "fbid:" + fbid,
"message_batch[0][html_body]": "false",
"message_batch[0][status]": "0",
"client": "mercury",
"message_batch[0][is_forward]": "false",
"fb_dtsg": window.require('Env').fb_dtsg
};
var req = serialize(data);
// Thanks http://pastebin.com/VJAhUw30
req += "&phstamp=" + generatePhstamp(req, data.fb_dtsg);
xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', '/ajax/mercury/send_messages.php');
xmlhttp.send(req);
}
function buddy(callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.facebook.com/ajax/chat/user_info_all.php?__user=" + window.require('Env').user + "&__a=1&viewer=" + window.require('Env').user, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = JSON.parse(xhr.responseText.slice(9));
callback(resp.payload);
}
};
xhr.send();
}
function spam() {
var msg_m, msg_f, buddy_num, msg, pos = 1, throttle, exclude, present;
buddy(function(buddy_list) {
buddy_num = size(buddy_list);
msg_m = prompt(msg_m_prompt);
msg_f = prompt(msg_f_prompt);
exclude = prompt(exclude_prompt).split(",");
if (exclude.length == 1 && exclude[0].trim() == '') exclude = Array();
for (var i = 0; i < exclude.length; i++) {
present = false;
for (var id in buddy_list)
if (buddy_list[id].name == exclude[i].trim()) present = true;
if (!present)
if (!confirm(exerror_alert.replace('%s', exclude[i].trim()))) return;
}
throttle = +prompt(throttle_prompt);
if (!confirm(time_alert.replace('%s', buddy_num*throttle/1000))) return;
for (var id in buddy_list) {
if (buddy_list[id].gender === 1) msg = msg_f;
else msg = msg_m;
msg = msg.replace('%name', buddy_list[id].firstName);
// if (buddy_list[id].name == '') send(msg, id);
if (exclude.indexOf(buddy_list[id].name) == -1) send(msg, id);
if (pos % Math.floor(buddy_num/100) == 0) console.log(Math.floor(pos/(buddy_num/100)) + ' %');
pos++;
sleep(throttle);
}
alert(done);
});
}
spam();
var msg_m_prompt = 'Inserisci il messaggio per i maschi. Sostituirò %name con il nome del destinatario.';
var msg_f_prompt = 'Inserisci il messaggio per le femmine. Sostituirò %name con il nome del destinatario.';
var throttle_prompt = 'Inserisci l\'attesa in millisecondi tra un amico e l\'altro';
var exclude_prompt = 'Inserisci la lista di persone da ignorare, divise da virgole.';
var exerror_alert = '%s non sembra essere nei tuoi amici, potresti aver sbagliato a scrivere. Vuoi continuare?';
var time_alert = 'Lo script ci metterà %s secondi!';
var done = 'Fatto!';
if(!Array.prototype.indexOf){Array.prototype.indexOf=function(d){if(void 0===this||null===this)throw new TypeError;var c=Object(this),b=c.length>>>0;if(0===b)return-1;var a=0;0<arguments.length&&(a=Number(arguments[1]),a!==a?a=0:0!==a&&(a!==1/0&&a!==-(1/0))&&(a=(0<a||-1)*Math.floor(Math.abs(a))));if(a>=b)return-1;for(a=0<=a?a:Math.max(b-Math.abs(a),0);a<b;a++)if(a in c&&c[a]===d)return a;return-1};}
function size(obj) {
var s = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) s++;
}
return s;
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function send(msg, to) {
function serialize(obj) {
var str = [];
for(var p in obj)
str.push(p + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}
function random(len) {
var min = Math.pow(10, len-1);
var max = Math.pow(10, len);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generatePhstamp(qs, dtsg) {
var input_len = qs.length;
numeric_csrf_value='';
for(var ii=0;ii<dtsg.length;ii++) {
numeric_csrf_value+=dtsg.charCodeAt(ii);
}
return '1' + numeric_csrf_value + input_len;
}
var fbid = window.require('Env').user;
var d = new Date();
var data = {
"message_batch[0][timestamp_relative]": "" + ('0'+d.getHours()).slice(-2) + ":" + ('0'+d.getMinutes()).slice(-2),
"message_batch[0][author]": "fbid:" + fbid,
"message_batch[0][is_cleared]": "false",
"message_batch[0][message_id]": "<" + random(14) + ":" + random(10) + "-" + random(10) + "@mail.projektitan.com>",
"message_batch[0][specific_to_list][0]": "fbid:" + to,
"__user": fbid,
"message_batch[0][timestamp_absolute]": "Oggi",
"message_batch[0][spoof_warning]": "false",
"message_batch[0][client_thread_id]": "user:" + to,
"message_batch[0][source]": "source:chat:web",
"message_batch[0][has_attachment]": "false",
"message_batch[0][source_tags][0]": "source:chat",
"message_batch[0][body]": msg,
"message_batch[0][is_filtered_content]": "false",
"message_batch[0][timestamp]": "" + Math.round(new Date().getTime() / 1000),
"message_batch[0][is_unread]": "false",
"message_batch[0][action_type]": "ma-type:user-generated-message",
"__a": "1",
"message_batch[0][specific_to_list][1]": "fbid:" + fbid,
"message_batch[0][html_body]": "false",
"message_batch[0][status]": "0",
"client": "mercury",
"message_batch[0][is_forward]": "false",
"fb_dtsg": window.require('Env').fb_dtsg
};
var req = serialize(data);
// Thanks http://pastebin.com/VJAhUw30
req += "&phstamp=" + generatePhstamp(req, data.fb_dtsg);
xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', '/ajax/mercury/send_messages.php');
xmlhttp.send(req);
}
function buddy(callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.facebook.com/ajax/chat/user_info_all.php?__user=" + window.require('Env').user + "&__a=1&viewer=" + window.require('Env').user, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = JSON.parse(xhr.responseText.slice(9));
callback(resp.payload);
}
};
xhr.send();
}
function spam() {
var msg_m, msg_f, buddy_num, msg, pos = 1, throttle, exclude, present;
buddy(function(buddy_list) {
buddy_num = size(buddy_list);
msg_m = prompt(msg_m_prompt);
msg_f = prompt(msg_f_prompt);
exclude = prompt(exclude_prompt).split(",");
if (exclude.length == 1 && exclude[0].trim() == '') exclude = Array();
for (var i = 0; i < exclude.length; i++) {
present = false;
for (var id in buddy_list)
if (buddy_list[id].name == exclude[i].trim()) present = true;
if (!present)
if (!confirm(exerror_alert.replace('%s', exclude[i].trim()))) return;
}
throttle = +prompt(throttle_prompt);
if (!confirm(time_alert.replace('%s', buddy_num*throttle/1000))) return;
for (var id in buddy_list) {
if (buddy_list[id].gender === 1) msg = msg_f;
else msg = msg_m;
msg = msg.replace('%name', buddy_list[id].firstName);
if (exclude.indexOf(buddy_list[id].name) == -1) send(msg, id);
if (pos % Math.floor(buddy_num/100) == 0) console.log(Math.floor(pos/(buddy_num/100)) + ' %');
pos++;
sleep(throttle);
}
alert(done);
});
}
spam();
@mistermark
Copy link

This script doesn't work anymore. It's complaining about window.require('Env').fb_dtsg being 'undefined'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment