Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created June 29, 2012 09:17
Show Gist options
  • Save kopiro/3016868 to your computer and use it in GitHub Desktop.
Save kopiro/3016868 to your computer and use it in GitHub Desktop.
Autoremove Inactive Friends
var inactiveFriendsRemover = function()
{
var removeAll = function()
{
for (var i=0; i<ids.length; i++)
{
var id = ids[i];
var as = new AsyncRequest();
as.setURI('/ajax/profile/removefriend.php');
as.setData({ norefresh:true, uid:id });
as.send();
}
}
var users = document.querySelectorAll('table [ajaxify]');
var ids = [];
var names = [];
for (var i=0; i<users.length; i++)
{
var v = users[i];
if (!v) continue;
if (!v.getAttribute) continue;
var ajaxify = v.getAttribute('ajaxify');
if (!ajaxify) return;
if (ajaxify.match(/inactive/))
{
var id = ajaxify.match(/id=([0-9]*)/)[1];
var name = v.innerHTML;
ids.push(id);
names.push(name);
}
}
if ( confirm('Are you sure to remove this friends ('+names.length+' users) ?\n' + names.join(', ') ) )
{
removeAll();
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment