I've got this script I wrote to add links to the google gbar and
remove the original links. I'd like to add a type of button/link
looking thing to the gbar that calls a function when clicked. Here's
the code as is.

CODE
// ==UserScript==
// @name           MySimpleGbar
// @namespace      http://diveintogreasemonkey.org/download/
// @description       Simple way to replace the google gbar.
// @include        http://*.google.com/*
// @copyright       Spider with addLink() from JoeSimmons.
// ==/UserScript==

function id(ID) {
if(ID) { return document.getElementById(ID); }
else { return false; }
}

//               arg1       arg2           arg3    arg4        arg5
// Syntax: addLink('link text', 'link href', 'class', 'target', 'id of
node');
function addLink(arg1, arg2, arg3, arg4, arg5) {
if(arg1 && arg2) {
var n, a;
n=(arg5)?id(arg5):id('gbar');
a = document.createElement('a');
// Make the 1st argument the link text
if(arg1) {a.appendChild(document.createTextNode(arg1));}
// Make the 2nd argument the link href
if(arg2) {a.href = arg2;}
// Make the 3rd argument the link's class
if(arg3) {a.setAttribute('class', arg3);}
// Make the 4th argument the link's target
if(arg4) {a.setAttribute('target', arg4);}
// Add it to the variable gbar
n.appendChild(document.createTextNode(' '));
n.appendChild(a);
}
}

//target attribute
//_blank: new browser
//_self:  replace current page
//_parent:replace page called from
//_top:   current browser

// ADD THE LINKS HERE
addLink('Web', 'http://www.google.com/ig?hl=en', 'gb1', '_self',
'gbar');
addLink('Gmail', 'http://mail.google.com/mail/?hl=en&tab=wm', 'gb1',
'_self', 'gbar');
addLink('Documents', 'http://docs.google.com/?hl=en&tab=wo#all',
'gb1', '_self', 'gbar');
addLink('Calendar', 'http://www.google.com/calendar/render?tab=oc',
'gb1', '_self', 'gbar');
addLink('Sites', 'http://sites.google.com/?tab=c3', 'gb1', '_self',
'gbar');
addLink('Maps', 'http://maps.google.com/maps?hl=en&tab=vl','gb1',
'_self', 'gbar');
// Remove comments to add these links
//===================================
//addLink('Images', 'http://images.google.com/imghp?hl=en&tab=wi',
'gb1', '_self', 'gbar');
//addLink('News', 'http://news.google.com/nwshp?hl=en&tab=wn', 'gb1',
'_self', 'gbar');
//addLink('Shopping', 'http://www.google.com/prdhp?hl=en&tab=nf',
'gb1', '_self', 'gbar');
//addLink('Video', 'http://video.google.com/?hl=en', 'gb1', '_self',
'gbar');
//addLink('Groups', 'http://groups.google.com/grphp?
hl=en&tab=vg&pli=1', 'gb1', '_self', 'gbar');
//addLink('Books', 'http://books.google.com/bkshp?hl=en&tab=gp',
'gb1', '_self', 'gbar');
//addLink('Scholar', 'http://scholar.google.com/schhp?hl=en&tab=ps',
'gb1', '_self', 'gbar');
//addLink('Finance', 'http://finance.google.com/finance?hl=en&tab=pe',
'gb1', '_self', 'gbar');
//addLink('Blogs', 'http://blogsearch.google.com/?hl=en&tab=eb',
'gb1', '_self', 'gbar');
//addLink('YouTube', 'http://www.youtube.com/?tab=b1', 'gb1', '_self',
'gbar');
//addLink('Photos', 'http://picasaweb.google.com/home?tab=cq', 'gb1',
'_self', 'gbar');
//addLink('Reader', 'http://www.google.com/reader/view/?tab=qy',
'gb1', '_self', 'gbar');
//addLink('More', 'http://www.google.com/intl/en/options/', 'gb1',
'_self', 'gbar');
// To add a custom link use the following syntax
// addLink('link text', 'link href', 'class', 'target', 'id of node');
// ADD THE LINKS HERE

// REMOVE LINKS HERE
// This will remove the original gbar links
var gbar = document.getElementById('gbar');
gbar.removeChild(gbar.firstChild);
// REMOVE LINKS HERE
/CODE

This is part of the function that I want to call when the button/link
is clicked:

CODE
function Custom()
{
     var LinkText = prompt("Enter the link text:", "");
     var Link = prompt("Enter the URL:", "");
     addLink(LinkText, Link, 'gb1', '_self', 'gbar');
}
/CODE

Also, I was wondering if there's an easy way to write to text files in
Javascript. I'd like to be able to either append the new link into the
actual script text file or keep and write/read the new links from a
text file.
Thanks for any help.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to