Created
August 15, 2016 00:08
-
-
Save Telematica/609aa81026dbbe6aa1f8bdef9bcda606 to your computer and use it in GitHub Desktop.
Get User from Twitter List and Request List Migrate (Twitter for Web)
This file contains hidden or 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
//[\r\n]+ | |
var users = [], | |
listId = JSON.parse(document.getElementById('init-data').value).list_id, //'762404565366956032', | |
headers = { | |
"Accept" : "application/json, text/javascript, */*; q=0.01", | |
"Accept-Language" : "en-US,en;q=0.5", | |
"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8", | |
"X-Requested-With" : "XMLHttpRequest", | |
}, | |
formData = { | |
//"_method":"DELETE", | |
"authenticity_token": document.querySelector('[name="authenticity_token"]').value //"b788e2a2890d262b5bb3f1c56bac6e96109baac6" | |
}, | |
counter = 0; | |
Notification | |
.requestPermission().then(function(result){ | |
if ('granted' === result) { | |
sendRequest(users[counter]); | |
} else { | |
alert('Notification Permission rejected.'); | |
} | |
}); | |
function sendRequest(user) { | |
var xhr = new XMLHttpRequest(), | |
strData = '', | |
url = 'https://twitter.com/i/$userId$/lists/$listId$/members'; //https://twitter.com/i/4416500843/lists/739298270749429760/members | |
//Set Custom URL | |
url = url.replace(/\$userId\$/, user).replace(/\$listId\$/, listId); | |
//Prepare Request URL | |
xhr.open('POST', url); | |
//Set Request Headers | |
for (header in headers) { | |
xhr.setRequestHeader(header, headers[header]); | |
} | |
//Set POST Data | |
for(data in formData) { | |
strData += decodeURIComponent(data+'='+formData[data])+'&'; | |
} | |
//OnError binding | |
xhr.onerror = function(e) { | |
console.error(xhr.statusText); | |
return new Notification('Something went wrong adding the Account at position: '+counter); | |
}; | |
//OnSuccess binding | |
xhr.onload = function() { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
counter++; | |
if (undefined !== users[counter]) { | |
sendRequest(users[counter]); | |
console.log(users[counter], counter); | |
return new Notification('Processing Account from position: '+counter); | |
} else { | |
return new Notification('No more Accounts to be added to current List'); | |
} | |
} else { | |
console.error(xhr.statusText); | |
return new Notification('Server responded the request, but an Error occurred! Check the logged data on console!'); | |
} | |
} | |
}; | |
console.log('success!'); | |
return xhr.send(strData); | |
} | |
//Get All User Id's from List Page | |
(function () { //getUserIds | |
var publics = [], privates = []; | |
document.querySelector('.stream').querySelectorAll('.user-actions[data-user-id]').forEach(function(a,b,c){ | |
if (null === a.parentNode.querySelector('.Icon--protected')) { | |
publics.push(a.dataset.userId); | |
} else { | |
privates.push(a.dataset.userId); | |
//window.open('https://twitter.com/intent/user?user_id='+a.dataset.userId); | |
} | |
}); | |
copy(privates); | |
return publics; | |
})(); | |
/* | |
Create List : https://twitter.com/i/lists/create | |
Add/Delete User from list : https://twitter.com/i/712362530723631106/lists/762404565366956032/members | |
Get User Profile : https://twitter.com/intent/user?user_id=XXX | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment