Writing a userscript...

Ichinisan

Lifer
Oct 9, 2002
28,298
1,236
136
I've recently started using Gmail to handle my work email because I need to be able to filter and sort messages with labels and sub-labels in order to manage everything.

I see the "Invite to Gmail" link almost every time I reply to someone, and I think it might get clicked accidentally someday. Using the Chrome "Inspect Element" option, I see there's a <span> with an ID of "link_invite" and has the "Invite to Gmail" option within the <span> tags. I wrote a script that, I think, should hide the span:

Code:
// ==UserScript==
// @include     https://*.google.com/*
// ==/UserScript==

document.getElementById("link_invite").style = "display:none";

I've only tried this script with Google Chrome. For some reason, it doesn't work. If you are a userscript guru, can you tell me why this doesn't seem to have any effect?

Thanks!

[edit]
I'm guessing the "span" object doesn't exist when the script is run on page load, but is created sometime after the page loads. I guess I need to make it so my script adds an event handler to be executed any time an object is added to the page. When an object with ID "link_invite" is added to the page, it's visibility would be suppressed.

I'll probably fail at figuring this out on my own, but I'll try...
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,835
4,815
75
document.getElementById("link_invite").style = "display:none";
Code:
document.getElementById("link_invite").style.display = "none";
At least that's how I'd do it in Firefox. Give it a try in Firebug.

In any case, you're better off writing a user style for what you want to do. They're simpler and faster.

Edit:
Code:
#link_invite { display:none !important }
 

Ichinisan

Lifer
Oct 9, 2002
28,298
1,236
136
Code:
document.getElementById("link_invite").style.display = "none";
At least that's how I'd do it in Firefox. Give it a try in Firebug.

In any case, you're better off writing a user style for what you want to do. They're simpler and faster.

Edit:
Code:
#link_invite { display:none !important }

Thanks. I think it's cool that Chrome supports userscripts without using an extra add-on, so I made a few and installed them directly in Chrome (Greasemonkey not required). I guess I have to use a plug-in to support userstyles.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,835
4,815
75
I guess I have to use a plug-in to support userstyles.
Yes. But I like it better than Chrome's User Script support, personally.

Edit: Technically, that site will install styles as scripts. You could do one as an example and then create your own script if you wanted. But like I said, user styles are faster: instead of appearing and then disappearing, the link you want to get rid of will never appear.
 
Last edited: