/** * ==VimperatorPlugin== * @name adddialog.js * @description Add/Delete a :dialog argument. * @description-ja :dialog コマンドで開けるダイアログを追加/削除する。 * @author AmaiSaeta * @version 1.01.20091226 * @minVersion 2.1 * @maxVersion 2.1 * ==/VimperatorPlugin== */ /* {{{ License The MIT License Copyright (c) 2009 AmaiSaeta Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }}} */ let PLUGIN_INFO = // {{{ {NAME} Add/Delete a :dialog argument. :dialogコマンドで開けるダイアログを追加/削除する。 1.00.20091021 AmaiSaeta MIT License 2.1 2.1 || :adddialog gmmanage "Greasemonkeyの『ユーザスクリプトの管理』ダイアログを開く" chrome://greasemonkey/content/manage.xul :deldialog gmmanage ||< ]]> ; /// }}} liberator.plugins.adddialog = (function(args) { // {{{ var name, desc, uri; if(args.length < 2) { liberator.echoerr("The arguments is not worth.", commandline.APPEND_TO_MESSAGES); return; } if(args.length == 2) { // omitted description. name = args[0]; desc = args[1]; uri = args[1]; } else { name = args[0]; desc = args[1]; uri = args[2]; } config.dialogs.push([name, desc, function() openDialog(uri, "_blank")]); }); /// }}} liberator.plugins.deldialog = function(args) { // {{{ var index, dialogLen = config.dialogs.length; var i; if(args.length < 1) { liberator.echoerr("The argument is not worth."); return; } for(index = 0; index < dialogLen; ++index) { if(config.dialogs[index][0] === args[0]) { // found! for(var i = index + 1; i < dialogLen; ++i) { config.dialogs[i - 1] = config.dialogs[i]; } config.dialogs.pop(); return; // success deleted } } liberator.echoerr("'" + args[0] + "' dialog is not found."); // not found }; /// }}} commands.addUserCommand(['adddia[log]'], 'Add a new :dialog argument.', liberator.plugins.adddialog); commands.addUserCommand(['deldia[log]'], 'Delete a :dialog argument.', liberator.plugins.deldialog); // vim: set autoindent tabstop=4 shiftwidth=4 softtabstop=4 textwidth=0 foldmethod=marker : #n12'>12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
/* NEW BSD LICENSE {{{
Copyright (c) 2009-2012, anekos.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
    3. The names of the authors may not be used to endorse or promote products
       derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.


###################################################################################
# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license       #
# に参考になる日本語訳がありますが、有効なのは上記英文となります。                #
###################################################################################

}}} */

// PLUGIN_INFO {{{
let PLUGIN_INFO = xml`
<VimperatorPlugin>
  <name>tabsort</name>
  <description>Add ":tabsort" and ":tabuniq" command.</description>
  <description lang="ja">":tabsort", ":tabuniq" コマンドを追加する</description>
  <version>1.1.4</version>
  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
  <minVersion>2.3</minVersion>
  <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/tabsort.js</updateURL>
  <license>new BSD License (Please read the source code comments of this plugin)</license>
  <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
  <detail><![CDATA[
    == Commands ==
    :tabso[or] [-t[arget]=<TARGET>]
  ]]></detail>
  <detail lang="ja"><![CDATA[
    == Commands ==
    :tabso[or] [-t[arget]=<TARGET>]:

    == Misc ==
    URLによるソートばかり使う!という人は
    >||
    command! urlsort tabsort -t=url
    ||<
    なんかを .vimperatorrc に書いておくと良いよ。
  ]]></detail>
</VimperatorPlugin>`;
// }}}

(function () {

  function memberCompare (name)
    function (a, b) a[name].toString().localeCompare(b[name].toString());

  function getTabs () {
    function gen(tab, i) {
      let browser = tab.linkedBrowser;
      let doc = browser.contentDocument;
      return {
        index: i,
        tab: tab,
        browser: browser,
        doc: doc,
        url: (browser.__SS_restore_data ? browser.__SS_restore_data.url : (doc.location && doc.location.href)),
        title: (browser.__SS_restore_data ? browser.__SS_restore_data.title : doc.title)
      };
    }
    return [gen(tab, i) for ([i, tab] in Iterator(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);
      }
    }

    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 = [
    ['title', 'Title'],
    ['url', 'URL'],
  ];

  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[0] || arg['-target'] || 'title'));
    },
    {
      options: [
        [['-target', '-t'], commands.OPTION_STRING, targetValidater, targetOptions],
      ],
      completer: completer
    },
    true
  );

})();

// vim:sw=2 ts=2 et si fdm=marker: