Created
March 20, 2011 06:03
-
-
Save lkraider/878143 to your computer and use it in GitHub Desktop.
Greasemonkey userscript that removes SSL from Cloudfront hosted assets in GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# README | |
This userscript is a hack to replace HTTPS Cloudfront hosted assets on GitHub. | |
Cloudfront serves its files *only* through 128-bit RC4/MD5 encryption, which is | |
old and not appropriate for secure use in the modern day, and as such I have | |
that disabled in Firefox (about:config security.ssl3.rsa_rc4_128_md5). | |
Since there is currently no way to whitelist encryption schemes for specific | |
websites, this userscript is a workaround that converts the CSS, Javascript and | |
images links used on github to plain http connection for the Cloudfront assets | |
server. | |
*/ | |
// ==UserScript== | |
// @name Github Cloudfront Disable SSL | |
// @namespace https://gist.github.com/lkraider | |
// @description Removes SSL from Cloudfront hosted assets | |
// @version 1.0.0 | |
// @author lkraider | |
// @include https://github.com/* | |
// @include https://*.github.com/* | |
// ==/UserScript== | |
var head = document.getElementsByTagName('head')[0]; | |
var link = head.getElementsByTagName('link'); | |
var script = head.getElementsByTagName('script'); | |
var body = document.getElementsByTagName('body')[0]; | |
var img = body.getElementsByTagName('img'); | |
var https_cloudfront = "https://d3nwyuy0nl342s.cloudfront.net"; | |
var cloudfront = https_cloudfront.replace("https://", "http://"); | |
// GitHub pages contain `assetHost` variable that already points to correct | |
// server which is useful in case the host changes so the script doesn't need | |
// to be updated manually. Gist pages don't seem to define this though. | |
if (unsafeWindow.GitHub.assetHost) { | |
https_cloudfront = unsafeWindow.GitHub.assetHost; | |
cloudfront = https_cloudfront.replace("https://", "http://"); | |
unsafeWindow.GitHub.assetHost = cloudfront; | |
} | |
for (var i in link) { | |
link[i].href = link[i].href.replace(https_cloudfront, cloudfront); | |
} | |
var new_script = []; | |
for (var i in script) { | |
var old_src = script[i].src; | |
if (old_src) { | |
var new_src = old_src.replace(https_cloudfront, cloudfront); | |
script[i].src = new_src; | |
if (old_src != new_src) { | |
var el = document.createElement('script'); | |
el.type = 'text/javascript'; | |
el.src = new_src; | |
new_script.push(el); | |
} | |
} | |
} | |
for (var i in new_script) { | |
head.appendChild(new_script[i]); | |
} | |
for (var i in img) { | |
img[i].src = img[i].src.replace(https_cloudfront, cloudfront); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment