LDRになにかくっつけるときにgeneratorに渡されるオブジェクト

最速インターフェース研究会 :: livedoor Readerに何かくっつけるGreasemonkeyの書き方
を参考にグリモン作ってみている。widgetsのジェネレータに渡されるオブジェクトがよくわからないので調べてみた。

(unsafeWindow||window).entry_widgets.add("hoge", function(feed, item) {
	return [i for (i in feed)].join(',');
}, "hogehoge");

という感じで、オブジェクトの内容を確認列挙してみる。ちなみに内包記法初めて使った。便利だねこれ。

feedオブジェクト
  • ads,
  • subscribe_id
  • channel:フィードに関する情報
    • error_count:???
    • link:発信元サイトのURL
    • description:説明
    • image:アイコン
    • title:タイトル
    • feedlink:フィードのURL
    • subscribers_count:購読者数
    • expires:???
  • items:item(後述)の配列

channelの内容は以下のような感じ

,channel
,error_count#string[0]
,link#string[http://unsigned.g.hatena.ne.jp/Trapezoid/]
,description#string[Dis Communication]
,image#string[]
,title#string[Dis Communication - 「*[vimperator]」の検索結果]
,feedlink#string[http://unsigned.g.hatena.ne.jp/Trapezoid/rss2?word=%2A%5Bvimperator%5D]
,subscribers_count#string[2]
,expires#number[1233261848]
itemオブジェクト
  • enclosure:???
  • link:本文へのリンク
  • enclosure_type:???
  • author:著者
  • body:本文
  • created_on:作成日時
  • modified_on:更新日時
  • id:ID
  • title:タイトル
  • category:カテゴリ

中身はこんな感じ

0,enclosure#string[]
0,link#string[http://unsigned.g.hatena.ne.jp/Trapezoid/20081228/1230428012]
0,enclosure_type
0,author#string[Trapezoid]
0,body#string[[http://vimperator.g.hatena.ne.jp/Trapezoid/20081226/1230268956:title] [http://vimperator.g.hatena.ne.jp/Trapezoid/20081226/1230267916:title] [http://vimperator.g.hatena.ne.jp/Trapezoid/20081219/1229656465:title] 実は色々更新してます。]
0,created_on#number[1230428012]
0,modified_on#number[1230428012]
0,id#string[7108814]
0,title#string[[vimperator]一応こっちでも告知しときますね]
0,category#string[]

itemオブジェクトの内容を列挙するスクリプトも書いてみた。

(unsafeWindow||window).entry_widgets.add("hoge", function(feed, item) {
	var result = [];
	result.push('<div>');
	
	(function discover(level, target){
	   if(typeof target == 'object') 
	     for (i in target) {
		   result.push([level, i].join(','));
		   discover(level+1, target[i]);
		 }
	   else 
	     result.push(["#", typeof target, "[", target, "]"].join(''));

	})(0, item);
	
	result.push('</div>');
    return result.join('<br />');
}, "hogehoge");