Created
August 12, 2017 10:24
-
-
Save mashirozx/b233cc5bce09153de9721445619509c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://storage.mashiro.space/assets/js/hitokoto.min.js"></script> | |
<div> | |
<p class="hitokoto"></p> | |
<p class="from"></p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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