root/lang/javascript/vimperator-plugins/trunk/amebanow.js

Revision 36127, 4.7 kB (checked in by anekos, 9 months ago)

アメーバなうの変更に手抜き対応

  • Property svn:executable set to *
Line 
1/* NEW BSD LICENSE {{{
2Copyright (c) 2009, anekos.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
8    1. Redistributions of source code must retain the above copyright notice,
9       this list of conditions and the following disclaimer.
10    2. Redistributions in binary form must reproduce the above copyright notice,
11       this list of conditions and the following disclaimer in the documentation
12       and/or other materials provided with the distribution.
13    3. The names of the authors may not be used to endorse or promote products
14       derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25THE POSSIBILITY OF SUCH DAMAGE.
26
27
28###################################################################################
29# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license       #
30# に参考になる日本語訳がありますが、有効なのは上記英文となります。                #
31###################################################################################
32
33}}} */
34
35// PLUGIN_INFO {{{
36let PLUGIN_INFO =
37<VimperatorPlugin>
38  <name>AmebaNau</name>
39  <name lang="ja">Amebaなう</name>
40  <description>nau</description>
41  <description lang="ja">Amebaなうする</description>
42  <version>1.0.4</version>
43  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
44  <license>new BSD License (Please read the source code comments of this plugin)</license>
45  <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
46  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/amebanow.js</updateURL>
47  <minVersion>2.3</minVersion>
48  <maxVersion>2.3</maxVersion>
49  <require>_libly.js</require>
50  <detail><![CDATA[
51    == command ==
52    :nau <MESSAGE>
53    == multi post setting ==
54      >||
55        let g:amebanow_multipost = "twitter|wassr"
56      ||<
57  ]]></detail>
58</VimperatorPlugin>;
59// }}}
60// INFO {{{
61let INFO =
62<plugin name="AmebaNow" version="1.0.4"
63        href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/amebanow.js"
64        summary="AmebaNau"
65        xmlns="http://vimperator.org/namespaces/liberator">
66  <author email="anekos@snca.net">anekos</author>
67  <license>New BSD License</license>
68  <project name="Vimperator" minVersion="2.3"/>
69  <p>
70  </p>
71  <item>
72    <tags>:nau</tags>
73    <spec>:nau message</spec>
74    <description>
75      <p>
76        Nau message.
77      </p>
78    </description>
79  </item>
80</plugin>;
81// }}}
82
83
84(function () {
85
86  function getToken (onSuccess) {
87    const url = 'http://now.ameba.jp/';
88    let req = new plugins.libly.Request(url);
89    req.addEventListener(
90      'onSuccess',
91      function (res) {
92        let m = res.responseText.match(/<input id="token" type="hidden" name="token" value="(\w+)"/);
93        if (m)
94          onSuccess(m[1]);
95      }
96    );
97    req.get();
98  }
99
100  function now (msg, token) {
101    const url = 'http://ucsnow.ameba.jp/post';
102    let data =
103      'entryText=' + encodeURIComponent(msg) +
104      '&token=' + token +
105      '&inputBtn=%E6%8A%95%E7%A8%BF';
106    let req =
107      new plugins.libly.Request(
108        url,
109        {Referer: 'http://now.ameba.jp/'},
110        {postBody: data}
111      );
112    req.addEventListener(
113      'onSuccess',
114      function (res) {
115        liberator.echo('\u3042\u3081\u30FC\u3070\u306A\u3046: ' + util.escapeString(msg));
116      }
117    );
118    req.post();
119  }
120
121  commands.addUserCommand(
122    ['amebanow', 'nau'], //XXX nau は typo に非ず!かぶり防止
123    'Description',
124    function (args) {
125      let msg = args.literalArg;
126      let mpCmds =
127        let (gv = liberator.globalVariables.amebanow_multipost)
128          (gv ? gv.split('|') : []);
129      getToken(function (token) now(msg, token));
130      mpCmds.forEach(function (cmd) liberator.execute(cmd + ' ' + msg));
131    },
132    {
133      literal: 0,
134    },
135    true
136  );
137
138})();
139
140// vim:sw=2 ts=2 et si fdm=marker:
Note: See TracBrowser for help on using the browser.