🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/02/02 03:21:52
🔄 下次更新时间:2026/02/02 04:21:52
手动刷新缓存

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 has bugs

§
Posted: 2014-09-27
Edited: 2014-09-27

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).

Cheers.

§
Posted: 2014-09-27

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.