var PLUGIN_INFO = {NAME} Access to Hatena Sevices quickly. はてなのサーヴィスに簡単にアクセス出来ます. 2.1a1pre 2.1a1pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/access_hatena.js Masayuki KIMURA and id:hitode909 0.63 || map ; :accesshatena ||< # 最後にスペースを入れておくと直ぐにホストの入力から始められます. ]]> ; (function(){ var useWedata; var ignoreIds; var ids; var recentHosts; var maxRecentHostsSize; var historyCompletions; var collectLogSpan; var pageFor; var title; var isFirst; var isIncreased; var isUpdated; var lastLocation; function Title() { this.initialize.apply(this, arguments); } Title.prototype = { initialize: function() { this.title = []; this.n = 0; }, key: function(host, id) { return [host, id.replace('/', '')].join(':'); }, set: function(host, id, title) { var key = this.key(host, id); if (this.title[key] == null) { this.title[key] = title; this.n++; } }, 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() { ids = []; recentHosts = []; historyCompletions = []; pageFor = []; title = new Title(); isFirst = true; isIncreased = false; isUpdated = false; lastLocation = window.content.location.href.replace(/^https?:\/\//, ''); maxRecentHostsSize = liberator.globalVariables.maxRecentHostsSize || 10; collectLogSpan = liberator.globalVariables.collectLogSpan || 24 * 7 * 4 * 60 * 60 * 1000000; // 4 weeks useWedata = liberator.globalVariables.accessHatenaUseWedata; ignoreIds = liberator.globalVariables.accessHatenaIgnoreIds; useWedata = (useWedata != null) ? useWedata : true; ignoreIds = (ignoreIds != null) ? ignoreIds : ['login']; if (useWedata) { loadWedata(); } } init(); function prepareSearch() { var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService); var options = historyService.getNewQueryOptions(); var query = historyService.getNewQuery(); query.beginTimeReference = query.TIME_RELATIVE_NOW; query.beginTime = -1 * collectLogSpan; query.endTimeReference = query.TIME_RELATIVE_NOW; query.endTime = 0; query.domain = "hatena.ne.jp"; return historyService.executeQuery(query, options).root; } function collectLog() { var root = prepareSearch(); ids = []; recentHosts = []; historyCompletions = []; historyCompletions.h = []; root.containerOpen = true; for (var i = 0, length = root.childCount; i < length; i++) { var page = root.getChild(i); page.uri.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; var _recent_hosts_length = recentHosts.length; if (host != '') { if (!page.uri) continue; if (!pageFor[host]) { pageFor[host] = page; isIncreased = true; } else if (pageFor[host].uri.length > page.uri.length) { // より短いアドレスのタイトルが妥当 pageFor[host] = page; isUpdated = true; } if (_recent_hosts_length < maxRecentHostsSize && recentHosts.indexOf(host) == -1) { recentHosts.push(host); } else if (recentHosts.indexOf(host) == -1 && historyCompletions.h.indexOf(host) == -1) { historyCompletions.push([host, pageFor[host].title]); historyCompletions.h.push(host); } } if (id != '' && !id.replace('/', '').match(new RegExp('^(?:' + ignoreIds.join('|') + ')$'))) { // Wedata の拒否リストに入っていなかったら var index = ids.indexOf(id); if (index == -1) { ids.unshift(id); } else { ids.splice(index, 1); ids.unshift(id); } if (isFirst || isIncreased || isUpdated) { // 初回か,pageFor に何か追加されたか,pageFor が更新されたら isIncreased = false; isUpdated = false; if (page.title != '' && title.get(host, id) != page.title) { title.set(host, id, page.title); } } } } root.containerOpen = false; isFirst = false; } 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 (ignoreIds.indexOf(id) == -1 && id != '') { ignoreIds.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; var targetTab = args.bang ? liberator.CURRENT_TAB : liberator.NEW_TAB; liberator.open(uri, targetTab); lastLocation = ''; }, { completer: function (context, args) { if (args.length == 1) { context.title = ["Host", "Service"]; if (window.content.location.href.replace(/^https?:\/\//, '') != lastLocation) { // ページ遷移がない場合に何度も collectLog() しないように collectLog(); lastLocation = window.content.location.href.replace(/https?:\/\//, ''); } context.completions = [[recentHosts[i], pageFor[recentHosts[i]].title] for (i in recentHosts) if (recentHosts.hasOwnProperty(i))].concat(historyCompletions); } 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(); liberator.echo('Finish initializing.'); } ); })(); // vim:sw=4 ts=4 et: #n163'>163 164 165 166 167 168 169
/* NEW BSD LICENSE {{{
Copyright (c) 2008-2010, 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 =
<VimperatorPlugin>
  <name>Stat Stat</name>
  <name lang="ja">すたすた</name>
  <description>Show information on statusline.</description>
  <description lang="ja">ステータスラインに情報を表示</description>
  <version>1.0.2</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/statstat.js</updateURL>
  <minVersion>2.0</minVersion>
  <maxVersion>2.3</maxVersion>
  <detail><![CDATA[
    Usage:
      :statstat <JS_EXPRESSION>
    Links:
      http://d.hatena.ne.jp/nokturnalmortum/20081202/1228218135
  ]]></detail>
</VimperatorPlugin>;
// }}}
// INFO {{{
let INFO =
<plugin name="Stat Stat" version="1.0.2"
        href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/statstat.js"
        summary="Show information on statusline."
        xmlns="http://vimperator.org/namespaces/liberator">
  <author email="anekos@snca.net">anekos</author>
  <license>New BSD License</license>
  <project name="Vimperator" minVersion="2.0"/>
  <p>
  </p>
  <item>
    <tags>:statstat</tags>
    <spec>:statstat <a>jsExpression</a></spec>
    <description>
      <p>
        Set the expression for displaying information on statline.
      </p>
    </description>
  </item>
</plugin>;
// }}}

(function () {

  let stat = liberator.plugins.statstat;
  let defaultExpression = liberator.globalVariables.statstat_expression;
  let defaultInterval = liberator.globalVariables.statstat_interval;
  let autorun = s2b(liberator.globalVariables.statstat_autorun, false);

  function s2b (s, d) (!/^(\d+|false)$/i.test(s)|parseInt(s)|!!d*2)&1<<!s;
  function e2a (e) function () liberator.eval(e);

  // Initialize
  if (stat) {
    let e = stat.panel;
    if (e && e.parentNode)
      e.parentNode.removeChild(e);
    if (stat.handle) {
      clearInterval(stat.handle);
      stat.handle = null;
    }
  }

  {
    let panel = this.panel = document.createElement('statusbarpanel');
    panel.setAttribute('id', 'ank-stat-stat-panel');
    let label = document.createElement('label');
    label.setAttribute('value', '-----');
    panel.appendChild(label);
    let stbar = document.getElementById('status-bar');
    stbar.insertBefore(panel, document.getElementById('liberator-statusline').nextSibling);

    stat = liberator.plugins.statstat = {
      previousText: null,
      panel: panel,
      label: label,
      interval: 1000,
      set text (value) {
        value = value.toString();
        if (this.previousText === value)
          return value;
        this.label.setAttribute('value', '<- ' + value + ' ->');
        this.previousText = value;
        return value;
      },
      action: function () new Date().toLocaleString(),
      execute: function () (this.text = this.action.apply(this, arguments)),
      run: function () {
        let self = this;
        Array.slice(arguments).forEach(function (v) {
          if (v instanceof Function)
            self.action = v;
          else if (typeof v == 'string')
            self.action = function () liberator.eval(v);
          else if (typeof v == 'number')
            self.interval = v;
        });
        this.handle = setInterval(function () self.execute(), this.interval);
      },
      handle: null
    };
  }

  // set default
  if (defaultExpression)
    stat.action = e2a(defaultExpression);
  if (defaultInterval)
    stat.interval = parseInt(defaultInterval);
  if (autorun)
    stat.run();

  commands.addUserCommand(
    ['statstat'],
    'Run statstat',
    function (arg) {
      if (stat.handle)
        clearInterval(stat.handle);
      let interval = arg.count ? arg.count * 100 : 100;
      stat.action = e2a(arg.string);
      stat.handle = setInterval(function () stat.execute(), interval);
    },
    {
      completer: function (context) completion.javascript(context),
      argCount: '*',
      count: true
    },
    true
  );

})();

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