Skip to content

Instantly share code, notes, and snippets.

@mircobabini
Created December 9, 2012 12:22
Show Gist options
  • Save mircobabini/4244635 to your computer and use it in GitHub Desktop.
Save mircobabini/4244635 to your computer and use it in GitHub Desktop.
useful to create large lists from others on twitter
/**
* useful to create large lists from others on twitter
*
* @author Mirco Babini <[email protected]>
* @license http://creativecommons.org/licenses/by-nc/3.0/
*
* @usage
* gimmeabeer (listid);
* gimmeabeer ([listid1, listid2, ..]);
*/
(function (w) {
w.tests = w.acts = 0;
// change timeout if ajax fails coz of ur 56k connection :|
var timeout = 500;
// world is a better place now
var _ = {},
$ = w.jQuery;
// gimmeabeer is the new execute
w.gimmeabeer = function (listid) {
_.listids = (!$.isArray (listid)) ? [listid] : listid;
boostjquery ();
// get elems on page and 'cycle' them
var elems = $(".dropdown-menu li:nth-child(4)");
elaborate (elems);
}
var boostjquery = function () {
$.fn.pop = [].pop;
$.fn.shift = [].shift;
}
// that's recursive coz of timeouts..
var elaborate = function (elems)
{
w.tests++;
if (elems.length > 0)
{
// shift an elem
var elem = elems.shift ();
// click on it to open the modalbox
elem.click ();
// wait and then* check-for-checking the field to check, lol
setTimeout (function () {
var index, listid, check;
// cycle them all: if at least one is checked i won't act
for (index in _.listids)
{
listid = _.listids[index];
check = $("#list-membership-dialog li[data-list-id=" + listid + "]");
if (check.find ("input[type=checkbox]:first").is (":checked"))
return true;
}
w.acts++;
check.click ();
}, timeout);
// wait for a while and go thru elems
setTimeout (function () {
elaborate (elems);
}, timeout+100);
}
else
{
alert (w.acts + '/' + w.tests);
}
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment