rickdog
10/31/2013 - 6:52 AM

xxx

xxx

<!DOCTYPE html>
<html class="no-js">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0" type="text/javascript"></script>
<script src="https://gist.github.com/rickdog/7245244/raw/0ffbc45f3ef248a714ea06543f53c75ad4fd7836/zoom.js" type="text/javascript"></script>
</head>

<body>

feed: <input id="url" type="text" size="80"/> <button onclick="loadUrl();">GO</button>

<h1 id="feedName"></h1>
<h1>historical feed items XML (master - DON'T SAVE IN Scrapbook)</h1>


<div id="display">
	<ol id="list">
	</ol>
</div>


<script type="text/javascript">
/*
 * Google feed API with history in XML.
 * The feed items are rendered as an OL list with H3 headers that have click events.
 * The click events load the item's content from a saved array of content(see var page[]).
 * This prevents the rendering of the entire feed and only renders the item when it's header is clicked.
 */
// Wordpress export is RSS!: http://rickshide.com/wordpress.2013-07-15
// blog search, must use rss & num <=50: https://www.google.com/search?hl=en&lr=&q=mp3%20blog&tbm=blg&output=rss&num=50


google.load("feeds", "1");

var page;


function loadUrl()
{
	var url = $("#url").val();
	document.title = url;
	$("#feedName").innerHTML = url;
	OnLoad(url);
}

var addList = function(n, title, page)
{
	var h3 = document.createElement("h3");
	h3.innerHTML = title;
	h3.page = page;
	$(h3).click(function()
	{
		if (this.nextSibling.innerHTML.length == 0)
			this.nextSibling.innerHTML = this.page;
		else
			this.nextSibling.innerHTML = "";
	});
	$("#list").append('<li><div"></div></li>');
	$("#list li").last().prepend(h3);
};

function OnLoad(url)
{
	if (typeof url != "string")	// an initial call happens from google.setOnLoadCallback(OnLoad); (see end of this script), url is an Event
		return;
		
	// Create a feed instance that will grab feed.
	var feed = new google.feeds.Feed(url);

	// Request the results in XML
	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	feed.includeHistoricalEntries(); 
	feed.setNumEntries(250); // we want a maximum of 250 entries, if they exist

	// Calling load sends the request off.  It requires a callback function.
	feed.load(feedLoaded);
}


// Our callback function, for when a feed is loaded.
function feedLoaded(result)
{
	if (result.error)
	{
		$("#feedName").html("code: "+result.error.code + "<br/>" + result.error.message);
		return false;
	}

	$("#feedName").html(result.xmlDocument.getElementsByTagName('title')[0].textContent + "<br/>" + document.title);

	var list = $('#list');
	list.html("");
	page = [];

	// Get all items returned.
	var type = result.xmlDocument.documentElement.tagName;
	var items = null;
	if (type == "feed")
		items = result.xmlDocument.getElementsByTagName('entry');
	else if (type == "rss")
		items = result.xmlDocument.getElementsByTagName('item');
	else
		alert(type); 

	// Loop through our items
	for (var i = 0; i < items.length; i++)
	{
		var item = items[i];

		// Get the title from the element.  firstChild is the text node containing
		// the title, and nodeValue returns the value of it.
		var title = item.getElementsByTagName('title')[0].firstChild.nodeValue;
		
		var cont;
		if ((cont = item.getElementsByTagName('content')).length)
			cont = cont[0].firstChild.nodeValue;
		else if ((cont = item.getElementsByTagName('content:encoded')).length)
			cont = cont[0].firstChild.nodeValue;
		else if ((cont = item.getElementsByTagName('description')).length)
			cont = cont[0].firstChild.nodeValue;
		else if ((cont = item.getElementsByTagName('summary')).length)
			cont = cont[0].firstChild.nodeValue;
		else
			cont = "<br/><br/>(no content)";

		var link = item.getElementsByTagName('link');
		if (link.length) {
			if (link[0].childNodes.length)  // TODO: loop thru & get for rel="alternate"
				link = link[0].firstChild.nodeValue;
			else if (link[0].hasAttributes("href"))
				link = link[0].getAttribute("href");
		}

		var ln = "<a href='" + link + "' target=_blank>" + title + "</a><br/>";
		var date;
		if ((date = item.getElementsByTagName('pubDate')).length)
			date = date[0].firstChild.nodeValue;
		else if ((date = item.getElementsByTagName('published')).length)
			date = date[0].firstChild.nodeValue;
		else if ((date = item.getElementsByTagName('updated')).length)
			date = date[0].firstChild.nodeValue;
		else
			date = "(no date)";

		var author = item.getElementsByTagName('author');
		if (author.length)
		{
			if (author[0].getElementsByTagName("name").length)
				date = "By: " + author[0].getElementsByTagName("name")[0].textContent + "<br/>" + date;
			else if (author[0].childElementCount)
				date = "By: " + author[0].firstChild.nodeValue + "<br/>" + date;
			else
				date = "By: " + author[0].textContent;
		}
		var category = item.getElementsByTagName('category');
		var cats = "";
		for (j = 0; j < category.length; j++)
		{
			if (category[j].firstChild)
				cats += (j > 0 ? ", " : "") + category[j].firstChild.nodeValue;
			else
				cats += (j > 0 ? ", " : "") + category[j].getAttribute("term");
		}

		page[i] = ln + date + "<br/>" + (cats.length ? "Categories: "  + cats : "") + cont + "<br/><br/>";
		addList(i, title, page[i]);
	}
}

google.setOnLoadCallback(OnLoad);

</script>

 

</body>
</html>