diff options
author | anekos | 2010-03-14 11:07:23 +0000 |
---|---|---|
committer | anekos | 2010-03-14 11:07:23 +0000 |
commit | cc8e92fb0ba07867445de83c98ad4a303aa61fa9 (patch) | |
tree | 480e344aa2e5320f956cbe75a3a74138670b9629 | |
parent | 027ac37d2b4b22e8a524d4644fef884998cb84ae (diff) | |
download | vimperator-plugins-cc8e92fb0ba07867445de83c98ad4a303aa61fa9.tar.bz2 |
tabuniq コマンドを追加 && サブコマンド式に
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@37011 d0d07461-0603-4401-acd4-de1884942a52
-rwxr-xr-x | tabsort.js | 73 |
1 files changed, 53 insertions, 20 deletions
@@ -36,12 +36,12 @@ THE POSSIBILITY OF SUCH DAMAGE. let PLUGIN_INFO = <VimperatorPlugin> <name>tabsort</name> - <description>Add ":tabsort" command.</description> - <description lang="ja">tabsort コマンドを追加する</description> - <version>1.0.1</version> + <description>Add ":tabsort" and ":tabuniq" command.</description> + <description lang="ja">":tabsort", ":tabuniq" コマンドを追加する</description> + <version>1.1.0</version> <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> - <minVersion>2.2pre</minVersion> - <maxVersion>2.2pre</maxVersion> + <minVersion>2.3</minVersion> + <maxVersion>2.3</maxVersion> <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tabsort.js</updateURL> <license>new BSD License (Please read the source code comments of this plugin)</license> <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license> @@ -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 ); |