Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
[Ubiquity] newtab - Open new tab as...
/**
* newtab - A new tab is opened as...
*/
const SS = (Cc['@mozilla.org/browser/sessionstore;1']
.getService(Ci.nsISessionStore)),
mwin = Cc['@mozilla.org/appshell/window-mediator;1']
.getService(Ci.nsIWindowMediator)
.getMostRecentWindow('navigator:browser'),
tabHandle = {
'': function(){
var newtab = mwin.getBrowser().addTab('about:blank')
},
back: function(){
var newtab = mwin.getBrowser().addTab('about:blank'),
state = eval('('+SS.getTabState(mwin.getBrowser().mCurrentTab)+')');
if(state.index - 1 > 0)
state.index -= 1;
SS.setTabState(newtab, uneval(state));
},
next: function(){
var newtab = mwin.getBrowser().addTab('about:blank'),
state = eval('('+SS.getTabState(mwin.getBrowser().mCurrentTab)+')');
if(state.index + 1 <= state.entries.length)
state.index += 1;
SS.setTabState(newtab, uneval(state));
},
clone: function(){
var newtab = mwin.getBrowser().addTab('about:blank');
SS.setTabState(newtab, SS.getTabState(mwin.getBrowser().mCurrentTab));
},
up: function(){
var newtab = CmdUtils.getWindow().open(CmdUtils.getDocument().URL);
newtab.addEventListener('load', function(){
with(newtab.location)
hash ? hash = '' :
search ? search = '' :
href = /\/$/.test(href) ? '..' :
'.';}, true);
},
config: function(){
var newtab = mwin.getBrowser().addTab('about:config');
},
source: function(){
var newtab = mwin.getBrowser().addTab(
CmdUtils.getHtmlSelection().length > 0
? 'view-source:data:text/html,' + CmdUtils.getHtmlSelection()
: 'view-source:' + CmdUtils.getDocument().URL
);
},
}
CmdUtils.CreateCommand({
names: ['newtab'],
icon: 'chrome://ubiquity/skin/icons/favicon.ico',
description: 'A new tab is opened as...',
help: 'newtab [how]',
arguments: [{role: 'object', nountype: {
label: 'how',
suggest: function(t, h){
return [CmdUtils.makeSugg(x) for (x in tabHandle) if (x.match(t))];
}
}}],
preview: function(pb, {object: {text}}){
pb.innerHTML = <div>{this._style}
<h1>{this.description}[{text||'?'}].</h1></div>
+ this._supported();
},
execute: function({object: {text}}){
tabHandle[text]();
},
_supported: function(){
var s = <div><h2>Supported:</h2><ul></ul></div>;
for(var x in tabHandle)
s.div.ul.li += <li>{x}</li>;
return s.toString();
},
_style: <style><![CDATA[
h1{
font: italic bold 130% consolas;
color: #fff;
border-bottom: solid 1px #888;
letter-spacing: -1px;
overflow:hidden;
margin: 4px 0px 4px 0px;
padding: 2px;
}
h2{
font: bold 110% meiryo;
color: #ccc;
line-height: 80%;
letter-spacing: -1px;
overflow:hidden;
margin: 3px 0px 3px 0px;
padding: 2px;
}
ul {margin:0; padding:3px 5px 0px 10px}
li {list-style-type:none;
font:bold 95% "Consolas", monospace}
]]></style>,
author: {name: 'powchin', homepage: 'http://friendfeed.com/powchin'},
licence: 'MIT'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.