Created
November 24, 2015 04:31
-
-
Save Eccenux/fc29eae826f79f5d11cf to your computer and use it in GitHub Desktop.
Custom Buttons (FF) - open URL from current tab in any browser
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
// IE | |
this.openCurrentUrl("c:\\Program Files\\Internet Explorer\\iexplore.exe"); | |
// Firefox Developer Edition | |
this.openCurrentUrl("C:\\Program Files\\Mozilla\\Firefox Developer Edition\\firefox.exe"); | |
// Chrome | |
this.openCurrentUrl("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); | |
// Edge | |
// for whatever reason this doesn't work for local files (i.e. "file:///...") | |
this.openCurrentUrl("c:\\windows\\system32\\cmd.exe", ["/c", "start", "microsoft-edge:%u"]); |
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
/*Init*/ | |
/** | |
@param application Browser executable path. Note that this needs to be a full path. | |
@param args If empty then defaults to `["%u"]` - which means the browser executable takes one parameter and its the URL. | |
*/ | |
this.openCurrentUrl = function (application, args) { | |
// init | |
var localFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); | |
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); | |
// get url | |
var currentUrl = gBrowser.currentURI.spec; | |
// default arg format | |
if (typeof args !== "object") { | |
args = ["%u"]; | |
} | |
// replace "%u" in args | |
for (var i = 0; i < args.length; i++) { | |
args[i] = args[i].replace('%u', currentUrl); | |
} | |
// run | |
localFile.initWithPath(application); | |
process.init(localFile); | |
process.run(false, args, args.length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment