Last active
December 11, 2015 07:29
-
-
Save rpavlik/4566896 to your computer and use it in GitHub Desktop.
I'm not a regular twitter user, and it's too annoying to manually create the rss feed url for the twitter feeds I do want to follow in Google Reader. Their bookmarklet doesn't get the job done, but this one (twitter-specific) does. Just bookmark the "compiled" version.
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
javascript:(function(){var%20canonical%3D%22%22%3Bvar%20links%3Ddocument.getElementsByTagName(%22link%22)%3Bfor(var%20i%3D0%3Bi%3Clinks.length%3Bi%2B%2B)%7Bif(links%5Bi%5D.getAttribute(%22rel%22)%3D%3D%3D%22canonical%22)%7Bvoid(canonical%3Dlinks%5Bi%5D.getAttribute(%22href%22))%7D%7Dif(canonical)%7Bvar%20feed%3D%22https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fuser_timeline.rss%3Fscreen_name%3D%22%2Bcanonical.substr(canonical.lastIndexOf('%2F')%2B1)%3Blocation%3D'http%3A%2F%2Fwww.google.com%2Freader%2Fview%2Ffeed%2F'%2BencodeURIComponent(feed)%7D})(); |
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
// Use this tool to keep the full-form js maintainable: | |
// http://jsbeautifier.org/ | |
// | |
// and this tool to turn it into a bookmarklet: | |
// (enable "shrink vars" and "into bookmarklet") | |
// http://zenoplex.jp/tools/javascript_packer.html | |
// | |
// Based on original google reader bookmarklet. | |
// | |
// Get canonical URL for easy extraction of twitter handle | |
// thanks to http://stackoverflow.com/q/5980682/265522 | |
var canonical = ""; | |
var links = document.getElementsByTagName("link"); | |
for (var i = 0; i < links.length; i++) { | |
if (links[i].getAttribute("rel") === "canonical") { | |
void(canonical = links[i].getAttribute("href")); | |
} | |
} | |
if (canonical) { | |
// Grab user name from canonical url like https://twitter.com/luanews | |
// thanks to http://stackoverflow.com/q/4758103/265522 | |
// then build the feed url, thanks to | |
// http://planetpeschel.com/wp/2012/03/how-to-add-a-twitter-rss-feed-to-google-reader/ | |
var feed = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=" + canonical.substr(canonical.lastIndexOf('/') + 1); | |
location = 'http://www.google.com/reader/view/feed/' + encodeURIComponent(feed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment