...

View Full Version : Greasemonkey 'Component is not available'



1212jtraceur
12-27-2006, 03:30 AM
Thanks to Ancora, I now have a far better function for 'mailto:' anchor redirection.



// ==UserScript==
// @name mailto2alert
// @namespace http://1212jtraceur.memebot.com/
// @description Changes 'mailto:EMAIL_ADDRESS' anchors to 'alert(EMAIL_ADDRESS)' anchors. This is useful for those who would like email addresses displayed to them, so that they may use a non-default mail application, such as Gmail.
// @include *
// ==/UserScript==

(function mailto2alert()
{
var nAddr = [];
var n = 0;
var nLink = document.getElementsByTagName('a');
for (i=0; i<nLink.length; i++)
{
if (/^mailto/.test(nLink[i].href))
{
nAddr[nAddr.length] = nLink[i].href.replace(/^mailto:/,"").replace(/\?/,"|").replace(/\&/,"|");
nLink[i].href = nLink[i].href.replace(nLink[i].href,"#");
nLink[i].id = "m"+n++;
nLink[i].onclick = function()
{
var nIndex = this.id.replace("m","");
alert(nAddr[nIndex].replace(/\|/g,"\n"));
return false;
};
}
}
})();


However, Greasemonkey is giving me:



Component is not available


I'm new to Greasemonkey, and have no idea how to fix this. I would post elsewhere, but I couldn't find a forum for user script development help. If anyone is familiar with Greasemonkey, I would really appreciate their help.

Thanks,
1212jtraceur

Ancora
12-27-2006, 11:26 AM
1212jtraceur:

That is NOT the code I posted. I did NOT delcare the array INSIDE the function. And the onload=init is missing.

Test the code I posted AS IS. I will never understand what is so difficult for so many to understand about AS IS. There's the code, it's sitting there, just copy it, save it as an .html document, then open it. What is so difficult about that? But no, instead, you decide that "this" needs to be changed, "that" needs to be modified, "something else" will be ignored.

Greasemonkey my ... TEST CODE THAT IS POSTED FOR YOU AS IS! Stop being a waste of time, my time and that of anyone else generous enough to ever help you again.

dumpfi
12-27-2006, 12:34 PM
@Ancora: Don't be so rude. Even if you write "provided AS-IS" in big red flashing letters above your code, no one is forced to use your code AS-IS.

@Topic:
The ? in one regexp is not escaped, and the code must be executed onload.

Here's a working version:
// ==UserScript==
// @name mailto2alert
// @namespace http://1212jtraceur.memebot.com/
// @description Changes 'mailto:EMAIL_ADDRESS' anchors to 'alert(EMAIL_ADDRESS)' anchors. This is useful for those who would like email addresses displayed to them, so that they may use a non-default mail application, such as Gmail.
// @include *
// ==/UserScript==

function mailto2alert()
{
var nAddr = [];
var n = 0;
var nLink = document.getElementsByTagName('a');
var i;
for (i=0; i<nLink.length; i++)
{
if (/^mailto/.test(nLink[i].href))
{
nAddr[nAddr.length] = nLink[i].href.replace(/^mailto:/,"").replace(/\?/,"|").replace(/&/,"|").replace(/\|/g,"\n");
nLink[i].href = nLink[i].href.replace(nLink[i].href,"#");
nLink[i].id = "m"+n++;
nLink[i].onclick = function()
{
var nIndex = this.id.replace("m","");
alert(nAddr[nIndex]);
return false;
};
}
}
}
window.onload = mailto2alert; dumpfi

Ancora
12-27-2006, 01:06 PM
dumpfi:

I don't take orders from you. If you don't like what I post, shove it. I'll tell people to test my code AS IS, whether you like it or not, and whether you run your mouth about it or not.

1212jtraceur
12-27-2006, 02:26 PM
1212jtraceur:

That is NOT the code I posted. I did NOT delcare the array INSIDE the function. And the onload=init is missing.

Test the code I posted AS IS. I will never understand what is so difficult for so many to understand about AS IS. There's the code, it's sitting there, just copy it, save it as an .html document, then open it. What is so difficult about that? But no, instead, you decide that "this" needs to be changed, "that" needs to be modified, "something else" will be ignored.

Greasemonkey my ... TEST CODE THAT IS POSTED FOR YOU AS IS! Stop being a waste of time, my time and that of anyone else generous enough to ever help you again.

Woah, calm down, man. I know that's not the exact code, and I'm not blaming you for the problem. I did mean the thanks I gave you at the beginning of the thread, it wasn't sarcasm.

The reason I modified it is that it will be used within Greasemonkey, hence nullifying the need for window.onload = init. The array is inside the function to get rid of global variables, and to make the code look nicer.

I found that the problem was nLink[i].onclick = ...; Greasemonkey scripts do not support this, for security reasons, I think. Instead, I must use nLink[i].addEventListener(...), which does work.

However, the hrefs are not working, but I think I see why, and will attempt to fix it.

Thanks to both of you for your help,
1212jtraceur

EDIT:

It didn't take too long to fix. Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum