HTTP-to-HTTPS redirector

Replace http:// with https:// in the address bar, to make sure you're using the SSL-encrypted version of a page. Only enable for pages that you know are SSL enabled.

< Feedback on HTTP-to-HTTPS redirector

Review: OK - script works, but could use improvement

Some improvements

Hey. Thanks for writing this script. I'd like to make some minor suggestions to improve it.

1. Everything inside the wrapping anonymous function can be replaced with a single statement:
location.protocol = "https";

2. If for some reason the first suggestion is rejected (I'm not entirely sure if it works on every browser), you can make the regex replace version error-proof by adding a "^" to the beginning of the regex, so that it would only match at the beginning of the URL string.
location.href.replace(/^http\:/, 'https');

3. As per Greasemonkey documentation, adding the meta-block imperative @grant none to every userscript that doesn't use special APIs is a good security measure (at least for those who are for some reason still using GM 1.x).

Woops, I forgot the most important suggestion.

Please add the following metadata imperative:

// @run-at document-start

This causes the redirection to occur *before* the page is loaded, which is a lot faster, bandwidth-friendly, and saves the user from a potentially frustrating redirection that occurs after the page has been loaded.

(Full info in documentation page.)

Thanks again.

Post reply

Sign in to post a reply.