mirror of
https://github.com/caojiezi2003/live2d-widget.git
synced 2024-11-22 15:19:44 +00:00
Code style update
This commit is contained in:
parent
c03643b452
commit
bef89cba8f
@ -23,7 +23,7 @@ console.log(`
|
|||||||
* https://www.fghrsh.net/post/123.html
|
* https://www.fghrsh.net/post/123.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function initWidget(waifuPath, apiPath) {
|
function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
|
||||||
if (screen.width <= 768 || (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000)) {
|
if (screen.width <= 768 || (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -100,14 +100,14 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
var referrer = document.createElement("a");
|
var referrer = document.createElement("a");
|
||||||
referrer.href = document.referrer;
|
referrer.href = document.referrer;
|
||||||
var domain = referrer.hostname.split(".")[1];
|
var domain = referrer.hostname.split(".")[1];
|
||||||
if (location.hostname == referrer.hostname) text = '欢迎阅读<span style="color:#0099cc;">『' + document.title.split(' - ')[0] + '』</span>';
|
if (location.hostname == referrer.hostname) text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
||||||
else if (domain == 'baidu') text = 'Hello!来自 百度搜索 的朋友<br/>你是搜索 <span style="color:#0099cc;">' + referrer.search.split('&wd=')[1].split('&')[0] + '</span> 找到的我吗?';
|
else if (domain == "baidu") text = `Hello!来自 百度搜索 的朋友<br/>你是搜索 <span style="color:#0099cc;">${referrer.search.split("&wd=")[1].split("&")[0]}</span> 找到的我吗?`;
|
||||||
else if (domain == 'so') text = 'Hello!来自 360搜索 的朋友<br/>你是搜索 <span style="color:#0099cc;">' + referrer.search.split('&q=')[1].split('&')[0] + '</span> 找到的我吗?';
|
else if (domain == "so") text = `Hello!来自 360搜索 的朋友<br/>你是搜索 <span style="color:#0099cc;">${referrer.search.split("&q=")[1].split("&")[0]}</span> 找到的我吗?`;
|
||||||
else if (domain == 'google') text = 'Hello!来自 谷歌搜索 的朋友<br/>欢迎阅读<span style="color:#0099cc;">『' + document.title.split(' - ')[0] + '』</span>';
|
else if (domain == "google") text = `Hello!来自 谷歌搜索 的朋友<br/>欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
||||||
else text = 'Hello!来自 <span style="color:#0099cc;">' + referrer.hostname + '</span> 的朋友';
|
else text = `Hello!来自 <span style="color:#0099cc;">${referrer.hostname}</span> 的朋友`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(' - ')[0]}』</span>`;
|
text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
||||||
}
|
}
|
||||||
showMessage(text, 7000, 8);
|
showMessage(text, 7000, 8);
|
||||||
}
|
}
|
||||||
@ -116,8 +116,7 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
var userAction = false,
|
var userAction = false,
|
||||||
hitokotoTimer = null,
|
hitokotoTimer = null,
|
||||||
messageTimer = null,
|
messageTimer = null,
|
||||||
messageArray = ["已经过了这么久了呀,日子过得好快呢……", "使用Chrome可以获得最佳浏览体验哦!", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"],
|
messageArray = ["已经过了这么久了呀,日子过得好快呢……", "使用Chrome可以获得最佳浏览体验哦!", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"];
|
||||||
apiURL = "";
|
|
||||||
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
|
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
|
||||||
$(document).mousemove(function() {
|
$(document).mousemove(function() {
|
||||||
userAction = true;
|
userAction = true;
|
||||||
@ -165,8 +164,6 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initModel() {
|
function initModel() {
|
||||||
waifuPath = waifuPath || "/waifu-tips.json";
|
|
||||||
apiURL = apiPath || "";
|
|
||||||
var modelId = localStorage.getItem("modelId"),
|
var modelId = localStorage.getItem("modelId"),
|
||||||
modelTexturesId = localStorage.getItem("modelTexturesId");
|
modelTexturesId = localStorage.getItem("modelTexturesId");
|
||||||
if (modelId == null) {
|
if (modelId == null) {
|
||||||
@ -203,12 +200,13 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
initModel();
|
||||||
|
|
||||||
function loadModel(modelId, modelTexturesId) {
|
function loadModel(modelId, modelTexturesId) {
|
||||||
localStorage.setItem("modelId", modelId);
|
localStorage.setItem("modelId", modelId);
|
||||||
if (modelTexturesId === undefined) modelTexturesId = 0;
|
if (modelTexturesId === undefined) modelTexturesId = 0;
|
||||||
localStorage.setItem("modelTexturesId", modelTexturesId);
|
localStorage.setItem("modelTexturesId", modelTexturesId);
|
||||||
loadlive2d("live2d", `${apiURL}/get/?id=${modelId}-${modelTexturesId}`, console.log("live2d", `模型 ${modelId}-${modelTexturesId} 加载完成`));
|
loadlive2d("live2d", `${apiPath}/get/?id=${modelId}-${modelTexturesId}`, console.log("live2d", `模型 ${modelId}-${modelTexturesId} 加载完成`));
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadRandModel() {
|
function loadRandModel() {
|
||||||
@ -217,7 +215,7 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
//可选 "rand"(随机), "switch"(顺序)
|
//可选 "rand"(随机), "switch"(顺序)
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
url: `${apiURL}/rand_textures/?id=${modelId}-${modelTexturesId}`,
|
url: `${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
if (result.textures["id"] == 1 && (modelTexturesId == 1 || modelTexturesId == 0)) showMessage("我还没有其他衣服呢!", 4000, 10);
|
if (result.textures["id"] == 1 && (modelTexturesId == 1 || modelTexturesId == 0)) showMessage("我还没有其他衣服呢!", 4000, 10);
|
||||||
@ -231,7 +229,7 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
var modelId = localStorage.getItem("modelId");
|
var modelId = localStorage.getItem("modelId");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
url: `${apiURL}/switch/?id=${modelId}`,
|
url: `${apiPath}/switch/?id=${modelId}`,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
loadModel(result.model["id"]);
|
loadModel(result.model["id"]);
|
||||||
@ -239,5 +237,4 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
initModel();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user