Hey,
I’ve been working on a Safari Extension for a few weeks now, and actually posted here for some initial help, thanks.
It’s evolved a bit now. But, I’m stuck again.
First, I’ll explain what it does.
It checks for the current URL, checks the users settings, and changes the URL appropriately. I’d like to add the ability to change the URL back (IE from .co.uk to.com), but can’t get the right command to get it work so it doesn’t simply change it from co.uk to .com then straight back, any ideas?
I also need some help on another subject, I’d like to make sure my code is efficient, so if you notice anything that seems ‘horrible’ please tell me ?
Here’s my current code (With bits missing so it can’t be completly copied):
[CODE]{
// Checks the command is to change the URL.
if (event.command !== “ChangeURL”)
return;
// Get the current tab’s URL. This URL can be undefined if the
// page is blank or the user is at a page like Top Sites. To
// get the URL, the extension must have permissions to access
// the page at that URL. The Web Site Access Level setting in
// the Extension Builder controls this. This particular extension
// wants an access level of “All” so that it can change all URLs.
var currentURL = event.target.browserWindow.activeTab.url;
// Sets myVolume to the users prefernces, alowing changes of .co.uk, .fr etc.
var myVolume = safari.extension.settings.URLSettings;
if (currentURL)
// Checks the users prefences, if preferences says “.co.uk”, change .com to .co.uk
if (myVolume == ‘.co.uk’) {
event.target.browserWindow.activeTab.url = currentURL.replace(/.com/ig, “.co.uk”);
}
// Checks the users prefences, if preferences says “.fr”, change .com to .fr
if (myVolume == ‘.fr’) {
event.target.browserWindow.activeTab.url = currentURL.replace(/.com/ig, “.fr”);
}
// Checks the users prefences, if preferences says “.de”, change .com to .de
if (myVolume == ‘.de’) {
event.target.browserWindow.activeTab.url = currentURL.replace(/.com/ig, “.de”);
}
}
Thanks,
Joseph Duffy