From cc8e92fb0ba07867445de83c98ad4a303aa61fa9 Mon Sep 17 00:00:00 2001 From: anekos Date: Sun, 14 Mar 2010 11:07:23 +0000 Subject: tabuniq コマンドを追加 && サブコマンド式に git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@37011 d0d07461-0603-4401-acd4-de1884942a52 --- tabsort.js | 73 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 20 deletions(-) (limited to 'tabsort.js') diff --git a/tabsort.js b/tabsort.js index e140358..b56cb33 100755 --- a/tabsort.js +++ b/tabsort.js @@ -36,12 +36,12 @@ THE POSSIBILITY OF SUCH DAMAGE. let PLUGIN_INFO = tabsort - Add ":tabsort" command. - tabsort コマンドを追加する - 1.0.1 + Add ":tabsort" and ":tabuniq" command. + ":tabsort", ":tabuniq" コマンドを追加する + 1.1.0 anekos - 2.2pre - 2.2pre + 2.3 + 2.3 http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tabsort.js new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) @@ -68,20 +68,33 @@ let PLUGIN_INFO = function memberCompare (name) function (a, b) a[name].toString().localeCompare(b[name].toString()); - function tabSort (cmp) { - let nbrowsers = getBrowser().browsers.length; - let ts = []; - for (let [i,] in tabs.browsers) { - let b = getBrowser().getBrowserAtIndex(i); - let c = b.contentDocument; - ts.push({ - index: i, - tab: gBrowser.mTabs[i], - url: c.location.href, - title: c.title - }); + function getTabs () [ + { + index: i, + tab: tab, + doc: #1=(tab.linkedBrowser.contentDocument), + url: #1#.location.href, + title: #1#.title, + } + for ([i, tab] in util.Array(config.browser.mTabs)) + ]; + + function tabUniq (cmp) { + let rms = []; + let tabs = getTabs(); + + for (let [i, tabA] in Iterator(tabs)) { + for each (let tabB in tabs.slice(i + 1)) { + if (cmp(tabA, tabB) === 0) + rms.push(tabB); + } } - ts.sort(cmp).forEach(function (it, i) (i == it.index) || getBrowser().moveTabTo(it.tab, i)); + + rms.forEach(function (rm) config.tabbrowser.removeTab(rm.tab)); + } + + function tabSort (cmp) { + getTabs().sort(cmp).forEach(function (it, i) (i == it.index) || config.tabbrowser.moveTabTo(it.tab, i)); } let targetOptions = [ @@ -92,17 +105,37 @@ let PLUGIN_INFO = function targetValidater (value) targetOptions.some(function ([n,]) n == value); + function completer (context) { + context.title = ['Target', 'Action']; + context.completions = targetOptions; + } + + commands.addUserCommand( + ['tabu[niq]'], + 'Uniq tabs', + function (arg) { + tabUniq(memberCompare(arg[0] || arg['-target'] || 'url')); + }, + { + options: [ + [['-target', '-t'], commands.OPTION_STRING, targetValidater, targetOptions], + ], + completer: completer + }, + true + ); + commands.addUserCommand( ['tabso[rt]'], 'Sort tabs', function (arg) { - tabSort(memberCompare(arg['-target'] || 'title')); + tabSort(memberCompare(arg[0] || arg['-target'] || 'title')); }, { - argCount: '0', options: [ [['-target', '-t'], commands.OPTION_STRING, targetValidater, targetOptions], ], + completer: completer }, true ); -- cgit v1.2.3