Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Posts
    206
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Greasemonkey 'Component is not available'

    Thanks to Ancora, I now have a far better function for 'mailto:' anchor redirection.

    PHP Code:
    // ==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 
    0;
        var 
    nLink document.getElementsByTagName('a');
        for (
    i=0i<nLink.lengthi++)
        {
            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

  • #2
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Last edited by Ancora; 12-27-2006 at 12:34 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    @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:
    Code:
    // ==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
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #4
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Posts
    206
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ancora View Post
    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!
    Last edited by 1212jtraceur; 12-27-2006 at 11:02 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •