Skip to content

Instantly share code, notes, and snippets.

@jixunmoe jixunmoe/Hitokoto.url.js
Last active Aug 29, 2015

Embed
What would you like to do?
Hitokoto.url.js
(function (window, location, document) {
if (!window.history || (location.hash && location.hash[1] != '#'))
return ;
var np = 'hitokoto_' + + new Date;
window[np] = function (hitokoto) {
history.replaceState(null, null, '##' + hitokoto.hitokoto + ' <-- ' + hitokoto.source);
};
var keepUpdate = function () {
var $sc = document.createElement ('script');
$sc.src = 'http://api.hitokoto.us/rand?cat=a&encode=jsc&fun=' + np + '&_r=' + +new Date;
document.head.appendChild ($sc);
$sc.onload = $sc.removeChild.bind($sc.parentNode, $sc);
};
setInterval (keepUpdate, 20000);
keepUpdate();
})(window, location, document);
(function(b,c,d){if(b.history&&(!c.hash||"#"==c.hash[1])){var e="hitokoto_"+ +new Date;b[e]=function(a){history.replaceState(null,null,"##"+a.hitokoto+" <-- "+a.source)};b=function(){var a=d.createElement("script");a.src="http://api.hitokoto.us/rand?cat=a&encode=jsc&fun="+e+"&_r="+ +new Date;d.head.appendChild(a);a.onload=a.removeChild.bind(a.parentNode,a)};setInterval(b,2E4);b()}})(window,location,document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.