Use fetch api

This commit is contained in:
Mimi 2019-12-04 18:30:44 +08:00
parent 619b7e4ace
commit cb77fe55e8

View File

@ -119,7 +119,9 @@ function loadWidget(waifuPath, apiPath) {
function showHitokoto() {
//增加 hitokoto.cn 的 API
if (Math.random() < 0.6 && messageArray.length > 0) showMessage(messageArray[Math.floor(Math.random() * messageArray.length)], 6000, 9);
else $.getJSON("https://v1.hitokoto.cn", function(result) {
else fetch("https://v1.hitokoto.cn")
.then(response => response.json())
.then(result => {
var text = `这句一言来自 <span style="color:#0099cc;">『${result.from}』</span>,是 <span style="color:#0099cc;">${result.creator}</span> 在 hitokoto.cn 投稿的。`;
showMessage(result.hitokoto, 6000, 9);
setTimeout(() => {
@ -154,7 +156,9 @@ function loadWidget(waifuPath, apiPath) {
modelTexturesId = 53; //材质 ID
}
loadModel(modelId, modelTexturesId);
$.getJSON(waifuPath, function(result) {
fetch(waifuPath)
.then(response => response.json())
.then(result => {
result.mouseover.forEach(tips => {
$(document).on("mouseover", tips.selector, function() {
var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text;
@ -195,28 +199,22 @@ function loadWidget(waifuPath, apiPath) {
var modelId = localStorage.getItem("modelId"),
modelTexturesId = localStorage.getItem("modelTexturesId");
//可选 "rand"(随机), "switch"(顺序)
$.ajax({
cache: false,
url: `${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`,
dataType: "json",
success: function(result) {
fetch(`${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`)
.then(response => response.json())
.then(result => {
if (result.textures["id"] == 1 && (modelTexturesId == 1 || modelTexturesId == 0)) showMessage("我还没有其他衣服呢!", 4000, 10);
else showMessage("我的新衣服好看嘛?", 4000, 10);
loadModel(modelId, result.textures["id"]);
}
});
}
function loadOtherModel() {
var modelId = localStorage.getItem("modelId");
$.ajax({
cache: false,
url: `${apiPath}/switch/?id=${modelId}`,
dataType: "json",
success: function(result) {
fetch(`${apiPath}/switch/?id=${modelId}`)
.then(response => response.json())
.then(result => {
loadModel(result.model["id"]);
showMessage(result.model["message"], 4000, 10);
}
});
}
}