[Greasemonkey] "Bloglines Keep All New Link" User script

Nicola Paolucci durden at gmail.com
Thu Jun 9 01:19:53 EDT 2005


Hi Jeremy,

On 6/8/05, Jeremy Dunck <jdunck at gmail.com> wrote:
> On 6/8/05, Nicola Paolucci <durden at gmail.com> wrote:
> > On 6/3/05, Mark Wubben <markwubben at gmail.com> wrote:
> > > Why do you need to "embed" the JavaScript code?
> >
> > I had tried without embedding the Javascript code into the page but
> > then those functions would not be found when clicking the 'keep all
> > new' link. Probably some simple thing I was missing.
> 
> You have to "export" any GM functions you want to be available outside
> the script itself.
> 
> For those functions, do:
> window.foo = function() {
> 
> }
> 
> instead of :
> function foo() {
> 
> }

It works like a charm, thanks:

// "Bloglines Keep All New Link" User script
// version 0.3
// 2005-06-01
// Copyright (c) 2005, Nicola Paolucci <durden /\t gmail.com>
// Released under the BSD license
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Bloglines Keep All New Link", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Bloglines Keep All New Link
// @namespace http://www.durdn.net/greasemonkey
// @description Adds a new "keep all new" link to every blog page. If
you have a big list of entries in a blog and you are sure you will not
be able to read them in one session. You can click the "keep all new"
link and then untick the entries while you read them one by one.
// @include       http://www.bloglines.com/myblogs_display*
// ==/UserScript==


(function() {
    window.xpath = function(query) {
        return document.evaluate(query, document, null,
                                
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    }

    window.delay = function(gap){ /* gap is in millisecs */
        var then,now; then=new Date().getTime();
        now=then;
        while((now-then)<gap)
            {now=new Date().getTime();}
    }

    window.checkAllKeepNewBoxes = function() {
        allElements = xpath("//input[@type = \'checkbox\']");
        for (var i = 0; i < allElements.snapshotLength; i++) {
            thisElement = allElements.snapshotItem(i);
            prms = thisElement.id.split("-");
            prms[0] = prms[0].substring(4,prms[0].length);
            thisElement.checked = true;
            markUnreadItem(prms[0],prms[1]);
            delay(1000);
        }
    }

    function addKeepAllNewLink() {
        allElements = window.xpath("//ul[@class = 'channel_nav']/li");
        thisElement = allElements.snapshotItem(0);
        if (thisElement) {
            newli = document.createElement('li');
            newli.innerHTML = '<a
href="javascript:checkAllKeepNewBoxes()">keep all new</a>';
            thisElement.parentNode.insertBefore(newli, thisElement);
        }
    }

    if (document.title == "Bloglines | My Blogs") {
        addKeepAllNewLink();
    }
})();

-- Nick


More information about the Greasemonkey mailing list