aboutsummaryrefslogtreecommitdiffstats
path: root/tinyurl.js
blob: 5930d5a89f203f4e985c261c569a611d9a183f0a (plain)
1
2
3
4
5
6
7
8
9
10
11
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
// PLUGIN_INFO//{{{
var PLUGIN_INFO =
<VimperatorPlugin>
    <name>{NAME}</name>
    <description>TinyURL from Vimperator</description>
    <author mail="konbu.komuro@gmail.com" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author>
    <version>0.1</version>
    <minVersion>2.0pre</minVersion>
    <maxVersion>2.0pre</maxVersion>
    <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tinyurl.js</updateURL>
    <detail><![CDATA[

== COMMANDS ==
tinyurl [URL]:
    echo and copy URL
expandurl URL:
    expand URL

== LIBRARY ==
plugins.tinyurl.getTiny(url):
    return TinyURL
plugins.tinyurl.getExpand(url):
    return ExpandURL

    ]]></detail>
</VimperatorPlugin>;
//}}}

(function() {
    const TinyAPI = 'http://tinyurl.com/api-create.php?url=';

    commands.add(['tinyurl'], 'echo and copy TinyURL',
        function(args) util.copyToClipboard(tiny.getTiny(args.length==0 ? buffer.URL : args.string), true),
        {
            argCount: '?',
        });
    commands.add(['expandurl'], 'expand TinyURL',
        function(args) util.copyToClipboard(tiny.getExpand(args.string), true),
        {
            argCount: '1',
        });

    var tiny = plugins.tinyurl = {
        getTiny: function(url)
            util.httpGet(TinyAPI+encodeURIComponent(url)).responseText,
        getExpand: function (url)
            util.httpGet(url).channel.name
    };
})();
// vim: fdm=marker sw=4 ts=4 et:
me" コマンドを追加する</description> <version>1.2.1</version> <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> <license>new BSD License (Please read the source code comments of this plugin)</license> <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license> <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/open-frame.js</updateURL> <minVersion>2.3</minVersion> <maxVersion>2.4</maxVersion> <detail><![CDATA[ Add "openframe" and "tabopenframe" command. ]]></detail> <detail lang="ja"><![CDATA[ コマンド "openframe" "tabopenframe" を追加します ]]></detail> </VimperatorPlugin>; // }}} // INFO {{{ let INFO = <> <plugin name="openframe-command" version="1.2.1" href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/open-frame.js" summary="Add openframe command." lang="en-US" xmlns="http://vimperator.org/namespaces/liberator"> <author email="anekos@snca.net">anekos</author> <license>New BSD License</license> <project name="Vimperator" minVersion="2.3"/> <item> <tags>:openframe</tags> <spec>:openf<oa>rame</oa></spec> <description><p>Open the selected frame in current tab.</p></description> </item> <item> <tags>:tabopenframe</tags> <spec>:t<oa>ab</oa>o<oa>pen</oa>f<oa>rame</oa></spec> <description><p>Open the selected frame in new tab.</p></description> </item> </plugin> <plugin name="openframe-command" version="1.2.1" href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/open-frame.js" summary="Add openframe command." lang="ja" xmlns="http://vimperator.org/namespaces/liberator"> <author email="anekos@snca.net">anekos</author> <license>New BSD License</license> <project name="Vimperator" minVersion="2.3"/> <item> <tags>:openframe</tags> <spec>:openf<oa>rame</oa></spec> <description><p>現在のタブに選択したフレームを開く</p></description> </item> <item> <tags>:tabopenframe</tags> <spec>:t<oa>ab</oa>o<oa>pen</oa>f<oa>rame</oa></spec> <description><p>新しいタブに選択したフレームを開く</p></description> </item> </plugin> </>; // }}} (function () { let gvModeName = { current: liberator.globalVariables.open_frame_hint_mode_current, tab: liberator.globalVariables.open_frame_hint_mode_tab }; function frames () { let result = []; (function (win) { result = result.concat(Array.map(win.frames, function (win) win)); Array.forEach(win.frames, arguments.callee); })(config.browser.contentWindow); return result; } [true, false].forEach(function (tab) { let desc = 'Open frame in ' + (tab ? 'current tab' : 'new tab'); let modeName = gvModeName[tab ? 'tab' : 'current'] || ((tab ? 'tab-' : '') + 'open-frame'); let open = function (url) liberator.open(url, tab ? liberator.NEW_TAB : liberator.CURRENT_TAB); hints.addMode( modeName, desc, function (elem) { open(elem.ownerDocument.location.href); }, function () util.makeXPath(["body"]) ); commands.addUserCommand( tab ? ['tabopenf[rame]', 'topenf[rame]', 'tof[rame]'] : ['openf[rame]', 'of[rame]'], desc, function (args) { if (args.literalArg) { open(args.literalArg); } else { hints.show(modeName); } }, { literal: 0, completer: function (context) { context.title = ['URL', 'Title']; context.completions = [ [f.location.href, f.document.title || '<No Title>'] for each (f in frames()) ]; } }, true ); }); })(); // vim:sw=2 ts=2 et si fdm=marker: