Source for "Ma.gnolia Condenser"

By David Eason
Has 1 other script.


// ==UserScript==
// @name        Ma.gnolia Condenser
// @namespace   http://www.freewebs.com/daddydave
// @description Fits more bookmarks on a screen for ma.gnolia users and makes the lock icon for private bookmarks conspicuously red.
// @include     http://ma.gnolia.com/
// @include     http://ma.gnolia.com/tags/*
// @include     http://ma.gnolia.com/people/*
// @include     http://ma.gnolia.com/people/*/tags/*
// @include     http://ma.gnolia.com/groups/*
// @include     https://ma.gnolia.com/
// @include     https://ma.gnolia.com/tags/*
// @include     https://ma.gnolia.com/people/*
// @include     https://ma.gnolia.com/people/*/tags/*
// @include     https://ma.gnolia.com/groups/*
// @version     March 7, 2007

// ==/UserScript==
// Suggestions and bug reports may be sent to David Eason at daddydave (this is a gmail address)

(function(){
var strXBase = '//div[id("hotmarks")]/ol/li/p[2]|//div[id("featlinkers")]/ol/li/p[2]' +
               '|//div[id("featlinkers")]/div[contains(concat(" ", @class, " "),concat(" ", "column", " "))]/ol/li/p[2]';
               
var strXDetailMode = "//div[@id='contain']/div[@id='main']/p[1]/a[1]/@href";

// data URI for red padlock
uriClosedPadlock =
    'data:image/gif,GIF89a%10%00%10%00%B2%00%00%FF%FF%FF%FF%00%00%FF%99%99%FFff%CC%FF%FF' +
    '%FF%CC%FF%CC%99%99%FF%FF%CC%2C%00%00%00%00%10%00%10%00%00%03-%08%B1%DC%AD.J%26%00%10%93' +
    '%821n%0E%DB%D2%7D%D0RJ%E7%E9X%2C%3B%5DB%2C%BF%AD%85%A1rN%D7w%04%E7%BD%8Fp%A8%CA%00%12%00%3B';

function getXPathList (strXPath, startNode) {
    var x = document.evaluate(strXPath, startNode, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    if (!x) GM_log('Node matching '+ strXPath + ' not found');
    return x;
}

function moveElement(srce, dest) {
    if (srce && dest) {
        if (dest.appendChild) dest.appendChild(srce);
    }
}

function httpHostName(str) {
    var parts = String(str).split('/');
    if (!parts) return '';
    if ((parts[0] == 'http:' || parts[0] == 'https:') && parts.length >=3) {
        return parts[2];
    }
    return '';
}

function addGlobalStyle(css) {
// from http://diveintogreasemonkey.org/patterns/add-css.html
    var head, style;
    head = document.getElementsByTagName ('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

function makeover() {

    addGlobalStyle('\
        #contain {padding: 0 ! important;}\
        #sidebar {padding: 0 ! important;}\
        .tagsnmore {border-top: 1px solid rgb(153, 153, 102) ! important; }\
        .tagsnmore li.tags, .tagsnmore li.details{border: 0 ! important; padding: 0 ! important;}\
        .tagsnmore li.tags {padding: 0 ! important;}\
        li.actions, li.actions .icon{ display:inline ! important;}\
        #main p.desc { font-size: .85em;}\
        #main li { padding: 0 ! important;}\
        #main ul { padding: 0 ! important;}\
        #main h3 a {padding: 0 ! important;}\
        #main h3 {padding: 0 ! important;}\
        #main h1 {padding: 0;}\
        #navbar {padding:0;}' );

    var allMarks = getXPathList(strXBase, document);

    var thisMark, actionItem, goLink, imgGoto, title;
    var goLinks = [];
    var imgGotos = [];
    var originalUrl, hostName, faviconUrl;
    
    var hasActionsNode = getXPathList('//ul/li[contains(concat(" ", @class, " "),concat(" ", "actions", " "))]', document);
    var hasActions = (hasActionsNode && hasActionsNode.snapshotLength >= 1);

    for (var i = 0; i < allMarks.snapshotLength; i++) {

        // replace goto icon with favicon
        thisMark = allMarks.snapshotItem(i);
        goLinks = getXPathList('//img[contains(@src,"goto.gif")]/parent::a', thisMark);
        if (goLinks) goLink = goLinks.snapshotItem(0);

        imgGotos = getXPathList('//img[contains(@src,"goto.gif")]', thisMark);
        if (imgGotos) imgGoto = imgGotos.snapshotItem(0);

        title = goLink.getAttribute ("title");
        originalUrl = title.match("Visit (.*)");
        if (originalUrl) {
            // not using Niklas Malmgren's Ma.gnolia link fixer
            hostName = httpHostName(originalUrl[1]);
        }
        else {
            // using Niklas Malmgren's Ma.gnolia link fixer
            hostName = httpHostName(goLink.getAttribute("href"));
        }

        // set favicon
        if (hostName != '') {
            faviconUrl = 'http://' + hostName + '/favicon.ico';
        }
        imgGoto.setAttribute ('src', faviconUrl);

        // in testing, autohotkey had a 32x32 favicon so:
        imgGoto.setAttribute ('style', "width: 16px; height: 16px;");

        // find favicons that didn't load
        // dead bookmarks may not trigger the error event and so may show
        // the original goto.gif icon. This is a feature ;)
        imgGoto.addEventListener('error', function(e) {
            this.setAttribute ('src', 'http://ma.gnolia.com/favicon.ico');
        }, true);

        actionItem = getXPathList('../ul/li[contains(concat(" ", @class, " "),concat(" ", "actions", " "))]', thisMark);
        if (hasActions) {
           allMarks.snapshotItem(i).appendChild(document.createTextNode(" | "));
           moveElement(actionItem.snapshotItem(0), allMarks.snapshotItem (i));
        }

    }

    var imgPadlock;
    var imgPadlocks = getXPathList('//img[contains(@src,"/privacy-on.gif")]', document);

    for (var i = 0; i < imgPadlocks.snapshotLength; i++) {
        imgPadlock = imgPadlocks.snapshotItem (i);
        imgPadlock.src = uriClosedPadlock;
    }

}

window.addEventListener(
    'load',
    function() { makeover() },
    true);

})()