HatenaDairy.js

tombloo はてなダイアリーのオレオレ patch 暫定版

models.register( {
	name: 'HatenaDiary',
	ICON: 'http://d.hatena.ne.jp/favicon.ico',
	POST_URL : 'http://d.hatena.ne.jp',
	

	check : function(ps){
		return (/(regular|photo|quote|link)/).test(ps.type) && !ps.file;
	},
	converters: {
		getTitle: function(ps){
			return Hatena.reprTags(ps.tags) + '[' + ps.type + ']'
			//return Hatena.reprTags(ps.tags) + '[' + ps.type + ']'+ (ps.page || '')
		},
		renderingTemplates: {
			regular: '<p>{ps.description}</p>',
			photo:   '<p><blockquote class="tombloo_photo" cite={ps.pageUrl} title={ps.page}><img src={ps.itemUrl} /></blockquote></p>',
			link:    '<p><div class="tombloo_link"><a href={ps.pageUrl} title={ps.page}>{ps.page}</a></div></p>',
			quote:   '<p><blockquote class="tombloo_quote" cite={ps.pageUrl} title={ps.page}>{ps.body}</blockquote></p>',
		},
		__noSuchMethod__: function(name, args){
			var ps = args[0];
			return {
				title: (name == 'regular') ? ps.item : this.getTitle(ps),
				//title: (name == 'regular') ? '' : this.getTitle(ps),
				body: eval( this.renderingTemplates[name] ).toString()
			};
		},
	},
	post : function(params){
		var content;
		var self = this;
		return models.Hatena.getToken().addCallback(function(token){
			content = self.converters[params.type](params);
			content.rkm = token;
			return models.Hatena.getCurrentUser();
		}).addCallback(function(id){
			var endpoint = [self.POST_URL, id, ''].join('/');
			return request( endpoint, {
				redirectionLimit : 0,
				referrer    : endpoint,
				sendContent : content
			});
		});
	}
});