public
Last active

[Ubiquity] newtab - Open new tab as...

  • Download Gist
Ubiquity-newtab.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/**
* 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'
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.