Skip to content

Instantly share code, notes, and snippets.

@linusyu
Last active August 29, 2015 14:11
Show Gist options
  • Save linusyu/3faebb589642afcf9021 to your computer and use it in GitHub Desktop.
Save linusyu/3faebb589642afcf9021 to your computer and use it in GitHub Desktop.
location.href === "chrome://browser/content/browser.xul" && (function(){
"use strict";
if(typeof fireTrimURL !== "undefined") return;
var fireTrimURL = {
init: function() {
gBrowser.addProgressListener(this);
},
uninit: function() {
gBrowser.removeProgressListener(this);
},
urlbar: document.querySelector("#urlbar"),
processNewURL: function(aURI) {
if(/\s+/g.test(this.urlbar.value)){
var newURL = this.urlbar.value = this.urlbar.value.replace(/\s+/g,"");
var h = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
gBrowser.contentDocument.location.href = h.test(newURL) ?
newURL : "http://"+newURL;
}
},
QueryInterface: XPCOMUtils.generateQI(["nsIWebProgressListener",
"nsISupportsWeakReference"]),
onLocationChange: function(aProgress, aRequest, aURI) {
this.processNewURL(aURI);
}
};
window.fireTrimURL = fireTrimURL;
fireTrimURL.init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment