Skip to content

Commit

Permalink
小调整。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed May 18, 2024
1 parent b3704f7 commit 198e08a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
11 changes: 5 additions & 6 deletions p/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@
<div id="bottons">
<input id="auto" type="button" value="手动"/>

<input id="save" type="button" value="收藏" style="margin-left:5px"/>
<input id="remove" type="button" value="删除"/>
<input id="save" type="button" value="未收藏" style="margin-left:10px"/>
<input id="first" type="button" value=""/>
<input id="last" type="button" value=""/>

<input id="changeType" type="button" value="仅收藏" style="margin-left:5px"/>
<input id="prev" type="button" value="上张"/>
<input id="next" type="button" value="下张"/>
<input id="changeType" type="button" value="仅收藏" style="margin-left:10px"/>
<input id="prev" type="button" value="上一张"/>
<input id="next" type="button" value="下一张"/>

<input id="openConfigBtn" type="button" value="配置" style="margin-left:5px"/>
<input id="openConfigBtn" type="button" value="配置" style="margin-left:10px"/>
</div>
</div>

Expand Down
74 changes: 40 additions & 34 deletions p/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const loading = document.getElementById("loading"); // loading效果

const auto = document.getElementById("auto"); // 自动
const save = document.getElementById("save"); // 收藏
const remove = document.getElementById("remove"); // 删除
const first = document.getElementById("first"); // 首:加载第一张收藏
const last = document.getElementById("last"); // 尾:加载最后一张收藏
const changeType = document.getElementById("changeType"); // 切换类型:仅收藏、全部的
Expand Down Expand Up @@ -75,31 +74,28 @@ let inFocus = false; // 输入框是否获取到了焦点
save.addEventListener("click", function () {
const pid = input.value - 0;
if (pid > 0) {
input.style.backgroundColor = '#f1e0b8';

const savePidList = getSavePidList();
for (let i = 0; i < savePidList.length; i++) {
if (pid === savePidList[i]) {
return;
if (save.value === '未收藏') {
inSave();

const savePidList = getSavePidList();
for (let i = 0; i < savePidList.length; i++) {
if (pid === savePidList[i]) {
return;
}
}
}

savePidList.push(pid);
savePidList.sort((a, b) => a - b);
localStorage.setItem("savePidList", JSON.stringify(savePidList));
}
});
// “删除” 按钮点击事件
remove.addEventListener("click", function () {
const pid = input.value - 0;
if (pid > 0) {
const savePidList = getSavePidList();
let index;
while ((index = savePidList.indexOf(pid)) !== -1) {
savePidList.splice(index, 1);
input.style.backgroundColor = '';
savePidList.push(pid);
savePidList.sort((a, b) => a - b);
localStorage.setItem("savePidList", JSON.stringify(savePidList));
} else {
const savePidList = getSavePidList();
let index;
while ((index = savePidList.indexOf(pid)) !== -1) {
savePidList.splice(index, 1);
unSave();
}
localStorage.setItem("savePidList", JSON.stringify(savePidList));
}
localStorage.setItem("savePidList", JSON.stringify(savePidList));
}
});
// “首” 按钮点击事件
Expand All @@ -108,7 +104,7 @@ let inFocus = false; // 输入框是否获取到了焦点
if (savePidList.length > 0) {
const lastSavePid = savePidList[0];
input.value = lastSavePid;
input.style.backgroundColor = '#f1e0b8';
inSave();
doEnter(lastSavePid, false);
}
});
Expand All @@ -118,7 +114,7 @@ let inFocus = false; // 输入框是否获取到了焦点
if (savePidList.length > 0) {
const lastSavePid = savePidList[savePidList.length - 1];
input.value = lastSavePid;
input.style.backgroundColor = '#f1e0b8';
inSave();
doEnter(lastSavePid, false);
}
});
Expand Down Expand Up @@ -439,24 +435,24 @@ function doPrev () {
if (savePid >= pid) {
if (i === 0) {
input.value = pid - 1;
input.style.backgroundColor = '';
unSave();
} else {
input.value = savePidList[i - 1];
input.style.backgroundColor = '#f1e0b8';
inSave();
}
break;
}
}
if (i === savePidList.length) {
input.value = savePidList[i - 1];
input.style.backgroundColor = '#f1e0b8';
inSave();
}
} else {
input.value = pid - 1;
if (changeType.value === '全部的') {
isInSavePidList();
} else {
input.style.backgroundColor = '';
unSave();
}
}
doEnter();
Expand All @@ -477,24 +473,24 @@ function doNext () {
if (savePid <= pid) {
if (i === savePidList.length - 1) {
input.value = pid + 1;
input.style.backgroundColor = '';
unSave();
} else {
input.value = savePidList[i + 1];
input.style.backgroundColor = '#f1e0b8';
inSave();
}
break;
}
}
if (i === -1) {
input.value = savePidList[i + 1];
input.style.backgroundColor = '#f1e0b8';
inSave();
}
} else {
input.value = pid + 1;
if (changeType.value === '全部的') {
isInSavePidList();
} else {
input.style.backgroundColor = '';
unSave();
}
}
doEnter();
Expand Down Expand Up @@ -522,10 +518,20 @@ function isInSavePidList () {
const savePidList = getSavePidList();
for (let i = 0; i < savePidList.length; i++) {
if (pid === savePidList[i]) {
input.style.backgroundColor = '#f1e0b8';
inSave();
return;
}
}
}
unSave();
}

function inSave() {
input.style.backgroundColor = '#f1e0b8';
save.value = "已收藏";
}

function unSave() {
input.style.backgroundColor = '';
save.value = "未收藏";
}

0 comments on commit 198e08a

Please sign in to comment.