Skip to content

Instantly share code, notes, and snippets.

@plantvsbirds
Last active January 8, 2020 10:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plantvsbirds/ff8829a247d7fd522405 to your computer and use it in GitHub Desktop.
Save plantvsbirds/ff8829a247d7fd522405 to your computer and use it in GitHub Desktop.
/*------------------------get Twitter Ids on page ---------------------
| Find twitter IDs of people on page(intended for blocking multiple
users) bookmarklet inspired by @mariotaku 's wtb
| Author: Hong Lin <plantvsbird@gmail.com>
License: MIT
| See comments below for usage thx.
| https://gist.github.com/plantvsbirds/ff8829a247d7fd522405
*-------------------------------------------------------------------*/
(function (window, $) {
if (location.href.indexOf('twitter.com') < 0) {
alert('Please run this on twitter page, thx')
return
}
anchors = $('a[data-mentioned-user-id],a[data-user-id]')
map = {}
anchors.each(function () {
elem = $(this)
link = elem.attr('href')
name = elem.find('b').text() || link.slice(1, link.length - 1)
id = elem.attr('data-mentioned-user-id') || elem.attr('data-user-id')
if (id == '0')
id = 'Visit profile page and run again please. <a href="' + link + '">Click Here</a>'
map[id] = name
})
promptText = [
'',
'All Twitter accounts found on page',
''
]
ansInLines = Object.keys(map).map(function (k) {
return '[' + map[k] + '] : '+ k +' '
})
finalText = promptText
.concat(ansInLines)
.concat(promptText)
.concat(['<button type="button" onclick="window.open(\'\', \'_self\', \'\'); window.close();">Close</button>'])
.join('<br>')
alertWindow = window.open()
alertWindow.document.write(finalText)
if(!alertWindow || alertWindow.closed || typeof alertWindow.closed=='undefined') {
alert('Disable your popup blocking plz')
}
})(window, jQuery)
@plantvsbirds
Copy link
Author

Use this as bookmarklet.
Ctrl + D to add this page. Then click EDIT, change the address to following
(just minified version. no harmful stuff fucking with you)

javascript:!function(e,t){return location.href.indexOf("twitter.com")<0?void alert("Please run this on twitter page, thx"):(anchors=t("a[data-mentioned-user-id],a[data-user-id]"),map={},anchors.each(function(){elem=t(this),link=elem.attr("href"),name=elem.find("b").text()||link.slice(1,link.length-1),id=elem.attr("data-mentioned-user-id")||elem.attr("data-user-id"),"0"==id&&(id='Visit profile page and run again please. <a href="'+link+'">Click Here</a>'),map[id]=name}),promptText=["","All Twitter accounts found on page",""],ansInLines=Object.keys(map).map(function(e){return"["+map[e]+"] : "+e+" "}),finalText=promptText.concat(ansInLines).concat(promptText).concat(["<button type=\"button\" onclick=\"window.open('', '_self', ''); window.close();\">Close</button>"]).join("<br>"),alertWindow=e.open(),alertWindow.document.write(finalText),void((!alertWindow||alertWindow.closed||"undefined"==typeof alertWindow.closed)&&alert("Disable your popup blocking plz")))}(window,jQuery);

When on twitter page, just click the bookmark you added to run script.

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