labm0nkey / Feedly slimFeed

// ==UserScript==
// @id             feedlyslimfeed@labm0nkey
// @name           Feedly slimFeed
// @version        1.3
// @namespace      
// @author         labm0nkey
// @description    Adds favicons to feeds and quick mark as read buttons.
// @include       http://feedly.com/*
// @include       https://feedly.com/*
// @include       http://www.feedly.com/*
// @include       https://www.feedly.com/*
// @include       http://cloud.feedly.com/*
// @include       https://cloud.feedly.com/*
// @include       http://www.cloud.feedly.com/*
// @include       https://www.cloud.feedly.com/*
// @match         http://feedly.com/*
// @match         https://feedly.com/*
// @match         http://www.feedly.com/*
// @match         https://www.feedly.com/*
// @match         http://cloud.feedly.com/*
// @match         https://cloud.feedly.com/*
// @match         http://www.cloud.feedly.com/*
// @match         https://www.cloud.feedly.com/*
// @require       http://code.jquery.com/jquery-latest.min.js
// @run-at        document-end
// ==/UserScript==

function deserialize(name, def) {
    return eval(GM_getValue(name, (def || '({})')));
}

function serialize(name, val) {
    GM_setValue(name, uneval(val));
}

var arrow_down = '<img class="arrow_down" title="Mark below as read" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbC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LG58yMzMwMjLSMkgfMdy/wWDEwMDAwHD9kc5zDg4GJiYm2sYhIwPDX6j2v8wsLLS3ENV2Rmqn0iPKzRYWNy0sWq8dZ2GRxR5fh2SR1VBk4aOlc3S2MjCoMTBs1iw0adl2nI1ZCtXK/TyNxoU74WpaTvrjDRBCtcWbNxuUW82LN29iYNAkHBrB56bfbLN3Y2H5QrYP//+3vlt/tt89kIHhIiHLZt3ptLT/+/cLxYnmzx+rx3XnJ3jhthRimc2vX79+/vxJeSr9//8/w69fls+wW4pq2a9fv6iTLbBbimkZoTRBMNGgl6WMjIwMbGzHpZoMD25zv9Vpaffnz3d0y/CVpYyjbZpRC0ctHHALAQMA9bOf3WH9XQAAAAAASUVORK5CYII=">';

var arrow_up = '<img class="arrow_up" title="Mark above as read" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoX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Tt7NndwI2VhRAjRvSNVsd3JeAEu5wGy4Bp1BH/D7LhFHcFOmIrq+uOYZ/BO0wY7Ye3o6cJhToiHCU/gfvx228bWoZp5yQzBZslep8vpUdioAFxD5P3ifMYTmEouXsFadRVeT55TK7D8adcsINps1VJPyZjdE9raqXi6h1HD+CgWE9OQAPp/1C3LUnq6PWk8/rBdgaZp0jIMwNS+j1T7c3C40YBIqAIwPkUJQq5A4fSmsWepkvZP/00tdpqlwn9E+aAPqvkaAMYtf33esXfWAAAAAElFTkSuQmCC">';

var cache_refresh = '<img id="cacheRefresh" width="24" height="24" border="0" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz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iVutNE8CgKq1Xfl8FNtMCMKBf2K46bPwncBPIA9/TiIFe4Amwx2HuZ2B/BH8LOAfMp5mFHlU5+RngNLAPOBAxbxk4kmTztVhgBMhZeJt6mgsOch4AV4Cd1KpRdZnbEa5wDNioImMHuAZMpV5OA8cBW02dd9j8J5233KxibsjyftbBbRbU3+u6+bgA+iP8OYruAifUzZrXkUV8JatlkRuNrArjWKDTErzbNJHaaD590ao1OH40AsC3kHfd2mkl6dK6HXUlBvA+oi6qlQZi6koEwBaslxMAsK1dbASAWcv7YS2taynHhy28F40A8E5r9jB6GLMZ6dU1tr5goREAAG5Z3ndrczPoePJLluCN0lEXADPAKwuvC5gDnqprtBu977Dy5iLK8UXV0dCG5iK7t2y2EzyrI5gOOx3kbgEX0viQrWnd71LLdzpufkdlrqX1JZ4HThHzxtlCFZVVU2eWpJTwS+TFBDIWVcZCrQKS1kIb2onFNb/vhi5dXN2DOIwe68gBZzRVdgTujN5q1VoCngEr9aoEpdX/YkpcTotI3FEWEU9E8iLyT/QD9QcgIjkRKelJeSJSNPhFn6cNyIQhYgxYDzQohRA1WcC3RllEsgH5eRFZV15FRMasCDzP+20AGc3NZpc0ofzJEJ6nm/avWML4eeWX9dnUUVL5J23rzb16nhcKoGAIzKqySqiA3cwSPGXzecyXZwDwn319FeOACgagkiuAon+iYQt0Tl7dphTiJv7JZi1GLxsWyRkAyhYLhB5gWw1ZZ1JBZoBxdm+q06CMiGRcgngl4MuISFYDyRORXMDXp4CP/HnZuxJwnaALrTtu1F8/7nmeGONrkiD2Y6JiMXGhShAXHF3IFsRFpxhQITnDv4tAJuD/lUAg5o2grJZGIwGoDnN90RaP/0uJZtOvAQBHAfANQCkJsgAAAABJRU5ErkJggg==" class="pageAction" title="Refresh cache">';

var h1read = '<h1 class="readWait">Marking as read...</h1>';
var entryClass = '';

(function ($) {
    var favicons = {};

    var marking_as_read = false;

    //check settings
    if (GM_getValue("ffa_cache") == undefined) {
        favicons = generateFavicons();
    } else {
        favicons = deserialize("ffa_cache");
    }

    var cssTxt;
    cssTxt = " .arrow_up, .arrow_down {cursor: pointer;} .readWait { position: absolute; top: 50%; left: 50%; background: none repeat scroll 0 0 rgba(255, 255, 255, 0.2); border-radius: 3px; color: #82BD1A;} .u4Entry { padding-left: 24px; }";
    cssTxt += ".u0Entry:nth-child(even) { background-color:#f6fceb; } .u0Entry:nth-child(odd) { background-color:#fdfef9; }";
    cssTxt += ".u4Entry:nth-child(even) { background-color:#f6fceb; } .u4Entry:nth-child(odd) { background-color:#fdfef9; }";
    cssTxt += ".u5Entry:nth-child(even) { background-color:#f6fceb; } .u5Entry:nth-child(odd) { background-color:#fdfef9; }";
    cssTxt += ".u100Entry:nth-child(even) { background-color:#f6fceb; } .u100Entry:nth-child(odd) { background-color:#fdfef9; }";
    cssTxt += ".slim-favicon { opacity: 0.9; height: 16px, width: 16px; float: left;}";
    cssTxt += ".metadata { overflow: visible !important; }";
    cssTxt += ".u0Entry .slim-favicon {margin: 8px 7px 0px 0px;}";
    cssTxt += ".u4Entry .slim-favicon {margin: 1px 7px 0px 0px;} .u4Entry .metadata { max-height: 20px !important; } .u4Entry .slim-favicon { opacity: 0.9; width: 16px; height: 16px; display: inline; } ";
    cssTxt += ".u5Entry .slim-favicon {margin: 1px 7px 0px 0px;} .u5Entry .metadata { max-height: 20px !important; } .u5Entry .slim-favicon { opacity: 0.9; width: 16px; height: 16px; display: inline; } ";
    cssTxt += ".u100Entry .slim-favicon {margin: 1px 7px 0px 0px;} .u100Entry .metadata { max-height: 20px !important; } .u100Entry .slim-favicon { opacity: 0.9; width: 16px; height: 16px; display: inline; } ";

    GM_addStyle(cssTxt);

    function viewToClass() {
        return "." + checkView() + "Entry";
    }

    /*
     $('#feedlyPart').on('DOMAttrModified', function (event) {
     var element = event.target;

     if (element.attributes["id"].nodeValue == 'loadingEntries') {

     var entry = viewToClass();
     $(entry).each(function () {
     $(this).slimStyle();
     });

     $('#section0_column0').on('DOMNodeInserted', function (event) {
     var element = event.target;
     var entry = viewToClass();
     if (element.attributes["class"].nodeValue == (entry + ' ')) {
     addFavicon($(element));
     addArrows($(this));
     }
     });
     }
     });
     */
    $.fn.slimStyle = function () {
        return this.each(function () {
            addFavicon($(this));
            addArrows($(this));
        });
    };

    var init = function () {

    };

    function checkView() {
        var timeline = $('#timeline');
        if (timeline.hasClass('u0EntryList')) {
            entryClass = 'u0Entry';
            return 'u0';
        }
        if (timeline.hasClass('u4EntryList')) {
            entryClass = 'u4Entry';
            return 'u4';
        }
        if (timeline.hasClass('u5EntryList')) {
            entryClass = 'u5Entry';
            return 'u5';
        }
        if (timeline.hasClass('u100EntryList')) {
            entryClass = 'u100Frame';
            return 'u100';
        }
        return 'error';
    }

    function addFavicon(e) {
        var fav = e.find('.slim-favicon');
        if (fav.length == 0) {
            switch (checkView()) {
                case 'u0':
                    var info = e.find('.sourceInfo');
                    var uri = info.find('a').attr('data-uri');
                    info.before(favicons[uri]);
                    break;
                case 'u4':
                    var info = e.find('.sourceTitle');
                    var uri = info.attr('data-uri');
                    info.before(favicons[uri]);
                    break;
                case 'u5':
                    var info = e.find('.sourceTitle');
                    var uri = info.attr('data-uri');
                    info.before(favicons[uri]);
                    break;
                case 'u100':
                    var info = e.find('.sourceTitle');
                    var uri = info.attr('data-uri');
                    info.before(favicons[uri]);
                    break;
            }
        }
    }

    function addArrows(e) {
        var tools = e.find('.condensedTools');

        if (tools.find('.arrow_down').length == 0) {
            var a = $(tools).prepend(arrow_up);
            $(a).find('.arrow_up').on('click', function () {
                if (!marking_as_read) {
                    marking_as_read = true;
                    $("#feedlyPart0").css("opacity", "0.1");
                    $("#feedlyPart0").parent().prepend(h1read);

                    var entry = viewToClass();
                    $(this).closest(entry).prevAll(entry).each(function () {
                        if ($(this).find('.unread').length == 1) {
                            $(this).click();
                        }
                    });
                    $(this).closest(entry).click();
                    $("#feedlyPart0").css("opacity", "1");
                    $("#feedlyPart0").parent().find(".readWait").remove();
                    marking_as_read = false;
                }
            });
            var b = tools.prepend(arrow_down);
            $(b).find('.arrow_down').on('click', function () {
                if (!marking_as_read) {
                    marking_as_read = true;
                    $("#feedlyPart0").css("opacity", "0.1");
                    $("#feedlyPart0").parent().prepend(h1read);

                    var entry = viewToClass();
                    $(this).closest(entry).nextAll(entry).each(function () {
                        if ($(this).find('.unread').length == 1) {
                            $(this).click();
                        }
                    });
                    $(this).closest(entry).click();
                    $("#feedlyPart0").css("opacity", "1");
                    $("#feedlyPart0").parent().find(".readWait").remove();
                    marking_as_read = false;
                }
            });
        }
    }

    function generateFavicons() {
        var array = {};
        $('.tab').each(function () {
            $(this).find('.icon.handle').not('.expanded').each(function () {
                $(this).click();
            });

            $(this).find('.favicon').each(function () {
                var element = $(this).clone();
                element.addClass('slim-favicon');
                element.removeClass('favicon');
                var image = $('<div/>').append(element).html();

                var index = $(this).parent().attr('data-uri');

                array[index] = image;
            });

            $(this).find('.icon.handle.expanded').each(function () {
                $(this).click();
            });
        });
        return array;
    }

    $(document).bind('DOMNodeInserted', function (event) {
        var element = event.target;
        if (element.attributes["id"].nodeValue == 'timeline') {
            $('#timeline > div').bind("DOMNodeInserted", function (event) {
                checkView();
                if ($(event.target).hasClass(entryClass)) {
                    $(event.target).slimStyle();
                }
            });

        }
        if (element.attributes["id"].nodeValue == 'feedlyTitleBar') {
            if ($('#cacheRefresh').length == 0) {
                var cache = $('.pageActionBar').prepend(cache_refresh);
                $(cache).find('#cacheRefresh').on('click', function () {
                    favicons = generateFavicons();
                    serialize("ffa_cache", favicons);
                    alert('Cache refreshed. Please refresh page.');
                });
            }
        }
    });
})(jQuery);