Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active February 4, 2020 18:49
Show Gist options
  • Save luislobo14rap/36cb7d8a83849ccb65e02209dfede1a2 to your computer and use it in GitHub Desktop.
Save luislobo14rap/36cb7d8a83849ccb65e02209dfede1a2 to your computer and use it in GitHub Desktop.
force-to-https.js
// force-to-https.js v1
function forceToHttps() {
if (location.protocol == 'http:') {
var linkHttps = location.href.replace('http', 'https');
// via location
window.location.protocol = 'https:';
window.location.href = linkHttps;
// via click
var a = document.createElement('a');
a.setAttribute('href', linkHttps);
a.setAttribute('style', 'display: none !important;');
a.click();
// reinforce
setInterval(function() {
window.location.href = linkHttps;
a.click();
}, 3500);
// via meta
var meta = document.createElement('meta');
meta.setAttribute('content', '0;URL=' + linkHttps);
meta.setAttribute('http-equiv', 'refresh');
(document.head || document.getElementsByTagName('head')[0]).append(meta);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment