/    Sign up×
Community /Pin to ProfileBookmark

Do I use IF here?

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”);
}

}[/CODE]

Thanks,
Joseph Duffy

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@AlphaWolfauthorSep 29.2010 — If you need any more info, or might help me out with further issues (Nothing major, I'm trying to teach myself), I can be added on MSN <redacted>
×

Success!

Help @AlphaWolf spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...