Skip to content

Instantly share code, notes, and snippets.

@jixunmoe
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jixunmoe/28e2d34992f1ec56d68c to your computer and use it in GitHub Desktop.
Save jixunmoe/28e2d34992f1ec56d68c to your computer and use it in GitHub Desktop.
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