Skip to content

Instantly share code, notes, and snippets.

@D1SoveR
Created December 13, 2010 00:13
Show Gist options
  • Save D1SoveR/738488 to your computer and use it in GitHub Desktop.
Save D1SoveR/738488 to your computer and use it in GitHub Desktop.
Greasemonkey Script for Facebook HTTPS
// ==UserScript==
// @name Facebook HTTPS-ifier
// @namespace Facebook
// @description Converts all links pointing to Facebook to use HTTPS.
// @author Mikolaj "D1SoveR" Banasik
// @include http://*facebook.com/*
// @include https://*facebook.com/*
// @match http://*facebook.com/*
// @match https://*facebook.com/*
// ==/UserScript==
(function () {
/* If Facebook page is not using HTTPS protocol,
* switch it to HTTPS as soon as possible.
*/
if (window.location.protocol === "http:") {
var newLoc = window.location.href;
newLoc = newLoc.replace(/^http:/i, "https:");
window.location.replace(newLoc);
/* If Facebook page's already going through the
* secure protocol, make sure all the internal links
* are leading to HTTPS location as well.
*/
} else {
// Links
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
if (links[i].href.match(/^http:\/\/(?:[a-zA-Z0-9]+\.)?facebook\.com/i)) {
links[i].href = links[i].href.replace(/^http:/i, "https:");
}
}
// Forms
var forms = document.getElementsByTagName("form");
for (var i = 0; i < forms.length; i++) {
if (forms[i].action.match(/^http:\/\/(?:[a-zA-Z0-9]+\.)?facebook\.com/i)) {
forms[i].action = forms[i].action.replace(/^http:/i, "https:");
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment