Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- place this code on a page in your blog -->
- <script type="text/javascript">
- // Posts in chronological order from feed / MS-potilas 2013 yabtb.blogspot.com
- //
- // Modified slightly in 2017 to make it work with the quirks of the current Blogger editor.
- // The other "chronological view from feed" script stopped working in December 2016 when google dropped their feed API.
- //
- // Configuration:
- var maxResults = 500; // 1-500 (500 is max possible)
- var numPerPage = 7; // post per page, number or "all"
- var feedURI = "/feeds/posts/default";
- // full url could be used, too (read from another blog):
- // var feedURI = "http://yabtb.blogspot.com/feeds/posts/default";
- var theResult = null;
- function doThings() {
- var result = theResult;
- if (!result.error) {
- var container = document.getElementById("feedDiv");
- container.innerHTML = "";
- var strBuffer= "";
- var j = 0;
- var base = parseInt(window.location.hash.replace("#", ""));
- if(isNaN(base) || !base) base = 0;
- if(window.location.hash == "#all" || window.location.hash == "all" || numPerPage == "all")
- numPerPage = result.feed.entry.length;
- for (var i = result.feed.entry.length-1-base; j < numPerPage && i >= 0; i--) {
- var entry = result.feed.entry[i];
- var posturl = "";
- for (var k = 0; k < entry.link.length;k++) {
- if (entry.link[k].rel == 'alternate') {
- posturl = entry.link[k].href;break;
- }
- }
- var datePart = entry.published.$t.match(/\d+/g); // assume ISO 8601
- var postDate = new Date(datePart[0],datePart[1]-1,datePart[2],datePart[3],datePart[4],datePart[5]);
- strBuffer = strBuffer + "<"+"h2 class=\"date-header\">" + postDate.toDateString() + "<"+"/h2>";
- strBuffer = strBuffer + "<"+"h3 class=\"post-title entry-title\"><a href=\"" + posturl + "\">"+ entry.title.$t + "<"+"/a></"+"h3><"+"br />";
- strBuffer = strBuffer + entry.content.$t + "<"+"div class=\"post-footer-line post-footer-line-1\"><div class=\"post-footer\">";
- strBuffer = strBuffer + "Posted by " + entry.author[0].name.$t + " at " + postDate.getHours() + ":" + (postDate.getMinutes() < 10 ? "0":"") + postDate.getMinutes();
- var cmtCnt = entry.thr$total ? entry.thr$total.$t : 0;
- strBuffer = strBuffer + " <a href=\"" + posturl + "#comments\">"+cmtCnt+(cmtCnt==1 ? " comment" : " comments")+"<"+"/a>";
- if(entry.category && entry.category.length) {
- strBuffer = strBuffer + "<"+""+"br />Labels: ";
- for(var z = 0 ; z < entry.category.length ; z++) {
- if(z) strBuffer = strBuffer + ", ";
- strBuffer = strBuffer + "<"+"a href=\"/search/label/" + encodeURIComponent(entry.category[z].term) + "\">" + entry.category[z].term + "<"+"/a>";
- }
- }
- strBuffer = strBuffer + "<"+"/div></"+"div><"+"br /><"+"br />";
- j++;
- }
- strBuffer = strBuffer + "<"+"div style=\"margin-bottom: -1.5em; text-align: center\"><a onclick=\"setTimeout(doThings,500)\" href=\"#0\">First Post</a></"+"div>";
- strBuffer = strBuffer + "<"+"div>";
- if(i>0) strBuffer = strBuffer + "<"+"a onclick=\"setTimeout(doThings,500)\" href=\"#" + (base + numPerPage) + "\">Newer Posts</a>";
- if(base >= numPerPage) strBuffer = strBuffer + "<"+"a style=\"float:right\" onclick=\"setTimeout(doThings,500)\" href=\"#" + (base-numPerPage) + "\">Older Posts</a> ";
- strBuffer = strBuffer + "<"+"/div><"+"br />";
- strBuffer = strBuffer.replace(/<img width=.1. height=.1. [^>]+>/g, "");
- container.innerHTML = strBuffer;
- }
- window.scroll(0,0);
- }
- function feedRead(result) {
- theResult = result;
- doThings();
- }
- function loadFeed() {
- var hd = document.getElementsByTagName('head')[0];
- var sc = document.createElement('script');
- sc.type = 'text/javascript';
- sc.src = feedURI + "?max-results="+maxResults+"&redirect=false&alt=json-in-script&callback=feedRead"+ "&_hash="+Math.random();
- hd.appendChild(sc);
- // clear page title field:
- var elements = document.getElementsByTagName("*");
- for(var i=0 ; i<elements.length ; i++)
- if(/(^| )post-title( |$)/.test(elements[i].className))
- elements[i].parentNode.removeChild(elements[i]);
- }
- window.addEventListener ?
- window.addEventListener("load",loadFeed,false) :
- window.attachEvent && window.attachEvent("onload",loadFeed);
- </script>
- <div id="feedDiv"><i>Loading, please wait...</i></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement