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/*"))
returntrue;
returnfalse;
}
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).
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.