// ==UserScript==
// @name          delicious >> my web
// @namespace     http://www.rhyle.org/gm/
// @description   Add "copy this link to Yahoo My Web" in del.icio.us
// @include       http://del.icio.us/*
// ==/UserScript==
function gm_xpath(what,where) {
	return document.evaluate(what,where,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
}

allH3s = gm_xpath("//h4[@class='desc']",document);
allDesc = gm_xpath("//div[@class='extended']",document);
allMeta = gm_xpath("//div[@class='meta']",document);

for (i=0; i<allH3s.snapshotLength; i++) {
	
	theURL = allH3s.snapshotItem(i).firstChild.href;
	theTitle = allH3s.snapshotItem(i).firstChild.innerHTML;
	theDesc = (allDesc.snapshotItem(i)) ? allDesc.snapshotItem(i).innerHTML : '';
	theMeta = allMeta.snapshotItem(i);
		
	meta = allMeta.snapshotItem(i);
	theTags = meta.innerHTML.split('...')[0];
	theTags = theTags.split('by')[0];
	theTags = theTags.replace('to ','');
	theTags = theTags.split('</a> ');
	for (k in theTags){
		theTags[k] = theTags[k].replace(/<a[^>]*>/i , "");
	}
	theTags.join(", ");
	
	yURL = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?' 
             + 'u='  + encodeURIComponent(theURL)
             + '&t=' + encodeURIComponent(theTitle)
             + '&d=' + encodeURIComponent(theDesc)
             + '&tag=' + encodeURIComponent(theTags);
        
        yLink = ' ... <a title="Copy this to Yahoo! My Web" href="'+yURL+'">&raquo;Y!</a>';
        allMeta.snapshotItem(i).innerHTML += yLink; 
}
