Created
August 3, 2011 13:35
-
-
Save Griever/1122641 to your computer and use it in GitHub Desktop.
選択範囲内のリンクを新しいタブグループで開く
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
// 選択範囲内のリンクを新しいタブグループで開く | |
// こんな感じでいいんだろうか | |
(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