what is wrong with my javascript?

closed account (Dy7SLyTq)
im writing an addon for this site that auto appends a signature when you make post a topic or a thread, but im having some trouble with my regex. right now it just dynamically loads an alert to tell me if im on cplusplus.com but its doing it on every site

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require("sdk/tabs").on("ready", CatchURL);

function CatchURL(tab) {
    if(IsCorrectSite(tab)){
        tab.attach({
            contentScript: "alert(\"" + tab.url + "\");"
        });
    }
}

function IsCorrectSite(tab)
{
    var Site = new String(tab.url);

    if(Site.search("http(s)?://www.cplusplus.com/*"))
        return true;

    return false;
}
Maybe try making your regex more exclusive?
^https?://www\.cplusplus\.com/.*
(Don't forget to escape backslashes as necessary.)
closed account (Dy7SLyTq)
i tried that but it didnt work at all. now when i go to c++ it doesnt even register it
Weird. No idea what kind of regex syntax it uses, then. http://regexpal.com/ says the expression is alright.
closed account (Dy7SLyTq)
thanks for the help anyways :p. i broke down and made an account on daniweb to ask
Doesn't Javascript (or JQuery) have a URI class or something? If it does you might be able to extract the domain name from the URL instead of using regexes (directly).
closed account (3qX21hU5)
Doesn't Javascript (or JQuery) have a URI class or something? If it does you might be able to extract the domain name from the URL instead of using regexes (directly).


window.location might be what you are looking for but I am not the greatest with JavaScript to be honest so I am not to sure.

https://developer.mozilla.org/en-US/docs/Web/API/window.location?redirectlocale=en-US&redirectslug=DOM%2Fwindow.location

https://developer.mozilla.org/en-US/docs/Web/API/Location
@Zereo
That's it.

@DTSCode
Just compare window.location.hostname with 'cplusplus.com'.
closed account (Dy7SLyTq)
can i still use that with the firefox api?
Yes, it's standard HTML DOM which all modern browsers support.
closed account (Dy7SLyTq)
awesome. thanks!
Topic archived. No new replies allowed.