Igor Tolkov

March 2014

123456121314151617181920212223242526

Photos feed for the new Facebook

The new Facebook layout, compared with the “old new” Facebook layout, misses a photos feed. Bummer, since that’s probably my favorite way of browsing Facebook.

Challenge: code up a photos feed for Facebook in 40 minutes.

The simple solution relies on a macro plugin (I use Scriptish for Firefox, there is probably a similar app for Chrome.) The macro is Javascript code that is executed on or after page load. Here is the code:

// ==UserScript==
// @id             10
// @name           Facebook-photosfeed
// @version        0.01
// @namespace
// @author         Igor Tolkov
// @description    Introduces a photos feed for Facebook
// @include        https://www.facebook.com/*
// @run-at         document-start
// ==/UserScript==
window.setInterval(function(){
    /* Hides posts, leaving only those which contain photos */
    var show_photos = function(){
        var s = document.getElementsByClassName("_5jmm");
        for(var i in s){
            var a = s[i]; if(!a.className) continue;
            a.style.display = "none";
        }
        for(var t in {"_5cq3":0, "_2a2q":1}){
            var s = document.getElementsByClassName(t);
            for(var i in s){
                var a = s[i]; if(!a.className) continue;
                while(a.className.indexOf("_5jmm")==-1) a = a.parentNode;
                a.style.display = "block";
            }
        }
    };

    /* Adds a photos feed link in sidebar */
    if(!document.getElementById("link_show_photos"))
    {
        var li = document.createElement("LI");
        li.id = "link_show_photos";
        li.className = "sideNavItem stat_elem";
        li.innerHTML = '<a title="News Feed" href="/?sk=photos" class="item clearfix"><div class="rfloat"><span aria-busy="1" aria-label="Loading..." class="img _55ym _55yn _55yo _5tqs uiSideNavSpinner"></span></div><div><span class="imgWrap"><i class="img sp_247cvt sx_cfa14f"></i></span><div class="linkWrap noCount">Photos Feed</div></div></a>';
        var ref = document.getElementById("navItem_app_4748854339" /* News Feed */);
        ref.parentNode.insertBefore(li, ref.nextSibling);
    }
    else
    {
        if(location.search == "?sk=photos")
            document.getElementById("link_show_photos").className = "sideNavItem stat_elem selectedItem open";
        else
            document.getElementById("link_show_photos").className = "sideNavItem stat_elem";
    }

    /* We use a custom news feed landing url. Facebook does not recognize it and ignores it. */
    if(location.search == "?sk=photos")
        show_photos();
}, 500);

Now you can also have a Facebook photos feed!