diff options
Diffstat (limited to 'twittperator')
-rw-r--r-- | twittperator/browsing.tw | 131 | ||||
-rw-r--r-- | twittperator/copy.tw | 24 | ||||
-rw-r--r-- | twittperator/eject-alert.tw | 5 | ||||
-rw-r--r-- | twittperator/mstrans.tw | 24 | ||||
-rw-r--r-- | twittperator/ril.tw | 21 | ||||
-rw-r--r-- | twittperator/rt.tw | 44 | ||||
-rw-r--r--[-rwxr-xr-x] | twittperator/twsidebar.tw | 69 |
7 files changed, 309 insertions, 9 deletions
diff --git a/twittperator/browsing.tw b/twittperator/browsing.tw new file mode 100644 index 0000000..6eeeda7 --- /dev/null +++ b/twittperator/browsing.tw @@ -0,0 +1,131 @@ +/* NEW BSD LICENSE {{{ +Copyright (c) 2012, Jagua. +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 # +# に参考になる日本語訳がありますが、有効なのは上記英文となります。 # +################################################################################### + +}}} */ + +/* + * Please write the below line into .vimperatorrc. + * let g:twittperator_plugin_browsing = 1 + * + * You can add the settings for each site + * by setting liberator.globalVariables.tw_browsing_format. + */ + +// INFO {{{ +let INFO = +<> + <plugin name="Now Browsing! Now Reading!" version="1.0.0" + href="http://vimpr.github.com/" + summary="twittperator plugin. assist to tweet about a site you are browsing now." + lang="en-US" + xmlns="http://vimperator.org/namespaces/liberator"> + <author homepage="https://github.com/Jagua">Jagua</author> + <license>New BSD License</license> + <project name="Vimperator" minVersion="3.0"/> + <p>twittperator plugin. assist to tweet about a site you are browsing now.</p> + <item> + <tags>:tw!browsing</tags> + <tags>:tw!reading</tags> + <spec>:tw!browsing <a>comment</a></spec> + <description><p>make a :tw Now browsing prompt</p></description> + <tags>g:tw_browsing_format</tags> + <spec>g:tw_browsing_format = <a>FORMATS OF EACH SITE</a></spec> + <description><p>setting sample</p><code><![CDATA[ +javascript<<EOM +liberator.globalVariables.tw_browsing_format = [{ + url: /^http:\/\/www\.youtube\.com\/watch\?v=[a-zA-Z0-9]+/, + format: function (title, url, selection, comment) { + let r = url; + if (url.match(/^http:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9]+)/)) { + r = 'http://youtu.be/' + RegExp.$1; + } + return title + ' ' + r + ' ' + comment; + }, + },{ + url: /.*/, + format: function (title, url, selection, comment) { + return (selection ? '"' + selection + '" ' : '') + (comment ? comment + ' ' : '') + 'Now reading: ' + title + ' ' + url; + }, + }]; +EOM + ]]></code></description> + </item> + </plugin> +</>; +// }}} + + +(function () { + const TW = liberator.plugins.twittperator; + + var format = liberator.globalVariables.tw_browsing_format || []; + + const default_format = [{ + url: /.*/, + format: function (title, url, selection, comment) { + return (selection ? '"' + selection + '" ' : '') + (comment ? comment + ' ' : '') + 'Now browsing: ' + title + ' ' + url; + }, + }]; + + format = format.concat(default_format); + + function browsing(comment) { + var tweet = ''; + var title = buffer.title; + var url = buffer.URL; + var selection = window.content.getSelection().toString(); + + format.forEach(function (def) { + if (url.match(def.url) && tweet == '') + tweet = def.format(title, url, selection, comment); + }); + return tweet; + } + + ['browsing', 'reading'].forEach(function (cmdName) { + TW.SubCommands.add( + TW.SubCommand({ + command: [cmdName], + description: 'Now ' + cmdName, + action: function(arg) { + setTimeout(function () { + commandline.open(':', 'tw ' + browsing(arg), modes.EX); + }, 100); + }, + timelineComplete: false, + }) + ); + }); + +})(); + +// vim: set et fdm=syntax fenc= ft=javascript sts=2 sw=2 ts=2 : diff --git a/twittperator/copy.tw b/twittperator/copy.tw new file mode 100644 index 0000000..50a280a --- /dev/null +++ b/twittperator/copy.tw @@ -0,0 +1,24 @@ +/* + * Please write the below line into .vimperatorrc. + * let g:twittperator_plugin_copy = 1 + * + */ + +(function () { + const TW = liberator.plugins.twittperator; + + TW.SubCommands.add( + TW.SubCommand({ + command: ['copy'], + description: "Copy a tweet", + action: function(arg) { + util.copyToClipboard(arg); + }, + timelineComplete: true, + completer: TW.Completers.text(function(s) s.id) + }) + ); +})(); + +// vim: set et fdm=syntax fenc= ft=javascript sts=2 sw=2 ts=2 : + diff --git a/twittperator/eject-alert.tw b/twittperator/eject-alert.tw index 9e6fe5a..08b3eaf 100644 --- a/twittperator/eject-alert.tw +++ b/twittperator/eject-alert.tw @@ -1,16 +1,17 @@ /* * Please write the below line into .vimperatorrc. - * let g:twittperator_plugin_reply_eject_alert = 1 + * let g:twittperator_plugin_eject_alert = 1 * let g:twittperator_screen_name = "<YOUR_SCREEN_NAME>" */ (function () { let screenName = liberator.globalVariables.twittperator_screen_name; + let dev = function () (liberator.globalVariables.twittperator_plugin_eject_alert_device || ''); plugins.twittperator.ChirpUserStream.addListener( function onMsg (msg, raw) { if (msg.text && msg.user && msg.in_reply_to_screen_name === screenName) - io.system('eject && eject -t'); + io.system('sh -c "' + ['eject', dev(), '&&', 'eject', '-t', dev()].join(' ') + '" &'); } ); })(); diff --git a/twittperator/mstrans.tw b/twittperator/mstrans.tw new file mode 100644 index 0000000..9f4a582 --- /dev/null +++ b/twittperator/mstrans.tw @@ -0,0 +1,24 @@ +/* + * Please write the below line into .vimperatorrc. + * let g:twittperator_plugin_mstrans = 1 + * + * Require: mstrans.js + */ + +(function () { + const TW = liberator.plugins.twittperator; + + TW.SubCommands.add( + TW.SubCommand({ + command: ['mstrans'], + description: "Translate a tweet", + action: function(arg) { + liberator.execute('mstrans ' + arg); + }, + timelineComplete: true, + completer: TW.Completers.text(function(s) s.id) + }) + ); +})(); + +// vim: set et fdm=syntax fenc= ft=javascript sts=2 sw=2 ts=2 : diff --git a/twittperator/ril.tw b/twittperator/ril.tw new file mode 100644 index 0000000..2b9c430 --- /dev/null +++ b/twittperator/ril.tw @@ -0,0 +1,21 @@ +/* + * Please write the below line into .vimperatorrc. + * let g:twittperator_plugin_ril = 1 + */ + +(function () { + const TW = liberator.plugins.twittperator; + + TW.SubCommands.add( + TW.SubCommand({ + command: ['ril'], + action: function(arg) { + liberator.execute('readitlater add https://twitter.com/' + arg); + }, + timelineCompleter: true, + completer: TW.Completers.statusPage(function(s) s.id) + }) + ); +})(); + +// vim: sw=2 ts=2 et fdm=marker ft=javascript: diff --git a/twittperator/rt.tw b/twittperator/rt.tw new file mode 100644 index 0000000..fde9194 --- /dev/null +++ b/twittperator/rt.tw @@ -0,0 +1,44 @@ +/* + * Please write the below line into .vimperatorrc. + * let g:twittperator_plugin_rt = 1 + */ + +(function () { + const TW = liberator.plugins.twittperator; + + TW.SubCommands.add( + TW.SubCommand({ + command: ['rt'], + description: 'Official retweet', + action: function(arg) { + setTimeout(function () { + commandline.open(':', 'tw RT ' + arg, modes.EX); + }, 100); + }, + timelineComplete: true, + completer: TW.Completers.name_id(function(s) s.id) + }) + ); + + TW.SubCommands.add( + TW.SubCommand({ + command: ['urt'], + description: 'Unofficial retweet', + action: function(arg) { + arg.match(/^@([a-zA-Z0-9_]+)#\d+: (.*)$/); + var screen_name = RegExp.$1; + var text = RegExp.$2; + if (screen_name && text) { + setTimeout(function () { + commandline.open(':', 'tw RT @' + screen_name + ': ' + text, modes.EX); + }, 100); + } + }, + timelineComplete: true, + completer: TW.Completers.name_id_text(function(s) s.id) + }) + ); + +})(); + +// vim: set et fdm=syntax fenc= ft=javascript sts=2 sw=2 ts=2 : diff --git a/twittperator/twsidebar.tw b/twittperator/twsidebar.tw index 0961c00..a9cc9ce 100755..100644 --- a/twittperator/twsidebar.tw +++ b/twittperator/twsidebar.tw @@ -38,6 +38,12 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { // 繝ェ繧ケ繝医ョ譛螟ァ菫晄戟謨ー listMax: 100, + // 繝ェ繧ケ繝医ョ陦ィ遉コ鬆シ域鬆シ城剄鬆シ + listAscendingOrder: true, + + // 繝繧、繝シ繝医&繧後k蠎ヲ縺ォ譛譁ー繝繧、繝シ繝井ス咲スョ縺セ縺ァ繧ケ繧ッ繝ュ繝シ繝ォ縺吶k + listAutoScroll: true, + // 譌・譛ャ隱槭□縺 for filter stream jpOnly: true, @@ -48,7 +54,13 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { dontStop: true, // 繧オ繧、繝峨ヰ繝シ縺碁哩縺倥※縺縺ヲ繧ゅ√%縺」縺昴j髢句ァ九@縺ヲ縺翫¥ - silentStart: false + silentStart: false, + + // 驟榊励°繧ェ繝悶ず繧ァ繧ッ繝医r霑斐☆縺ィ縲∝、画峩縺ァ縺阪k縲 + // 譁蟄怜 "reject" 繧定ソ斐☆縺ィ縲√◎繧ゅ◎繧ゅヤ繧、繝シ繝医′陦ィ遉コ縺輔l縺ェ縺上↑繧九 + modifier: function (msg, tab, streamName) { + return [msg, tab, streamName]; + } }; // 譌・譛ャ隱槫愛螳 @@ -158,6 +170,17 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { function append (t, tab, streamName) { tab = tab || 'home'; + let modified = Config.modifier && Config.modifier(t, tab, streamName); + if (modified) { + if (modified instanceof Array) { + [t, tab, streamName] = modified; + } if (modified === 'reject') { + return; + } else { + t = modified; + } + } + let now = JSON.stringify({name: t.name, text: t.text, tab: tab}); if (latest === now) { if (latestNode) @@ -172,13 +195,47 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { let cntr = getSidebarWindow().document.getElementById('tw-anekos-sb-' + tab + '-list'); let dom = xmlToDom(messageToXML(t)); let repDom = dom.cloneNode(true); + let visibleIndex = cntr.getIndexOfFirstVisibleRow(); let len = cntr.itemCount; - cntr.appendChild(repDom); + if (Config.listAscendingOrder) { + cntr.appendChild(repDom); + } else { + cntr.insertBefore(repDom, cntr.firstChild); + visibleIndex += 1; + } latestNode = repDom; - cntr.scrollToIndex(len - 1); - if (len > Config.listMax) - cntr.removeChild(cntr.firstChild); + if (len > Config.listMax) { + if (Config.listAscendingOrder) { + cntr.removeChild(cntr.firstChild); + visibleIndex -= 1; + } else { + cntr.removeChild(cntr.lastChild); + } + len -= 1; + } + + if (Config.listAutoScroll) { + if (Config.listAscendingOrder) { + cntr.scrollToIndex(len - 1); + } else { + cntr.scrollToIndex(0); + } + } else { + if (Config.listAscendingOrder) { + if (len - visibleIndex < 10) { // 10 = 邨カ螯吶↑蛟、シ√%繧後〒縺縺縺ョ縺具シ + cntr.scrollToIndex(len - 1); + } else { + cntr.scrollToIndex(visibleIndex); + } + } else { + if (visibleIndex < 3) { // 3 = 邨カ螯吶↑蛟、シ√%繧後〒縺縺縺ョ縺具シ + cntr.scrollToIndex(0); + } else { + cntr.scrollToIndex(visibleIndex); + } + } + } } return append; @@ -237,8 +294,6 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { type: 'favorite' }; appendTweet(t, 'home', streamName); - appendTweet(t, 'debug', streamName); - Config.sound.debug.play(); } } catch (e) { liberator.log(e); |