Advertisement
convoi

archive.min.js

Sep 21st, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Advanced Blogger TOC Script by Taufik Nurrohman
  3.  * URL: https://plus.google.com/108949996304093815163/about
  4.  */
  5. var tocConfig = {
  6.     url: "",
  7.     feedNum: 30,
  8.     labelName: (window.location.hash && window.location.hash != "#0" && window.location.hash != "#search") ? encodeURIComponent(window.location.hash.substr(1)) : false,
  9.     numChars: 150,
  10.     thumbWidth: 70,
  11.     navText: "Next ▼",
  12.     frontText: "Top ⇑",
  13.     noImage: "http://1.bp.blogspot.com/-htG7vy9vIAA/Tp0KrMUdoWI/AAAAAAAABAU/e7XkFtErqsU/s1600/grey.gif",
  14.     loading: "<span>Loading...</span>",
  15.     searching: "<span>Searching...</span>",
  16.     MonthNames: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  17.     noResult: "No Result"
  18. };
  19.  
  20. function getID(b) {
  21.     return document.getElementById(b)
  22. }
  23. var head = document.getElementsByTagName("head")[0],
  24.     tocContainer = getID("feedContainer"),
  25.     feedNav = getID("feedNav"),
  26.     orderByer = getID("orderFeedBy"),
  27.     labelSorter = getID("labelSorter"),
  28.     input = getID("postSearcher").getElementsByTagName("input")[0],
  29.     resultDesc = getID("resultDesc"),
  30.     nextPage, feedArchive, startPage = 0;
  31.  
  32. function cropFeed(d, c) {
  33.     var f = d.split("<");
  34.     for (var e = 0; e < f.length; e++) {
  35.         if (f[e].indexOf(">") != -1) {
  36.             f[e] = f[e].substring(f[e].indexOf(">") + 1, f[e].length)
  37.         }
  38.     }
  39.     f = f.join(" ");
  40.     f = f.substring(0, c - 1);
  41.     return f
  42. }
  43.  
  44. function showLabels(c) {
  45.     var a = c.feed.category,
  46.         d = "";
  47.     d = "<select id='labelSorter' onchange='changeSort(this.value);'>";
  48.     d += "<option value='' selected>CATEGORY...</option>";
  49.     for (var b = 0; b < a.length; b++) {
  50.         d += "<option value='" + decodeURIComponent(a[b].term) + "'>" + a[b].term.toUpperCase() + "</option>"
  51.     }
  52.     d += "</select>";
  53.     labelSorter.innerHTML = d
  54. }
  55.  
  56. function showFeedList(t) {
  57.     var m = t.feed.entry,
  58.         o, s, n, h, e, u, g, p, r, q, c = "";
  59.     if (typeof(t.feed.entry) !== "undefined") {
  60.         for (var f = 0; f < tocConfig.feedNum; f++) {
  61.             o = (m) ? m[f] : "", nextPage = "";
  62.             if (f == t.feed.entry.length) {
  63.                 break
  64.             }
  65.             s = o.title.$t;
  66.             for (var d = 0; d < o.link.length; d++) {
  67.                 if (o.link[d].rel == "alternate") {
  68.                     n = o.link[d].href;
  69.                     break
  70.                 }
  71.             }
  72.             for (var b = 0; b < t.feed.link.length; b++) {
  73.                 if (t.feed.link[b].rel == "next") {
  74.                     nextPage = t.feed.link[b].href
  75.                 }
  76.             }
  77.             for (var a = 0; a < o.link.length; a++) {
  78.                 if (o.link[a].rel == "replies" && o.link[a].type == "text/html") {
  79.                     q = o.link[a].title;
  80.                     break
  81.                 }
  82.             }
  83.             if ("content" in o) {
  84.                 e = o.content.$t
  85.             } else {
  86.                 if ("summary" in o) {
  87.                     e = o.summary.$t
  88.                 } else {
  89.                     e = ""
  90.                 }
  91.             }
  92.             if ("media$thumbnail" in o) {
  93.                 h = o.media$thumbnail.url.replace(/\/s[0-9]+\-c/, "/s" + tocConfig.thumbWidth + "-c")
  94.             } else {
  95.                 h = tocConfig.noImage.replace(/\/s[0-9]+\-c/, "/s" + tocConfig.thumbWidth + "-c")
  96.             }
  97.             postdate = o.published.$t.substring(0, 10), u = postdate.substring(0, 4), g = postdate.substring(5, 7), p = postdate.substring(8, 10), r = tocConfig.MonthNames[parseInt(g, 10) - 1];
  98.             c += "<li><div class='inner'>";
  99.             c += "<a href='" + n + "' target='_blank'><img style='width:" + tocConfig.thumbWidth + "px;height:" + tocConfig.thumbWidth + "px;' src='" + h + "' alt='" + s + "' /></a>";
  100.             c += "<a class='toc-title' href='" + n + "' target='_blank'>" + s + "</a><strong> - (" + q + ")</strong><br>";
  101.             c += "<div class='news-text'>" + cropFeed(e, tocConfig.numChars) + "&hellip;<br style='clear:both;'/></div>";
  102.             c += '<div class="date"><span class="dd">' + p + '</span><span class="dm">' + r + '</span><span class="dy">' + u + "</span></div></div></li>"
  103.         }
  104.         if (input.value !== "" && window.location.hash == "#search") {
  105.             resultDesc.innerHTML = "<span>Search Result for Keyword <strong>&quot;" + input.value + "&quot;</strong></span>"
  106.         } else {
  107.             resultDesc.innerHTML = ""
  108.         }
  109.         feedContainer.innerHTML += c;
  110.         if (nextPage) {
  111.             if (window.location.hash && window.location.hash !== "#0") {
  112.                 c = "<a href='javascript:initResult(2);' class='next'>" + tocConfig.navText + "</a>"
  113.             } else {
  114.                 c = "<a href='javascript:initResult(1);' class='next'>" + tocConfig.navText + "</a>"
  115.             }
  116.         } else {
  117.             c = "<a href='#table-outer' onclick='jQuery(&apos;html, body&apos;).animate({scrollTop: jQuery(&apos;#table-outer&apos;).offset().top}, 1500); return false' class='front'>" + tocConfig.frontText + "</a>"
  118.         }
  119.         feedNav.innerHTML = c;
  120.         input.value = "";
  121.         labelSorter.getElementsByTagName("select")[0].removeAttribute("disabled");
  122.         orderByer.removeAttribute("disabled")
  123.     } else {
  124.         feedContainer.innerHTML = "";
  125.         alert(tocConfig.noResult);
  126.         feedNav.innerHTML = "<a href='?reload=true'>" + tocConfig.frontText + "</a>";
  127.         searchDesc.innerHTML = ""
  128.     }
  129. }
  130.  
  131. function initResult(a) {
  132.     var b, c;
  133.     if (a == 1) {
  134.         b = nextPage.indexOf("?");
  135.         c = nextPage.substring(b)
  136.     } else {
  137.         if (a == 2) {
  138.             b = nextPage.indexOf("?");
  139.             c = nextPage.substring(b).replace(/\?/, "/-/" + window.location.hash.substr(1) + "?")
  140.         } else {
  141.             c = "?start-index=1&max-results=" + tocConfig.feedNum + "&orderby=" + orderByer.value + "&alt=json-in-script"
  142.         }
  143.     }
  144.     c += "&callback=showFeedList";
  145.     updateScript(c)
  146. }
  147.  
  148. function removeScript() {
  149.     var a = getID("temporer-script");
  150.     a.parentNode.removeChild(a)
  151. }
  152.  
  153. function buildLabels() {
  154.     var a = document.createElement("script");
  155.     a.type = "text/javascript";
  156.     a.src = (tocConfig.url === "" ? window.location.protocol + "//" + window.location.host : tocConfig.url) + "/feeds/posts/summary?max-results=0&alt=json-in-script&callback=showLabels";
  157.     head.appendChild(a)
  158. }
  159.  
  160. function updateScript(b) {
  161.     if (startPage == 1) {
  162.         removeScript()
  163.     }
  164.     feedNav.innerHTML = tocConfig.loading;
  165.     if (tocConfig.labelName !== false) {
  166.         feedArchive = (tocConfig.url === "" ? window.location.protocol + "//" + window.location.host : tocConfig.url) + "/feeds/posts/summary/-/" + tocConfig.labelName + b
  167.     } else {
  168.         feedArchive = (tocConfig.url === "" ? window.location.protocol + "//" + window.location.host : tocConfig.url) + "/feeds/posts/summary" + b
  169.     }
  170.     var a = document.createElement("script");
  171.     a.type = "text/javascript";
  172.     a.src = feedArchive;
  173.     a.id = "temporer-script";
  174.     head.appendChild(a);
  175.     startPage = 1
  176. }
  177.  
  178. function changeSort(c) {
  179.     removeScript();
  180.     tocContainer.innerHTML = "";
  181.     feedNav.innerHTML = tocConfig.loading;
  182.     var b = document.createElement("script"),
  183.         d = labelSorter.getElementsByTagName("select")[0],
  184.         a = (c !== 0) ? "/-/" + c : "";
  185.     b.type = "text/javascript";
  186.     b.id = "temporer-script";
  187.     b.src = (tocConfig.url === "" ? window.location.protocol + "//" + window.location.host : tocConfig.url) + "/feeds/posts/summary" + a + "?alt=json-in-script&max-results=" + tocConfig.feedNum + "&orderby=" + orderByer.value + "&callback=showFeedList";
  188.     head.appendChild(b);
  189.     d.disabled = true;
  190.     orderByer.disabled = true;
  191.     window.location.hash = c
  192. }
  193.  
  194. function searchPost() {
  195.     removeScript();
  196.     tocContainer.innerHTML = "";
  197.     resultDesc.innerHTML = "";
  198.     feedNav.innerHTML = tocConfig.searching;
  199.     var a = document.createElement("script");
  200.     a.type = "text/javascript";
  201.     a.id = "temporer-script";
  202.     a.src = (tocConfig.url === "" ? window.location.protocol + "//" + window.location.host : tocConfig.url) + "/feeds/posts/summary?alt=json-in-script&orderby=published&q=" + input.value + "&max-results=9999&callback=showFeedList";
  203.     head.appendChild(a);
  204.     window.location.hash = "#search";
  205.     return false
  206. }
  207. getID("postSearcher").onsubmit = function() {
  208.     return searchPost()
  209. };
  210. orderByer.onchange = function() {
  211.     changeSort(0)
  212. };
  213. labelSorter.getElementsByTagName("select")[0].onchange = function() {
  214.     changeSort(this.value)
  215. };
  216. window.onload = function() {
  217.     initResult(0);
  218.     buildLabels();
  219.     window.location.hash = "#0"
  220. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement