From 0b75423c22cb84968b5f69aac24c31b0288adfa4 Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 17 Dec 2008 12:10:02 +0000
Subject: コメント機能追加
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26949 d0d07461-0603-4401-acd4-de1884942a52
---
stella.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 75 insertions(+), 23 deletions(-)
diff --git a/stella.js b/stella.js
index 4e997c4..edb304a 100644
--- a/stella.js
+++ b/stella.js
@@ -292,6 +292,8 @@ Thanks:
delete style.__stella_backup;
}
+ function s2b (s, d) (!/^(\d+|false)$/i.test(s)|parseInt(s)|!!d*2)&1< http://www.nicovideo.jp/watch/sm2586636
- sendComment: function (message, command) {
+ // 自分のコメントが見れないので、うれしくないかも。
+ sendComment: function (message, command, vpos) {
+ let self = this;
- return;
+ // コメント連打を防止
+ {
+ let now = new Date();
+ let last = this.__last_comment_time;
+ if (last && (now.getTime() - last.getTime()) < 5000)
+ return raise('Shurrup!!');
+ this.__last_comment_time = now;
+ }
- let self = this;
- let postkey, block_no, flvInfo, ticket;
function getThumbInfo () {
liberator.log('getThumbInfo')
+ if (self.cachedInfo.block_no !== undefined)
+ return;
let xhr = httpRequest(self.baseURL + 'api/getthumbinfo/' + self.id);
let xml = xhr.responseXML;
let cn = xml.getElementsByTagName('comment_num')[0];
- block_no = cn.textContent.replace(/..$/, '');
- liberator.log('block_no: ' + block_no)
+ self.cachedInfo.block_no = cn.textContent.replace(/..$/, '');
}
+
function getFLV () {
liberator.log('getFLV')
+ if (self.cachedInfo.flvInfo !== undefined)
+ return;
let xhr = httpRequest(self.baseURL + 'api/getflv?v=' + self.id);
let res = xhr.responseText;
- flvInfo = parseParameter(res);
- liberator.log(flvInfo);
+ self.cachedInfo.flvInfo = parseParameter(res);
}
+
function getPostkey (){
liberator.log('getPostkey')
- let url = self.baseURL + 'api/getpostkey?thread=' + flvInfo.thread_id + '&block_no=' + block_no;
+ let info = self.cachedInfo;
+ if (info.postkey !== undefined)
+ return;
+ let url = fromTemplate(
+ '--base--api/getpostkey?thread=--thread_id--&block_no=--block_no--',
+ {
+ base: self.baseURL,
+ thread_id: info.flvInfo.thread_id,
+ block_no: info.block_no
+ }
+ );
+ liberator.log(url)
let xhr = httpRequest(url);
let res = xhr.responseText;
- postkey = res.replace(/^.*=/, '');
+ info.postkey = res.replace(/^.*=/, '');
}
+
function getComments () {
liberator.log('getComments')
+ let info = self.cachedInfo;
+ if (info.ticket !== undefined)
+ return;
let tmpl = '';
- let xhr = httpRequest(flvInfo.ms, fromTemplate(tmpl, flvInfo));
- window.rxml = xhr.responseXML;
- //window.exml = new XML(xhr.responseText);
- let r = rxml.evaluate('//packet/thread', rxml, null, 9, null, 7, null).singleNodeValue;
- ticket = r.getAttribute('ticket');
+ let xhr = httpRequest(info.flvInfo.ms, fromTemplate(tmpl, info.flvInfo));
+ let xml = xhr.responseXML
+ let r = xml.evaluate('//packet/thread', xml, null, 9, null, 7, null).singleNodeValue;
+ info.ticket = r.getAttribute('ticket')
}
- function commentXML () {
+
+ function sendChat () {
+ liberator.log('sendChat')
+ let info = self.cachedInfo;
let tmpl = '--body--';
let args = {
- __proto__: flvInfo,
- ticket: ticket,
- postkey: postkey,
- vpos: 10,
+ __proto__: info.flvInfo,
+ ticket: info.ticket,
+ postkey: info.postkey,
+ // 0 秒コメントはうざいらしいので勝手に自重する
+ vpos: Math.max(100, parseInt(vpos || (self.player.ext_getPlayheadTime() * 100), 10)),
body: message
};
+ liberator.log(args)
let data = fromTemplate(tmpl, args);
- liberator.log();
- let xhr = httpRequest(flvInfo.ms, data);
+ let xhr = httpRequest(info.flvInfo.ms, data);
liberator.log(xhr.responseText)
}
+
liberator.log('sendcommnet')
getThumbInfo();
getFLV();
getPostkey();
getComments();
- commentXML();
+ sendChat();
},
};
@@ -1165,6 +1215,8 @@ Thanks:
add('fe[tch]', 'fetch');
add('la[rge]', 'large');
add('fu[llscreen]', 'fullscreen');
+ if (s2b(liberator.globalVariables.stella_use_nico_comment, false))
+ add('sa[y]', 'say');
commands.addUserCommand(
['strel[ations]'],
--
cgit v1.2.3