Last active
March 20, 2017 13:31
-
-
Save JonathanPorta/4655470a99306aab407a7009f244ff97 to your computer and use it in GitHub Desktop.
Add a checkbox to a Twitter user and then see who was checked
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
// This File: https://gist.github.com/JonathanPorta/4655470a99306aab407a7009f244ff97 | |
// Handles List: https://gist.github.com/JonathanPorta/5278413566e561e1c4bf059aecf99d1d | |
// Add the checkboxes | |
var allHandles = []; | |
$('a.ProfileCard-screennameLink').each(function(i,e){ | |
var $e = $(e); | |
var handle = $e.text().trim(); | |
$e.before($("<input type='checkbox' style='height: 2.5em; width: 2.5em;' value='"+handle+"'/>")); | |
allHandles.push(handle); | |
}); | |
// See what was checked | |
var checkedHandles = []; | |
$('.ProfileCard-screenname input[type="checkbox"]:checked').each(function(i,e){ | |
var $e = $(e); | |
var handle = $e.val().trim(); | |
checkedHandles.push(handle); | |
}); | |
checkedHandles | |
// Unsub from all handles - 2 seconds between each. | |
var sleep = function (ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// Grab the right buttons and then clickitty click click away! | |
var btns = []; | |
$(checkedHandles).each(async function(k,v){ | |
var handle = v.replace('@', ''); | |
var unsub = $('div.user-actions[data-screen-name="'+handle+'"]>button'); | |
btns.push(unsub); | |
await sleep(2000); | |
unsub.click(); | |
}); | |
//Generate links from handles in new THCbabess | |
// requires sleep() | |
var urls = []; | |
$(checkedHandles).each(async function(k,v){ | |
var handle = v.replace('@', ''); | |
var url = $("<a class='checkedHandleLink' href='/"+handle+"' target='_BLANK'>"+handle+"</a>"); | |
$('body').append(url); | |
urls.push(url); | |
}); | |
// Click the links | |
// requires sleep() | |
var stop = 15; // set this small at first to test | |
$('a.checkedHandleLink').each(/*async*/ function(i, e){ | |
if(i == stop) {return false;} | |
var link = $(e); | |
var href = link.attr('href'); | |
window.open(href, i); | |
link.remove() // Remove it so we don't go there again | |
}); | |
//Finally, subscribe to dat shit! | |
(async function(){ | |
// Define some variables that we need to know in order to poke things in the dom. | |
var handle = location.pathname.replace('/', ''); // Finds the username of current profile | |
var interactionOptions = $('.user-actions[data-screen-name='+handle+']'); | |
// First, we need a set of helper functions to make sure everyting is copistetic | |
var sleep = function (ms) { return new Promise(resolve => setTimeout(resolve, ms)); } | |
var ensureMenuIsOpen = function() { | |
// Make sure the dropdown menu is open before we start trying to check it. | |
if(!$('.user-actions[data-screen-name='+handle+'] .dropdown-menu').is(':visible')){ | |
// Menu isn't open, so, let's open sesame it! | |
$('.user-actions[data-screen-name='+handle+'] .user-dropdown-icon').click(); // OPEN DROPPPPP DOOOOOOOOWN - before da po-po shut us dow....rr.. | |
} | |
}; | |
var hasNotifications = function(){ | |
ensureMenuIsOpen(); | |
// menu should be open and the off button should be visible. otherwise, notifications are off... | |
return $('.user-actions[data-screen-name='+handle+'] .dropdown-menu').is(':visible') && $('.user-actions[data-screen-name='+handle+'] .device-notifications-off-text button').is(':visible') | |
}; | |
var enableNotifications = function() { | |
// Guard against not being able to enable notifications | |
if(!canEnableNotifications()){ return false; } | |
ensureMenuIsOpen(); | |
if(!hasNotifications()) { | |
$('.user-actions[data-screen-name='+handle+'] .device-notifications-on-text').click(); // Enable Mobile Notes | |
return true; | |
} | |
}; | |
var isFollowing = function() { | |
return interactionOptions.hasClass('following'); | |
}; | |
var isPending = function() { | |
return interactionOptions.hasClass('pending'); | |
}; | |
var canEnableNotifications = function() { | |
return interactionOptions.hasClass('following') && !hasNotifications() | |
}; | |
var canFollow = function() { | |
// Can only follow if we are not already following nor are we waiting on the user to accept. | |
if(isFollowing() || isPending()){ return false; } | |
return true; | |
}; | |
var follow = function(){ | |
// Guard against an already-followed state or a pending (waiting for user to accept the follow) state. | |
if(!canFollow()){ return false } | |
var followButton = $('button.user-actions-follow-button', interactionOptions); | |
// ensure we have a button, otherwise, fail! | |
if(followButton.length > 0) { | |
followButton.click(); | |
return true; | |
} | |
else { | |
return false; | |
} | |
}; | |
// Do the actual work | |
if(canFollow()){ | |
follow(); | |
} | |
await sleep(1000); | |
if(canEnableNotifications()){ | |
enableNotifications(); | |
} | |
// Make it easy to see that the script ran properly. | |
ensureMenuIsOpen() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment