Don't try to call
GM_
functions from a webpage. (1) It's not directly possible, (2) it's a security risk, (3) it's almost never really necessary.Never use
onclick
in a Greasemonkey script (or at all, really). A simplealert("HELP"); return true;
might work, but anything more will crash and it's bad form anyway.Also, if you use
querySelectorAll
versusgetElementsByTagName
, you can fine-tune what links you process, EG:document.querySelectorAll ("div.main a.user")
-- which would get only those links with the CSS classuser
that were inside the <div> with the classmain
.
In this case, use addEventListener
(or use jQuery) to handle the links so your script code would become like:
var blocklist = JSON.parse (GM_getValue ("blocklist") );
var targlinks = document.querySelectorAll ('a');
for (var J = targlinks.length - 1; J >= 0; --J) {
var targlink = targlinks[J];
if (blocklist.indexOf (targlink.href) >= 0) {
targlink.style.display = 'none';
} else {
targlink.addEventListener ('click', virginLinkHandler, false);
}
}
function virginLinkHandler (zEvent) {
var newURL = zEvent.target.href;
blocklist = blocklist.concat (newURL);
GM_setValue ("blocklist", JSON.stringify (blocklist) );
}