Buzzurl + Tombloo をでっち上げる件
というわけで、昨日のエントリに引き続き、大分前にでっち上げたTomblooのBuzzurl対応スクリプトです。
一番下のスクリプトを「20_Buzzurl.js」という名前にして保存して、昨日のエントリにも書いた、拡張スクリプト用のフォルダの中に突っ込めばFFのメニューBuzzurlが現れると思います。
Evernote + Tombloo をでっち上げる件 - Study03.net 対シンバシ専用
Buzzurl対応するときに困ったのは、Tomblooの中で定義されている、クエリパラメータを構成する関数(queryString)が、POSTパラメータの名前がユニークである事前提ぽいのに対してBuzzurlのタグ用のPOSTパラメータは8個全てkeywordという名前で送られてくるという事でした。
なので完全にバッドなハックではありますが、queryStringを別で作って、keywordという名前のパラメータの場合にだけ、よしなにクエリパラメータを構成してくれるような感じにしました。
それにしても,相変わらずベースはid:Constellationさんのパクリでしかないですね。。。
id:Constellationさん、本当にありがとうございます。
※ タグ補完の部分に関しては実装していませんのであしからず
if(typeof(models)=='undefined') this.models = models = new Repository(); function queryString(params, question){ if(isEmpty(params)) return ''; if(typeof(params)=='string') return params; var qeries = []; for(var key in params){ var value = params[key]; if(value==null) continue; if(key == 'keyword') { for(var k in value) { var v = value[k]; if (v==null) { continue; } qeries.push(encodeURIComponent('keyword')+'='+encodeURIComponent(v)); } }else{ qeries.push(encodeURIComponent(key) + '='+ encodeURIComponent(value)); } } return (question? '?' : '') + qeries.join('&'); } models.register(update({ name : 'Buzzurl', ICON : 'http://buzzurl.jp/favicon.ico', POST_URL : 'https://buzzurl.jp/config/add/execute', CONFIRM_URL : 'https://buzzurl.jp/config/add/confirm', check : function(ps){ return (/(quote|link|conversation|video)/).test(ps.type) && !ps.file; }, post : function(ps){ var Buzzurl = this; return Buzzurl.getToken(ps).addCallback(function(token){ var content = { thumbprint: token.thumbprint, url: ps.itemUrl, title: ps.item, comment: joinText([ps.body, ps.description], ' ', true), keyword: ps.tags, user_num: token.user_num ? token.user_num : '', access: ps.private ? '5' : '0', }; return request(Buzzurl.POST_URL, { redirectionLimit : 0, sendContent : content, }); }); }, getAuthCookie : function(){ return getCookieString('buzzurl.jp', 'BNS'); }, getToken : function(ps){ var Buzzurl = this; switch (this.updateSession()){ case 'none': throw new Error(getMessage('error.notLoggedin')); case 'same': case 'changed': var self = this; return request(Buzzurl.CONFIRM_URL+'?url='+encodeURIComponent(ps.itemUrl)).addCallback(function(res){ //thumbprint if(res.responseText.match(/"thumbprint" value="(.*)"/)){ self.thumbprint = RegExp.$1; }else{ throw new Error(getMessage('error.notLoggedin')); } //user_num if(res.responseText.match(/"user_num" value="(.*)"/)){ self.user_num = RegExp.$1; }else{ throw new Error(getMessage('error.notLoggedin')); } return self; }); } }, }, AbstractSessionService));