aboutsummaryrefslogtreecommitdiffstats
path: root/twittperator
diff options
context:
space:
mode:
authorJagua2012-06-16 22:13:28 +0900
committerJagua2012-06-16 22:13:28 +0900
commitb6d01fff8fc8b356ff121635303d5191cc286697 (patch)
tree8dd17bf8ee6d369a84c2ffe2a58f5f90c8501966 /twittperator
parentfe95777cfee675a4e489d80a9de613ed51a39000 (diff)
downloadvimperator-plugins-b6d01fff8fc8b356ff121635303d5191cc286697.tar.bz2
Now browsing and Now reading
Diffstat (limited to 'twittperator')
-rw-r--r--twittperator/browsing.tw131
1 files changed, 131 insertions, 0 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 :