Instantly share code, notes, and snippets.

Embed
What would you like to do?
選択範囲内のリンクを新しいタブグループで開く
// 選択範囲内のリンクを新しいタブグループで開く
// こんな感じでいいんだろうか
(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