-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps_everywhere.js
More file actions
29 lines (27 loc) · 843 Bytes
/
Copy pathhttps_everywhere.js
File metadata and controls
29 lines (27 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// ==UserScript==
// @name HTTPS Everywhere
// @namespace github.com/haithamaouati
// @version 1.0
// @description Always use HTTPS; redirect all URLs from HTTP to HTTPS.
// @author Haitham Aouati
// @run-at document-start
// @match http://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
/**
* Logic:
* 1. Check protocol.
* 2. Attempt redirection using location.replace.
* 3. Catch and log errors to prevent script termination.
*/
try {
if (window.location.protocol === "http:") {
const secureUrl = window.location.href.replace(/^http:/, 'https:');
window.location.replace(secureUrl);
}
} catch (error) {
console.error(`[HTTPS Everywhere] Redirection failed: ${error.message}`);
}
})();