Skip to content

Instantly share code, notes, and snippets.

@mashirozx
Created August 12, 2017 10:24
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 mashirozx/b233cc5bce09153de9721445619509c1 to your computer and use it in GitHub Desktop.
Save mashirozx/b233cc5bce09153de9721445619509c1 to your computer and use it in GitHub Desktop.
<script src="https://storage.mashiro.space/assets/js/hitokoto.min.js"></script>
<div>
<p class="hitokoto"></p>
<p class="from"></p>
</div>
window.onload=function () {
var hitokoto = document.querySelector('.hitokoto');
var from = document.querySelector('.from');
update();
function update() {
gethi = new XMLHttpRequest();
gethi.open("GET","https://sslapi.hitokoto.cn/?c=a"); //这里选择类别,详见官方文档http://hitokoto.cn/api
gethi.send();
gethi.onreadystatechange = function () {
if (gethi.readyState===4 && gethi.status===200) {
var Hi = JSON.parse(gethi.responseText);
hitokoto.innerHTML = Hi.hitokoto;
from.innerHTML = "from: <b>" + Hi.from + "</b>"; //可自定义输出格式
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment