Skip to content

Instantly share code, notes, and snippets.

@Griever
Created August 3, 2011 13:35
Show Gist options
  • Save Griever/1122641 to your computer and use it in GitHub Desktop.
Save Griever/1122641 to your computer and use it in GitHub Desktop.
選択範囲内のリンクを新しいタブグループで開く
// 選択範囲内のリンクを新しいタブグループで開く
// こんな感じでいいんだろうか
(function() {
var win = document.commandDispatcher.focusedWindow;
if (!win || win == window) win = content;
var sel = win.getSelection();
var urls = [];
for (var i = 0, len = sel.rangeCount; i < len; i++) {
Array.forEach(sel.getRangeAt(i).cloneContents().querySelectorAll('a:not(:empty)'), function(a){
if (urls.indexOf(a.href) === -1)
urls.push(a.href);
});
};
if (urls.length === 0) return;
TabView._initFrame(function(){
var item = TabView._iframe.contentWindow.GroupItems.newGroup();
urls.forEach(function(url, i){
var tab = gBrowser.addTab(url);
TabView.moveTabTo(tab, item.id);
if (i === 0) gBrowser.selectedTab = tab;
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment