拡張機能「sage」にて、はてなRSSのサイト名を表示させる

2018年2月18日

この記事は最初の投稿日から18年経過しています。内容が古い可能性があります。

FireFox にしてから、RSSリーダとして Sage を使うようになりました。

Sage に「はてなRSS」を登録しているのですが、はてなRSSの場合、複数サイトのRSSが統合されているので、「コンテンツエリアにフィードを読み込む」設定にした時に、表示されているアイテムがどのサイトの記事なのか、一目でわかりません。

はてなRSSの rss を覗いてみると、<ag:source></ag:source>にサイトの名称が入っているようなので、その値を Sage 1.3.6 で表示できるように改造してみました。

sage.jar をほどいて個別のファイルを修正し、また jar に固めてやることで改造できます。

修正したのは、

  • content/createhtml.js
  • content/feedlib.js
  • content/res/template-item.txt
  • スタイルシート(sage.css)(ユーザスタイルシートを使っていればそれ)

の4つ。以下は、それぞれのdiffです。Sage 1.3.6 を改造しています。

注意)改造を加えることにより、予期せぬ問題が発生する可能性があります。利用は各人の責任においてお願いいたします。


content/createhtml.js

diff -ur sage.original/content/createhtml.js sage/content/createhtml.js
--- sage.original/content/createhtml.js	2005-09-14 19:49:32.000000000 +0900
+++ sage/content/createhtml.js	2006-03-15 17:52:42.000000000 +0900
@@ -90,6 +90,7 @@
var title = items[i].getTitle();
var description = "";
var pubDate = "";
+			var source = "";
if(items[i].hasContent()) {
description = allowEContent ? items[i].getContent() : htmlToText(items[i].getContent());
@@ -99,7 +100,9 @@
if(items[i].hasPubDate()) {
pubDate = "<div class=\"item-pubDate\">" + dateFormat(items[i].getPubDate(), twelveHourClock) + "</div>";
}
-
+			if (items[i].hasSource()) {
+				source = items[i].getSource();
+			}
var itemSource = this.ITEM_SOURCE;
itemSource = itemSource.replace("**NUMBER**", i+1);
itemSource = itemSource.replace("**LINK**", link);
@@ -107,6 +110,7 @@
itemSource = itemSource.replace("**TITLE**", title);
itemSource = itemSource.replace("**DESCRIPTION**", description);
itemSource = itemSource.replace("**PUBDATE**", pubDate);
+			itemSource = itemSource.replace("**SOURCE**", source);
itemsSource += itemSource;
}
htmlSource = htmlSource.replace("**ITEMS**", itemsSource);

content/feedlib.js

diff -ur sage.original/content/feedlib.js sage/content/feedlib.js
--- sage.original/content/feedlib.js	2005-09-14 19:49:32.000000000 +0900
+++ sage/content/feedlib.js	2006-03-15 17:54:30.000000000 +0900
@@ -84,7 +84,7 @@
var itemNodes = feedXML.getElementsByTagName("item");
var item, guid;
for(i = 0; itemNodes.length > i; i++) {
-		item = {title:"", link:"", content:"", pubDate:""};
+		item = {title:"", link:"", content:"", pubDate:"", source:""};
guid = null;
for (j = itemNodes[i].firstChild; j!=null; j=j.nextSibling) {
@@ -129,6 +129,9 @@
logMessage("unable to parse date string: " + tmp_str + " feed: " + this.title);
}
break;
+				case "source":
+					item.source = CommonFunc.getInnerText(j);
+					break;
}
}
@@ -136,7 +139,7 @@
item.link = this.link ? URIFixup.createFixupURI(this.link, nsIURIFixup.FIXUP_FLAG_NONE).resolve(guid) : guid;
}
-		var tmpFeedItem = new FeedItem(item.title, item.link, item.content, item.pubDate, null);
+		var tmpFeedItem = new FeedItem(item.title, item.link, item.content, item.pubDate, null, item.source);
if (tmpFeedItem.hasPubDate()) {
if (tmpFeedItem.getPubDate() > this.lastPubDate) {
@@ -282,7 +285,7 @@
item.content = CommonFunc.getInnerText(summaryNodes[0]);
}
-		var tmpFeedItem = new FeedItem(item.title, item.link, item.content, item.pubDate, item.baseURI);
+		var tmpFeedItem = new FeedItem(item.title, item.link, item.content, item.pubDate, item.baseURI, null);
if (tmpFeedItem.hasPubDate()) {
if (tmpFeedItem.getPubDate() > this.lastPubDate) {
@@ -391,12 +394,13 @@
*
*/
-function FeedItem(title, link, content, pubDate, baseURI) {
+function FeedItem(title, link, content, pubDate, baseURI, source) {
this.title = title;
this.link = link;
this.content = content;
this.pubDate = pubDate;
this.baseURI = baseURI;
+	this.source = source;
}
FeedItem.prototype.hasTitle = function() {
@@ -467,6 +471,22 @@
return this.hasBaseURI() ? this.baseURI : null;
}
+FeedItem.prototype.hasSource = function() {
+	if(!this.source) {
+		return false;
+	} else {
+		return true;
+	}
+}
+
+FeedItem.prototype.getSource = function() {
+	if(this.hasSource()) {
+		return this.source;
+	} else {
+		return "No source";
+	}
+}
+
/**
* Utility functions

content/res/template-item.txt

以下をTechnorati近辺に追加。

<div class="item-source">**SOURCE**</div>

スタイルシート

「div.item-source {~}」を追加

私は、Technorati の定義を参考にしつつ右下に出るように追加しました。

FireFox

Posted by toshyon