aboutsummaryrefslogtreecommitdiffstats
path: root/open-frame.js
blob: 1560b5608f409e1712e6da8831fa3bec2de0a29b (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
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
150
151
152
153
154
155
156
157
158
159
160
/* NEW BSD LICENSE {{{
Copyright (c) 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 = xml`
<VimperatorPlugin>
  <name>openframe-command</name>
  <name lang="ja">openframeコマンド</name>
  <description>Add ":openframe" command.</description>
  <description lang="ja">":openframe" コマンドを追加する</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>https://github.com/vimpr/vimperator-plugins/raw/master/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 = xml`
  <plugin name="openframe-command" version="1.2.1"
          href="http://github.com/vimpr/vimperator-plugins/blob/master/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://github.com/vimpr/vimperator-plugins/blob/master/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:
39;; // class definitions function Clock() { this._initialize.apply(this, arguments); } Clock.prototype = { _initialize: function (format) { this._format = format; this._master = window.document.createElement('label'); this._master.setAttribute('style', this._constants.style); this._intervalInfo = {}; }, _constants: { // default style style: [ 'margin: 0;', 'padding: 1px;', 'border: 0 none;', 'color: black;', 'background-color: white;', 'font-family: monospace;', 'font-weight: bold;', ].join(''), // prefix of id and class name prefix: 'liberator-plugin-clock-', driver: { t: function (label) { return setInterval(function () label.setAttribute('value', time()), 100); }, a: function (label) { return setInterval(function () label.setAttribute('value', weekDay()), 60 * 1000); }, d: function (label) { return setInterval(function () label.setAttribute('value', day()), 60 * 1000); }, y: function (label) { return setInterval(function () label.setAttribute('value', year()), 60 * 1000); }, }, generator: { t: function (self) { let l = self._master.cloneNode(false); l.setAttribute('id', self._constants.prefix + 'clock'); l.setAttribute('value', time()); let id = self._constants.driver.t(l); return { node: l, intervalId: id, }; }, a: function (self) { let l = self._master.cloneNode(false); l.setAttribute('id', self._constants.prefix + 'wday'); l.setAttribute('value', weekDay()); let id = self._constants.driver.a(l); return { node: l, intervalId: id, }; }, d: function (self) { let l = self._master.cloneNode(false); l.setAttribute('id', self._constants.prefix + 'day'); l.setAttribute('value', day()); let id = self._constants.driver.d(l); return { node: l, intervalId: id, }; }, y: function (self) { let l = self._master.cloneNode(false); l.setAttribute('id', self._constants.prefix + 'year'); l.setAttribute('value', year()); let id = self._constants.driver.y(l); return { node: l, intervalId: id, }; }, raw: function (self, str) { let l = self._master.cloneNode(false); l.setAttribute('class', self._constants.prefix + 'raw'); l.setAttribute('value', str); return { node: l, }; }, }, }, // generate generate: function () { let box = window.document.createElement('hbox'); box.setAttribute('id', this._constants.prefix + 'box'); box.setAttribute('style', 'display: block;'); box.setAttribute('class', 'liberator-container'); let format = this._format; let generator = this._constants.generator; let raw = ''; let formatFlag = false; for (let i=0, l=format.length ; i<l ; ++i) { let c = format[i]; switch(c) { case '%': formatFlag = true; if (raw) { box.appendChild(generator['raw'](this, raw).node); raw = ''; } break; default: if (formatFlag) { if (c in generator) { let g = generator[c](this); box.appendChild(g.node); if (g.intervalId) this._intervalInfo[c] = g; } formatFlag = false; } else { raw += c; } break; } } if (raw.length > 0) box.appendChild(generator['raw'](this, raw).node); this._box = box; }, get instance() this._box, get width() this._box.boxObject.width, hide: function () this._box.setAttribute('style', 'display: none;'), appear: function () this._box.setAttribute('style', 'display: block;'), justify: function (parentWidth) this._box.setAttribute('left', parentWidth - this.width), start: function () { let info = this._intervalInfo; for (let [k, i] in Iterator(info)) { if (!i.intervalId) { i.intervalId = this._constants.driver[k](i.node); } } }, stop: function () { let info = this._intervalInfo; for (let [k, i] in Iterator(info)) { if (i.intervalId) { clearInterval(i.intervalId); i.intervalId = undefined; } } }, }; // main --- let commandlineStack = getCommandlineStack(); if (!commandlineStack) { let errmsg = 'clock.js: not found the commandline.'; liberator.log(errmsg, 0); liberator.echoerr(errmsg); return; } // build clock let clock = new Clock(format); clock.generate(); // insert commandlineStack.appendChild(clock.instance); // register command [ [['clockhide'], 'hide clock', function () clock.hide() ], [['clockappear'], 'clock appear', function () clock.appear() ], [['clockstart'], 'start clock', function () clock.start() ], [['clockstop'], 'stop clock', function () clock.stop() ], [['clockjustify'], 'justify', function () clock.justify(window.innerWidth) ], ].forEach( function ([n, d, f]) commands.addUserCommand(n, d, f, {}) ); window.addEventListener( 'resize', function () { clock.justify(window.innerWidth); }, false ); autocommands.add( 'VimperatorEnter', /.*/, function () { clock.justify(window.innerWidth); } ); // stuff functions --- function time() { let now = new Date(); let hour = now.getHours().toString(10); let min = now.getMinutes().toString(10); if (hour.length < 2) hour = '0' + hour; if (min.length < 2) min = '0' + min; return hour + (now.getMilliseconds() < 400 ? ' ' : ':') + min; } function weekDay() { const wdays = 'sun mon tue wed thu fri sat'.split(/%s/); let now = new Date(); return now.toLocaleFormat ? now.toLocaleFormat('%a') : wdays[now.getDay()]; } function day() { let now = new Date(); let date = now.getDate().toString(10); let month = (now.getMonth() + 1).toString(10); if (date.length < 2) date = '0' + date; if (month.length < 2) month = '0' + month; return month + '/' + date; } function year() { return new Date().getFullYear().toString(10); } // node control function getCommandlineStack() { let messageTextarea = window.document.getElementById('liberator-message'); let commandlineStack = messageTextarea.parentNode; return commandlineStack.localName === 'stack' ? commandlineStack : null; } } )(); // vim: set sw=4 ts=4 et;