Bookmarklets are pieces of JavaScript code that are stored as bookmarks in your browser, and execute locally (i.e. inside the downloaded page) as the bookmark is clicked.
Using the Facebook Graph API, you can take a look “behind the scenes” to retrieve the raw information of what is being displayed when you browse Facebook.
Requests under the URL http://graph.facebook.com/ return JSONified data about the requested object, which is identified by it’s ID.
Posts and Threads
Let’s look at threads (posts) and their IDs. There are a couple of ways the thread ID is stored in the thread URL, depending on where it is posted (page, group) and how you browse it (permalink or notification):
https://www.facebook.com/[name]/posts/[thread id]
https://www.facebook.com/groups/[group id]/permalink/[thread id]/
https://www.facebook.com/photo.php?fbid=[thread id]&set=[...]
Since the thread ID is numeric, a simple regex \d+ would be sufficient to retrieve it. However, group IDs may also be numeric, and names may contain digits.
After a bit of experimenting, the regex that I came up with to extract the thread ID from a Facebook URL, is
(/[\/=](\d+)[&\/]?/.exec(window.location.toString().replace(/\/groups\/\d+\//),""))[1]
Using this regex, we can now craft a JavaScript routine to open a new window containing the Graph API result:
window.open("http://graph.facebook.com/" +
(/[\/=](\d+)[&\/]?/.exec(window.location.toString().replace(/\/groups\/\d+\//),""))[1] +
"/comments", "_blank")
and create a bookmark for it. Since this WordPress installation does not allow to include bookmarklet links, you need to
- Create a bookmark in your browser
- Give it a name, such as “View Comments in FB Graph”
- Set the URL or location to
javascript:window.open("http://graph.facebook.com/" + (/[\/=](\d+)[&\/]?/.exec(window.location.toString().replace(/\/groups\/\d+\//),""))[1] + "/comments", "_blank")
But this does not give you the contents of the whole thread, just the comments.
To retrieve the whole post, we can use the Graph API Explorer.
The Graph API Explorer retrieves the details of a Facebook object, such as a post or thread, using the URL
https://developers.facebook.com/tools/explorer/?method=GET&path=[object id]
So, as we know how to extract the thread ID from a FB URL, let’s create a bookmarklet with the URL
javascript:window.open("https://developers.facebook.com/tools/explorer/?method=GET&path="+ (/[\/=](\d+)[&\/]?/.exec(window.location.toString().replace(/\/groups\/\d+\//,"")))[1], "_blank")
This opens the Graph Explorer with the desired ID. Click Submit to retrieve the data. Probably you need to click Get Access Token first.
Remove the Right Column
If you want to take screenshots of Facebook pages, you probably want to remove the right column before screenshotting, since it only expands the image, but does not include the content you want to save.
The top-most HTML container for right column content is called “rightCol” (yes, surprising).
To remove it from display, simply add this code to a bookmarklet:
javascript:var rc=document.getElementById("rightCol");rc.parentElement.removeChild(rc);
Clean up the Likes Page
To get a screenshot of “selected” Likes on a Like Page, there is a way to delete the Likes we don’t like (haha).
Simply scroll down until the list of likes is complete, then run this bookmarklet:
javascript:var li=document.getElementsByClassName("_5rz");for(var i=0;i<li.length;i++){var l=li[i];l.onclick=(function(el){return function() { el.parentElement.removeChild(el);return false;};})(l);}
Now clicking on a Like preview image will remove the entry from the list, allowing you to retain only the desired entries, ready to screenshot.