Recent posts by The Dot

Subscribe to Recent posts by The Dot 50 posts found

Jul 7, 2008
The Dot 50 posts

Topic: Script development / A Scary Thought

I thought greasemonkey does a trace to see that this doesnt happen on the latest versions. (?)

 
Jul 1, 2008
The Dot 50 posts

Topic: Script development / userSTYLES.org - Bandwidth Limit Exceeded

while were at it, i cant access this thing on opera 9.50. the previous version of opera works great though.

and i cant post new scripts.
Status: 500 Internal Server Error Content-Type: text/html
500 Internal Server Error

 
Jun 27, 2008
The Dot 50 posts

Topic: Userscripts.org discussion / Userscripts Forum Navigation by Keyboard Script

Hi, I wrote a script for moving around the userscripts forums using shortcut keys :)
j - next
k - previous
u - up

I wouldve created a new script but i get this error when i try to :

Status: 500 Internal Server Error Content-Type: text/html
500 Internal Server Error

Further, no page on this site now opens on opera. Can somebody please help with these issues? Thanks.

Heres the script:


// Userscripts Forum Navigation 1.0

// ==UserScript==
// @name           Userscripts Forum Navigation
// @namespace      http://dotthought.blogspot.com
// @description    Adds shortcuts for forum navigation
// @include        http://userscripts.org/forums*
// ==/UserScript==

var LOADEVENT;
if(window.opera) LOADEVENT = 'DOMContentLoaded';
else LOADEVENT = 'load';

window.addEventListener(LOADEVENT, function() // why doesnt DOMContentLoaded work on firefox?
{
    if(loc().length == 31 || loc().length == 32) //we check if its at a page like http://userscripts.org/forums/1
    {
        var pni = {}; // prev next info
        pni['fn'] = forumN(); //forum number
        
        var x = xp('//a[@class="entry-title"]'); //links
        var li = function(n)
        {
            if(n>=0 && n<x.snapshotLength) return x.snapshotItem(n)
            else return null;
        };
        
        var getTopicNFromLink = function(s)
        {
            if(s) return getTopicN(s.href);
            else return null;
        }
        
        for(var i=0; i<x.snapshotLength; i++)
        {
            pni[li(i).firstChild.nodeValue] = {
                p: getTopicNFromLink(li(i-1)),
                n: getTopicNFromLink(li(i+1))
            }
        }
        
        if(typeof(GM_setValue)!='undefined') GM_setValue('pni'+forumN(), pni.toSource());
        else createCookie('pni'+forumN(), toSourceOpera(pni));
        
        var selected = undefined; // currently selected link
        window.addEventListener('keydown', keyHandler(
        {
            74: function() // j
            {
                if(typeof(selected)!='undefined')
                {
                    li(selected).style.backgroundColor = '';
                    selected++;
                    if(!li(selected))
                    {
                        var nlink = xp('//a[text()="Next »"]');
                        if(nlink.snapshotLength)
                        {
                            gotoLink(nlink.snapshotItem(0));
                        }
                        selected--;
                    }
                }
                else
                    selected=0;
                li(selected).style.backgroundColor = '#eee';
            },
            75: function() // k
            {
                if(typeof(selected)!='undefined')
                {
                    li(selected).style.backgroundColor = '';
                    selected--;
                    if(!li(selected))
                    {
                        var nlink = xp('//a[text()="« Previous"]');
                        if(nlink.snapshotLength)
                        {
                            gotoLink(nlink.snapshotItem(0));
                        }
                        selected++;
                    }
                }
                else
                    selected=0;
                li(selected).style.backgroundColor = '#eee';
            },
            85: function() // u
            {
                msg('Up');
                window.location = 'http://userscripts.org/forums';
            },
            13: function(){this.open();}, // enterkey
            79: function(){this.open();}, // o
            open: function()
            {
                if(!li(selected))
                {
                    selected=0;
                    msg('Opening first thread');
                }
                else
                {
                    msg('Open');
                }
                gotoLink(li(selected));
            }
        }), true);
        
        msg('Shortcuts setup complete');
    }
    else if(loc().length>32) // specific thread
    {
        var pni;
        if(typeof(GM_getValue)!='undefined') pni=eval(GM_getValue('pni'+forumN()));
        else pni=eval('var evalobj='+readCookie('pni'+forumN())+';');
        if(!pni) return;
        
        var i;
        var head = (''+document.getElementById('topic-title').firstChild.nodeValue.match(/[^ \n].*/)).replace('\n','');
        for(i=head.length-1; head.charAt(i)==' '; i--);
        head = head.slice(0,i+1);
        
        window.addEventListener('keydown', keyHandler(
        {
            74: function()
            {
                if(pni[head])
                {
                    if(pni[head].n)
                    {
                        msg('Next');
                        window.location = pni[head].n;
                    }
                    else
                    {
                        msg('No next thread. Up');
                        this.goUp();
                    }
                }
                else
                    msg('Next thread failed');
            },
            75: function()
            {
                if(pni[head])
                {
                    if(pni[head].p)
                    {
                        msg('Previous');
                        window.location = pni[head].p;
                    }
                    else
                    {
                        msg('No previous thread. Up');
                        this.goUp();
                    }
                }
                else
                    msg('Previous thread failed');
            },
            85: function()
            {
                msg('Up');
                this.goUp();
            },
            goUp: function()
            {
                window.location = loc().slice(0,31);
            }
        }), true);
        
        msg('Shortcuts setup complete');
    }
    else if(loc().length<31) // forums list
    {
        var x = xp('//a[@class="title"]'); //links
        var li = function(n)
        {
            if(n>=0 && n<x.snapshotLength) return x.snapshotItem(n)
            else return null;
        };
        
        var selected = undefined; // currently selected link
        window.addEventListener('keydown', keyHandler(
        {
            74: function() // j
            {
                if(typeof(selected)!='undefined')
                {
                    li(selected).style.backgroundColor = '';
                    selected++;
                    if(!li(selected))
                    {
                        selected--;
                    }
                }
                else
                    selected=0;
                li(selected).style.backgroundColor = '#eee';
            },
            75: function() // k
            {
                if(typeof(selected)!='undefined')
                {
                    li(selected).style.backgroundColor = '';
                    selected--;
                    if(!li(selected))
                    {
                        selected++;
                    }
                }
                else
                    selected=0;
                li(selected).style.backgroundColor = '#eee';
            },
            85: function() // u
            {
                msg('Up');
                window.location = 'http://userscripts.org/';
            },
            13: function(){this.open();}, // enterkey
            79: function(){this.open();}, // o
            open: function()
            {
                if(!li(selected))
                {
                    selected=0;
                    msg('Opening first category');
                }
                else
                {
                    msg('Open');
                }
                gotoLink(li(selected));
            }
        }), true);
        
        msg('Shortcuts setup complete');
    }
}, true);

function keyHandler(handlers)
{
    return function(e)
    {
        if(e.target)
        {
            var n = e.target.nodeName.toLowerCase();
            if(n=='textarea' || (n=='input' && e.target.type.toLowerCase()=='text')) return;
        }
        if(e.altKey || e.ctrlKey || e.metaKey) return;
        
        var k = e.keyCode;
        if(k in handlers) handlers[k]();
    }
}

function msg(m)
{
    if(!document.getElementById('tdNaviMsg'))
        document.getElementById('right').appendChild(makeDOM(
        {
            $t: 'span',
            id: 'tdNaviMsg',
            style:
            {
                padding: '3px',
                backgroundColor: '#eee'
            }
        }));
    document.getElementById('tdNaviMsg').innerHTML = m;
}

function forumN()
{
    return loc().charAt(30);
}

function getTopicN(s)
{
    return(s.substring(39, 39+4));
}

// UTIL FUNCTIONS

function toSourceOpera(o) //why does opera not have this? :(
{
    var s='{';
    for(var n in o)
    {
        s+="'"+n+"':";
        if(!o[n]) s+='null';
        else if(typeof(o[n])=='null') s+='null';
        else if(typeof(o[n])=='undefined') s+='undefined';
        else if(typeof(o[n])=='object') s+=toSourceOpera(o[n]);
        else s+="'"+o[n]+"'";
        s+=',';
    }
    s=s.substring(0,s.length-1)
    s+='}';
    return s;
}

function gotoLink(a)
{
    window.location = a.href;
}

function loc()
{
    var l = window.location.href;
    var qpo = l.indexOf('?');
    if(qpo!=-1) l=l.substring(0,qpo);
    return l
}

function xp(q, con)
{
    return document.evaluate(q, con || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}

function createCookie(name,value,days) { // modified from http://www.quirksmode.org/js/cookies.html
        days = days || 100;
        var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name, def) { // modified from http://www.quirksmode.org/js/cookies.html
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return def;
}

function makeDOM(o) // from http://dotthought.blogspot.com/2008/05/making-dom-elements-using-objects.html
{
    if('$dom' in o) return o.$dom;
    
    var el = document.createElement(o.$t);
    for(var i in o)
    {
        if(i != '$t' && i != '$c' && i != '$e') //not tagname or children or events
        {
            if(typeof(o[i]) != 'object')
                el[i]  = o[i];
            else
                for(var j in o[i])
                {
                    el[i][j] = o[i][j];
                }
        }
    }
    if('$c' in o)
    {
        for(var i=0; i<o.$c.length; i++)
        {
            el.appendChild(makeDOM(o.$c[i]));
        }
    }
    if('$e' in o)
    {
        for(var i in o.$e)
        {
            el.addEventListener(i, o.$e[i], false);
        }
    }
    return el;
}

/*
// cant reach these functions :( graesemonkey stack trace restrictions?
var setValue = GM_setValue || createCookie;
var getValue = GM_getValue || readCookie;

function set(n,o)
{
    setValue(n,o.toSource());
}
function get(n,d)
{
    if(getValue(n)) return(getValue(n).eval());
    else return(d);
}
*/

I will keep trying to create a new script for this, but until then, i thought this might be of use to somebody.

 
Jun 10, 2008
The Dot 50 posts

Topic: Script development / setAttribute not working?

form.addEventListener('event', function
{
//do this on event
//blah blah blah
}, true);

event is the event name.
generally just remove "on"
i.e. onClick -> click

 
Jun 10, 2008
The Dot 50 posts

Topic: The Banana Bar / proxys

idk if this works, but shouldnt tor (http://www.torproject.org/) let you get past any of those pesky filters? has anybody tried this? (i think i might have similar issues shortly ;) so i second the need for a service like that)

 
Jun 7, 2008
The Dot 50 posts

Topic: Ideas and script requests / Lists of Google Docs files in bookmark

have you tried the google docs gadget?

 
May 29, 2008
The Dot 50 posts

Topic: Ideas and script requests / My small greasemonkey tutorial

http://www.css3.info/selectors-test/test.html :D

pity firefox 3 is *stilllll* behind

 
May 29, 2008
The Dot 50 posts

Topic: Ideas and script requests / My small greasemonkey tutorial

css pseudo selectors? not always but loads of times :)

 
May 18, 2008
The Dot 50 posts

Topic: Script development / StumbleUpon - interacting with add-ons

someIframe.contentDocument.evaluate
and be sure to specify the same for the context too.

 
May 10, 2008
The Dot 50 posts

Topic: Script development / Unlock and view any private Myspace profile and photo by scripts

as regards the script, does anybody think its possible? i dont think they use some javascript thing for that anyway...

 
May 10, 2008
The Dot 50 posts

Topic: Script development / Unlock and view any private Myspace profile and photo by scripts

georgez71: "maybe its my underaged daughters myspace."

me: scowls

 
May 5, 2008
The Dot 50 posts

Topic: Script development / Storing JavaScript Objects

@dob: very nice :)

im sorry :) you're right i didnt read it.

 
May 4, 2008
The Dot 50 posts

Topic: Script development / Storing JavaScript Objects

@aquilax: very nice :)

 
May 3, 2008
The Dot 50 posts

Topic: Script development / moularization of scripts

I *thought* greasemonkey does something like wrap in an anonymous function, execute, and throw away?

If that was the case, this wouldnt be possible.

However, if you set your functions under a global namespace i.e. object, then you could access them in different scripts.

 
May 3, 2008
The Dot 50 posts

Topic: Script development / Storing JavaScript Objects

set(obj)
{
for(var i in obj)
GM_setValue(i+'_store',obj[i]);
}

get(obj)
{
for(var i in obj)
obj[i]=GM_getValue(i+'_store',obj[i]);
}

 
Apr 30, 2008
The Dot 50 posts

Topic: Ideas and script requests / Eye Strain Fix

opera.
hehe >:)

 
Apr 27, 2008
The Dot 50 posts

Topic: Ideas and script requests / Note - To - Self

Google Notebook extension ? Doesnt pop up thought. But its still nice.

 
Apr 23, 2008
The Dot 50 posts

Topic: Script development / gmail reply & forward

You need to set an event handler on the reply link. When its clicked, wait for the text to load. It loads in an iframe. You can change the text by changing the html in the iframe.

Things to watch out for:
1. you need to use top.contentWindow.getElementById('canvas_frame').contentWindow.getElement ...
instead of window.getElement because the greasemonkey script is loaded many times on different contentWindows
2. you need to wait for the message to load in the iframe. It doesnt immediately load when you click reply, its fetched via xhr. you can poll for this - window.setTimeout(function() { if(iframe exists) {do something with iframe} else {window.setTimeout again} } , 100)

i hope this is enough to get you started.

 
Apr 22, 2008
The Dot 50 posts

Topic: Script development / reading a variable out of an iframe parent

im not sure of the original source of the question, but it could have to do with greasemonkey. on a page with frames, sometimes the script will be run on each window (or each frame). so in that case, it might be useful.

 
Apr 18, 2008
The Dot 50 posts

Topic: Script development / reading a variable out of an iframe parent

function() {
alert(top.foo);
}

 
Apr 14, 2008
The Dot 50 posts

Topic: Script development / gmonkey + firefox3b5 issue

the latest firebug version crashes too.
and i forgot to mention that its only gmail that it crashes on.
oh well...

 
Apr 14, 2008
The Dot 50 posts

Topic: Script development / gmonkey + firefox3b5 issue

nope. it just works okay all by itself.
maybe it updated itself sometime ive got version 1.1.0b10
--edit - hmm it didnt update all by itself... ill go do that now---

"scripts not work in ff3b5 but work in ff2"

yeah this works in ff2 but not in ff3b5 like you said.
but the weird thing is that the script used to work with ff3b4.
and google's "official" script example doesnt work (though its really simple)
this led me to believe that there was something wrong with the api itself, or the way beta5 handles it.
and the fact that it works when the caches empty (i.e. on first time load) but not later. thats even weirder. i wonder why that could happen.

 
Apr 14, 2008
The Dot 50 posts

Topic: Script development / gmonkey + firefox3b5 issue

The google api doesnt seem to work well with firefox 3 beta 5. Any script that uses it will load the object the first time the page is loaded but will fail to do so any time after that, for example on refreshing the page. Clearing the cache will allow your script to work for another load.

Example script that fails:
http://code.google.com/p/gmail-greasemonkey/wik...

Just thought i would post this in case anybody has a similar problem.

... and the latest beta crashes firebug :( :(

 
Mar 19, 2008
The Dot 50 posts

Topic: Script development / event listener

is the pi_XHR object set as a property of the window?

i.e window.pi_XHR = {...} versus pi_XHR = {...}

 
Mar 17, 2008
The Dot 50 posts

Topic: Ideas and script requests / Google Notebook - possible to edit?

Sure its possible :)

Maybe its because a few scripts were created before Google changed the Notebook (thats quite an ancient change btw but a lot of scripts are old too ;) )