Skip to content

Instantly share code, notes, and snippets.

@J2TEAM
Last active May 30, 2018 23:45
Show Gist options
  • Save J2TEAM/cf6f7910042aa221a89b to your computer and use it in GitHub Desktop.
Save J2TEAM/cf6f7910042aa221a89b to your computer and use it in GitHub Desktop.
Get a random post by using Blogger Feeds API.
function getRandomPost(t){var o=t.feed.entry,n=o[Math.floor(Math.random()*o.length)];window.top.location.href=n.link[4].href}function loadScript(t){var o,n=document.getElementsByTagName("script")[0];o=document.createElement("script"),o.src=t,n.parentNode.insertBefore(o,n)}function randomButtonHandle(){var t=window.top.location,o=t.protocol+"//"+t.hostname+"/feeds/posts/default?alt=json-in-script&max-results=100&callback=getRandomPost";loadScript(o)}randomButtonHandle();
! function(t, o) {
"use strict";
t.getRandomPost = function(o) {
var n = o.feed.entry,
e = n[Math.floor(Math.random() * n.length)];
t.top.location.href = e.link[4].href
}, o(document).ready(function(o) {
var n = t.top.location,
e = n.protocol + "//" + n.hostname + "/feeds/posts/default?alt=json-in-script&max-results=100&callback=getRandomPost";
o("body").append('<script src="' + e + '"></script>')
})
}(window, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment