Google Feedフィードを読み込むサンプル
コード下記
var pastDay = 15;//何日数前までnewマークをつけるか指定
var now = (new Date()).getTime();//現在の時間
var pastTime = pastDay * 24 * 60 * 60 * 1000;//newマークをつける期間の時間
function initialize() {
var feed = new google.feeds.Feed(“http://xxx.com/?feed=rss2&cat=3");
feed.setNumEntries(5);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById(“newssfeedtable");
var html = “";
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var dd = new Date(entry.publishedDate); // now
var yearNum = dd.getYear();
if (yearNum < 2000) yearNum += 1900;
var m = dd.getMonth() + 1;
if (m < 10) {m = “0" + m;}
var d = dd.getDate();
if (d < 10) {d = “0" + d;}
var date = yearNum + “年" + m + “月" + d + “日";
html += “<li>" + date;
if(now >= dd.getTime() && now <= (dd.getTime() + pastTime)){
//newマークの追加
html += “<img src=’../img/icon-text-new.png’ alt=’新着’>";
}
//console.log(“now:" + now + " dd.getTime:" + dd.getTime() + " pastTime:" + pastTime);
html += “<br><a href='" + entry.link + “' target=’_blank’>" + entry.title + “</a></li>";
container.innerHTML = html;
}
}
});
}
google.setOnLoadCallback(initialize);