/* {{{ Copyright (c) 2008, 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 = every.js to run a specified command every time at specified interval. 指定のコマンドを指定の間隔で実行する。 1.1.1 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/every.js 2.0pre 2.0pre : run every time at [INTERVAL] sec. :[INTERVAL]delay : run after [INTERVAL] sec. :every! : kill specified process. The default value of [INTERVAL] is 1 sec. While Vimperator's focus is at command-line, these commands does not run. == Links == http://d.hatena.ne.jp/nokturnalmortum/20081102#1225552718 ]]> : [INTERVAL] 間隔で を走らせる。 :[INTERVAL]delay : [INTERVAL] 秒後に を走らせる。 :every! : 指定のプロセスを殺す。 [INTERVAL] のデフォルトは 1秒。 コマンドラインにいるときには、実行されないようになっている。 == Links == http://d.hatena.ne.jp/nokturnalmortum/20081102#1225552718 ]]> ; // }}} (function () { let every = liberator.plugins.every; if (every) { kill('*'); } else { liberator.plugins.every = every = {ps: []}; } function run (command, interval) { let fun = function () { if (liberator.mode != liberator.modules.modes.COMMAND_LINE) liberator.execute(command); }; every.ps.push({ handle: setInterval(fun, interval), command: command }); } function kill (index) { if (index == '*') { every.ps.forEach(function (process) clearInterval(process.handle)); liberator.echo(every.ps.length + ' processes were killed!'); every.ps = []; } else { let process = every.ps[index]; if (process) { clearInterval(process.handle); every.ps.splice(index, index); liberator.echo('process "' + process.command + '" was killed!'); } else { liberator.echoerr('unknown process'); } } } function msec (count) { return (count > 0) ? count * 1000 : 1000; } liberator.modules.commands.addUserCommand( ['every', 'ev'], 'every', function (args) { if (args.bang) { kill(args[0]); } else { run(args.string, msec(args.count)); } }, { count: true, bang: true, argCount: '+', completer: function (context, args) { if (args.bang) { context.title = ['PID', 'every process']; context.completions = [['*', 'kill em all']].concat(every.ps.map(function (p, i) ([i.toString(), p.command]))); } else { liberator.modules.completion.ex(context); } } }, true ); liberator.modules.commands.addUserCommand( ['delay'], 'delay', function (arg, bang, count) { let cmd = arg.string; let f = function () { if (liberator.mode == liberator.modules.modes.COMMAND_LINE) { setTimeout(f, 500); } else { liberator.execute(cmd); } }; setTimeout(f, msec(count)); }, { count: true, argCount: '+', completer: function (context) liberator.modules.completion.ex(context) } ); })(); 'n77' href='#n77'>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 150 151 152 153
/**
 * ==VimperatorPlugin==
 * @name           access_hatena.js
 * @description    Access to Hatena Service quickly
 * @description-ja はてなのサービスに簡単にアクセス
 * @minVersion     2.1a1pre
 * @author         id:masa138, id:hitode909
 * @version        0.5.8
 * ==/VimperatorPlugin==
 *
 * Usage:
 * :accesshatena -> access to http://www.hatena.ne.jp/
 *
 * :accesshatena {host} -> access to http://{host}.hatena.ne.jp/
 *
 * :accesshatena {host} {user_id} -> access to http://{host}.hatena.ne.jp/{user_id}/
 *
 * :accesshatena {group_name}.g {user_id} -> access to http://{group_name}.g.hatena.ne.jp/{user_id}/
 *
 */
(function(){
    var alwaysCollect;
    var useWedata;

    var wedataCache = [];
    var ignoreIds;
    var ids;
    var pageFor;
    var title;

    function Title() {
        this.initialize.apply(this, arguments);
    }
    Title.prototype = {
        initialize: function() {
            this.title = [];
        },
        key: function(host, id) {
            return [host, id.replace('/', '')].join(':');
        },
        set: function(host, id, title) {
            this.title[this.key(host, id)] = title;
        },
        get: function(host, id, title) {
            if (!this.title[this.key(host, id)]) return host + '.hatena.ne.jp/' + id;
            return this.title[this.key(host, id)];
        }
    };

    function init(flag) {
        ids     = [];
        pageFor = [];
        title   = new Title();

        alwaysCollect = liberator.globalVariables.accessHatenaAlwaysCollect;
        useWedata     = liberator.globalVariables.accessHatenaUseWedata;
        ignoreIds     = liberator.globalVariables.accessHatenaIgnoreIds;
        alwaysCollect = (alwaysCollect != null) ? alwaysCollect : true;
        useWedata     = (useWedata     != null) ? useWedata     : true;
        ignoreIds     = (ignoreIds     != null) ? ignoreIds     : ['login'];

        if (flag && useWedata) loadWedata();

        if (useWedata) {
            for (i in wedataCache) if (wedataCache.hasOwnProperty(i)) {
                var id = wedataCache[i];
                if (ignoreIds.indexOf(id) == -1) {
                    ignoreIds.push(id)
                }
            }
        }
    }
    init(true);

    function collectLog() {
        init(false);
        var visited = history.get('.hatena.ne.jp');
        for (i in visited) if (visited.hasOwnProperty(i)) {
            var page = visited[i];

            page.url.match('^https?://([a-zA-Z0-9.-]+)\\.hatena\\.ne\\.jp/([a-zA-Z][a-zA-Z0-9_-]{1,30}[a-zA-Z0-9]/?)?');
            var host = RegExp.$1;
            var id   = RegExp.$2;
            if (host != '') {
                if (!pageFor[host]) {
                    pageFor[host] = page;
                }
                if (pageFor[host].url.length > page.url.length) {
                    pageFor[host] = page;
                }
            }
            if (id != '' && !id.match('^(?:' + ignoreIds.join('|') + ')$') && ids.indexOf(id) == -1) {
                ids.push(id);
                if (id.indexOf('/') != -1) {
                    if (page.url.match('^https?://' + host + '\\.hatena\\.ne\\.jp/' + id + '$') && title.get(host, id) != page.title) {
                        title.set(host, id, page.title);
                    }
                }
            }
        }
    }
    collectLog();

    function loadWedata() {
        var url = 'http://wedata.net/databases/access_hatena_ignore_id/items.json';
        var req = XMLHttpRequest();

        req.open('GET', url, true);
        req.onload = registerIgnoreIds;
        req.onerror = function(e) { liberator.echoerr('Error in access_hatena.js: loadWedata'); };
        req.send(null);
    }

    function registerIgnoreIds(e) {
        var req = this;
        var json = eval(req.responseText);
        for (var i in json) if (json.hasOwnProperty(i)) {
            var id = json[i].data.id;
            if (wedataCache.indexOf(id) == -1 && id != '') {
                wedataCache.push(id);
            }
        }
    }

    commands.addUserCommand(["accesshatena"], "Access to Hatene Service Quickly",
        function(args) {
            var host = args[0] ? encodeURIComponent(args[0].toString()) : 'www';
            var id   = args[1] ? encodeURIComponent(args[1].toString()).replace('%2F', '/') : '';
            var uri  = 'http://' + host + '.hatena.ne.jp/' + id;
            liberator.open(uri, liberator.CURRENT_TAB);
        }, {
            completer: function (context, args) {
                if (args.length == 1) {
                    if (alwaysCollect) collectLog();
                    context.title = ["Host", "Service"];
                    context.completions = [[host, pageFor[host].title] for (host in pageFor) if (pageFor.hasOwnProperty(host))];
                } else if (args.length == 2) {
                    var host = args[0].toString();
                    context.title = ["ID", "Page"];
                    context.completions = [[ids[i], title.get(host, ids[i])] for (i in ids) if (ids.hasOwnProperty(i))];
                }
            }
        }
    );

    commands.addUserCommand(["accesshatenainit"], "Initialize Access Hatena",
        function() {
            init(true);
            liberator.echo('Finish initializing.');
        }
    );
})();
// vim:sw=4 ts=4 et: