Skip to content

Instantly share code, notes, and snippets.

@TheEssem
Forked from twilight-sparkle-irl/rtpin.js
Created October 10, 2019 16:18
Show Gist options
  • Save TheEssem/f93c7e37e12aa05a9fa1c7a5d25d1804 to your computer and use it in GitHub Desktop.
Save TheEssem/f93c7e37e12aa05a9fa1c7a5d25d1804 to your computer and use it in GitHub Desktop.
pin retweets on twitter
$(document).ajaxComplete((e, x, o) => {
if (o.url == "https://api.twitter.com/1.1/statuses/retweet.json") {
tweet_id = JSON.parse(x.responseText)['id_str'];
auth_token = JSON.parse(document.querySelector('#init-data').value)['formAuthenticityToken'];
fetch("https://twitter.com/i/tweet/pin", {
body: `authenticity_token=${auth_token}&id=${tweet_id}`,
method: "POST",
headers: {
Accept: "application/json, text/javascript, */*; q=0.01",
"Cache-Control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"X-Twitter-Active-User": "yes"
}
}).then(res => res.json()).then(res => $(document).trigger('uiShowError', res))
}
})
// paste this into javascript console on a twitter permalink status page (https://twitter.com/[user]/status/[id])
// this will make any tweet you retweet on that page also pin itself to your profile
// this is very laggy bc jquery sucks
// so i recommend opening your tweet in a new tab, pasting the code, retweeting, and then closing the tab
// also this only works on old twitter, not nu PWA twitter
// enjoi
// oh also
// this works because when you retweet a tweet, you get a tweet id
// this is not the original tweet's id, this is actually the id *of your retweet*
// for backwards compatibility reasons, twitter, despite displaying them differently, actually has retweets stored as normal tweets
// and these normal tweets are attributed to you
// so since it's a tweet, and it's attributed to you, the /i/tweet/pin api goes "well ok" and pins it bc it never checks if its a retweet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment