/*
* @title Count livedoor reader subscribers
* @description livedoor reader 登録数
* @include http://*
* @license MIT License
* @require
*/
var rssURLs;
var allcount = 0;
(function main() {
rssURLs = getRssURLFromDocuments();
var targetURL = rssURLs.shift();
if(targetURL == null) {
alert("Not Found RSS URL");
return;
}
nextFeeds(targetURL);
})();
function nextFeeds(feeds) {
if(feeds == undefined) {
var titleElements = document.getElementsByTagName("title");
var siteTitle = ""
if(titleElements.length > 0) {
siteTitle = titleElements[0].text;
}
alert(siteTitle + "の購読者: " + allcount);
return;
}
var url = 'http://rpc.reader.livedoor.com/count?feedlink=' + encodeURI(feeds) + '&callback=getCount';
loadJS(url);
}
function loadJS(src) {
var script = document.createElement('script');
script.src = src;
script.id = "livedoorreadercount";
document.body.appendChild(script);
}
function getCount(count) {
if(count > 0) {
allcount += parseInt(count);
}
document.body.removeChild(document.getElementById("livedoorreadercount"));
nextFeeds(rssURLs.shift());
}
function getRssURLFromDocuments() {
var linkTags = document.getElementsByTagName("link");
var rss = new Array();
for (var i = 0; i < linkTags.length; i++) {
var elem = linkTags[i];
if (elem.getAttribute("rel") == "alternate" && /(xml|rss)/.test(elem.getAttribute("type"))) {
rss.push(elem.href);
}
}
return rss;
}