Skip to content

Commit

Permalink
Code style update
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jun 13, 2019
1 parent c03643b commit bef89cb
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions waifu-tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ console.log(`
* 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)) {
return;
}
Expand Down Expand Up @@ -100,14 +100,14 @@ function initWidget(waifuPath, apiPath) {
var referrer = document.createElement("a");
referrer.href = document.referrer;
var domain = referrer.hostname.split(".")[1];
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 == '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 text = 'Hello!来自 <span style="color:#0099cc;">' + referrer.hostname + '</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 == "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 text = `Hello!来自 <span style="color:#0099cc;">${referrer.hostname}</span> 的朋友`;
}
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);
}
Expand All @@ -116,8 +116,7 @@ function initWidget(waifuPath, apiPath) {
var userAction = false,
hitokotoTimer = null,
messageTimer = null,
messageArray = ["已经过了这么久了呀,日子过得好快呢……", "使用Chrome可以获得最佳浏览体验哦!", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"],
apiURL = "";
messageArray = ["已经过了这么久了呀,日子过得好快呢……", "使用Chrome可以获得最佳浏览体验哦!", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"];
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
$(document).mousemove(function() {
userAction = true;
Expand Down Expand Up @@ -165,8 +164,6 @@ function initWidget(waifuPath, apiPath) {
}

function initModel() {
waifuPath = waifuPath || "/waifu-tips.json";
apiURL = apiPath || "";
var modelId = localStorage.getItem("modelId"),
modelTexturesId = localStorage.getItem("modelTexturesId");
if (modelId == null) {
Expand Down Expand Up @@ -203,12 +200,13 @@ function initWidget(waifuPath, apiPath) {
});
});
}
initModel();

function loadModel(modelId, modelTexturesId) {
localStorage.setItem("modelId", modelId);
if (modelTexturesId === undefined) modelTexturesId = 0;
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() {
Expand All @@ -217,7 +215,7 @@ function initWidget(waifuPath, apiPath) {
//可选 "rand"(随机), "switch"(顺序)
$.ajax({
cache: false,
url: `${apiURL}/rand_textures/?id=${modelId}-${modelTexturesId}`,
url: `${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`,
dataType: "json",
success: function(result) {
if (result.textures["id"] == 1 && (modelTexturesId == 1 || modelTexturesId == 0)) showMessage("我还没有其他衣服呢!", 4000, 10);
Expand All @@ -231,13 +229,12 @@ function initWidget(waifuPath, apiPath) {
var modelId = localStorage.getItem("modelId");
$.ajax({
cache: false,
url: `${apiURL}/switch/?id=${modelId}`,
url: `${apiPath}/switch/?id=${modelId}`,
dataType: "json",
success: function(result) {
loadModel(result.model["id"]);
showMessage(result.model["message"], 4000, 10);
}
});
}
initModel();
}

0 comments on commit bef89cb

Please sign in to comment.