diff --git a/dist/jhs-enhance.user.js b/dist/jhs-enhance.user.js index 882edff..bb8fffd 100644 --- a/dist/jhs-enhance.user.js +++ b/dist/jhs-enhance.user.js @@ -8082,47 +8082,49 @@ ${err.stack}` : ""); } return fileId; } - async deleteOfflineTasksByKeyword(keyword) { - try { - const singInfo = await (async () => { - const res = await gmHttp.get("https://115.com/?ct=offline&ac=space&_=" + (/* @__PURE__ */ new Date()).getTime()); - return "object" == typeof res ? res : null; - })(); - if (!singInfo) { - console.error("删除离线任务: 未登录115网盘"); - return; - } - const {sign, time} = singInfo, uid = singInfo.uid || (() => { - const match = document.cookie.match(/UID=(\d+)_/); - return match ? match[1] : null; - })() || await this.getUserId(); - const taskListRes = await gmHttp.postForm("https://115.com/web/lixian/?ct=lixian&ac=task_lists", { - page: 1, - uid, - sign, - time - }); - const tasks = (null == taskListRes ? void 0 : taskListRes.tasks) || []; - const keyword2 = keyword.toLowerCase().replace("fc2-", ""); - let deletedCount = 0; - for (const task of tasks) { - if (task.name && task.name.toLowerCase().includes(keyword2)) { - console.log(`删除离线任务: ${task.name} (hash: ${task.info_hash})`); - await gmHttp.postForm("https://115.com/web/lixian/?ct=lixian&ac=task_del", { - "hash[0]": task.info_hash, - flag: 1, - uid, - sign, - time - }); - deletedCount++; - } - } - deletedCount > 0 && console.log(`共删除 ${deletedCount} 个离线任务`); - } catch (error) { - console.error("删除离线任务失败:", error); - } - } + + //TODO: 暂时没有删除离线任务 + // async deleteOfflineTasksByKeyword(keyword) { + // try { + // const singInfo = await (async () => { + // const res = await gmHttp.get("https://115.com/?ct=offline&ac=space&_=" + (new Date).getTime()); + // return "object" == typeof res ? res : null; + // })(); + // if (!singInfo) { + // console.error("删除离线任务: 未登录115网盘"); + // return; + // } + // const {sign: sign, time: time} = singInfo, uid = singInfo.uid || (() => { + // const match = document.cookie.match(/UID=(\d+)_/); + // return match ? match[1] : null; + // })() || await this.getUserId(); + // const taskListRes = await gmHttp.postForm("https://115.com/web/lixian/?ct=lixian&ac=task_lists", { + // page: 1, + // uid: uid, + // sign: sign, + // time: time + // }); + // const tasks = (null == taskListRes ? void 0 : taskListRes.tasks) || []; + // const keyword2 = keyword.toLowerCase().replace("fc2-", ""); + // let deletedCount = 0; + // for (const task of tasks) { + // if (task.name && task.name.toLowerCase().includes(keyword2)) { + // console.log(`删除离线任务: ${task.name} (hash: ${task.info_hash})`); + // await gmHttp.postForm("https://115.com/web/lixian/?ct=lixian&ac=task_del", { + // "hash[0]": task.info_hash, + // flag: 1, + // uid: uid, + // sign: sign, + // time: time + // }); + // deletedCount++; + // } + // } + // deletedCount > 0 && console.log(`共删除 ${deletedCount} 个离线任务`); + // } catch (error) { + // console.error("删除离线任务失败:", error); + // } + // } } class ScreenShotPlugin extends BasePlugin { getName() { @@ -8553,6 +8555,19 @@ ${err.stack}` : ""); event.stopPropagation(); await this.retryMatch(event.currentTarget); })); + $(document).on("click", ".jhs-detail-delete-btn", (async (event) => { + event.preventDefault(); + event.stopPropagation(); + const $btn = $(event.currentTarget); + const matchData = $btn.attr("data-match"); + if (!matchData) return; + const matchList = JSON.parse(matchData); + const carNum2 = this.getPageInfo().carNum; + this.showDeleteDialog(carNum2, matchList, (async (newMatchList) => { + $("#115-match-table").remove(); + await this.matchDetailPage(newMatchList); + })); + })); await this.matchDetailPage(); $(document).on("click", ".jhs-match-detail-error-btn", (async (event) => { event.preventDefault(); @@ -8596,6 +8611,11 @@ ${err.stack}` : ""); `)).join(""); $tbody.append(rowsHtml); + $detail.css("position", "relative"); + $detail.append(`🗑️ 删除`); } else $tbody.append(` { + if (!bytes) return "-"; + const units = ["B", "KB", "MB", "GB", "TB"]; + let size = parseFloat(bytes), unit = 0; + for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++; + return size.toFixed(2) + " " + units[unit]; + }; + let html = '
'; + html += `
作品 ${carNum2} 匹配到 ${matchList.length} 个文件夹:
`; + html += '
'; + for (let i = 0; i < matchList.length; i++) { + const m = matchList[i]; + html += `
+ +
`; + } + html += "
"; + const layerIndex = layer.open({ + type: 1, + title: "删除115作品文件夹", + content: html, + area: ["520px", "auto"], + btn: ["确定删除", "取消"], + shadeClose: false, + yes: async (index) => { + const $layer = $(`#layui-layer${index}`); + const checked = $layer.find(".jhs-delete-folder-cb:checked"); + if (0 === checked.length) { + show.error("请至少选择一个文件夹"); + return; + } + const selected = checked.map((function () { + return parseInt($(this).data("index")); + })).get(); + layer.close(index); + let loadObj = loading(); + let deletedCount = 0; + try { + for (const i of selected) { + const m = matchList[i]; + const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", { + pid: m.dirId, + "fid[0]": m.folderId + }); + result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result); + } + loadObj.close(); + show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`); + const newMatchList = await this.searchFiles(carNum2); + afterDelete && afterDelete(newMatchList); + this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2); + } catch (error) { + loadObj.close(); + console.error("删除115文件失败:", error); + show.error(`删除失败: ${error.message || "网络错误"}`); + } + } + }); + $(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () { + const checked = $(this).prop("checked"); + $(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked); + })); + } async handleLoginRedirect() { window.open("https://115.com"); } @@ -10114,79 +10205,9 @@ ${err.stack}` : ""); const matchList = JSON.parse(matchData); const $box2 = $btn.closest(".item"); const { carNum: carNum2 } = this.getBoxCarInfo($box2); - this.showDeleteDialog(carNum2, matchList, $box2); - })); - } - - showDeleteDialog(carNum2, matchList, $box2) { - const formatSize = (bytes) => { - if (!bytes) return "-"; - const units = ["B", "KB", "MB", "GB", "TB"]; - let size = parseFloat(bytes), unit = 0; - for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++; - return size.toFixed(2) + " " + units[unit]; - }; - let html = '
'; - html += `
作品 ${carNum2} 匹配到 ${matchList.length} 个文件夹:
`; - html += '
'; - for (let i = 0; i < matchList.length; i++) { - const m = matchList[i]; - html += `
- -
`; - } - html += "
"; - const layerIndex = layer.open({ - type: 1, - title: `删除115作品文件夹`, - content: html, - area: ["520px", "auto"], - btn: ["确定删除", "取消"], - shadeClose: false, - yes: async (index) => { - const $layer = $(`#layui-layer${index}`); - const checked = $layer.find(".jhs-delete-folder-cb:checked"); - if (0 === checked.length) { - show.error("请至少选择一个文件夹"); - return; - } - const selected = checked.map((function () { - return parseInt($(this).data("index")); - })).get(); - layer.close(index); - let loadObj = loading(); - let deletedCount = 0; - try { - for (const i of selected) { - const m = matchList[i]; - const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", { - pid: m.dirId, - "fid[0]": m.folderId - }); - result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result); - } - loadObj.close(); - show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`); - const matchPlugin = this.getBean("WangPan115MatchPlugin"); - const newMatchList = await matchPlugin.searchFiles(carNum2); - matchPlugin.updateMatchStatus($box2, carNum2, newMatchList); - this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2); - } catch (error) { - loadObj.close(); - console.error("删除115文件失败:", error); - show.error(`删除失败: ${error.message || "网络错误"}`); - } - } - }); - $(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () { - const checked = $(this).prop("checked"); - $(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked); + this.getBean("WangPan115MatchPlugin").showDeleteDialog(carNum2, matchList, (async (newMatchList) => { + this.getBean("WangPan115MatchPlugin").updateMatchStatus($box2, carNum2, newMatchList); + })); })); } showImg($svgElement, $img, carNum2) { diff --git a/src/plugins/cover-button.js b/src/plugins/cover-button.js index 8e0df64..a1952dd 100644 --- a/src/plugins/cover-button.js +++ b/src/plugins/cover-button.js @@ -147,80 +147,9 @@ class CoverButtonPlugin extends BasePlugin { const matchList = JSON.parse(matchData); const $box2 = $btn.closest(".item"); const {carNum: carNum2} = this.getBoxCarInfo($box2); - this.showDeleteDialog(carNum2, matchList, $box2); - })); - } - - showDeleteDialog(carNum2, matchList, $box2) { - const formatSize = bytes => { - if (!bytes) return "-"; - const units = ["B", "KB", "MB", "GB", "TB"]; - let size = parseFloat(bytes), unit = 0; - for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++; - return size.toFixed(2) + " " + units[unit]; - }; - let html = '
'; - html += `
作品 ${carNum2} 匹配到 ${matchList.length} 个文件夹:
`; - html += '
'; - for (let i = 0; i < matchList.length; i++) { - const m = matchList[i]; - html += `
- -
`; - } - html += "
"; - const layerIndex = layer.open({ - type: 1, - title: `删除115作品文件夹`, - content: html, - area: ["520px", "auto"], - btn: ["确定删除", "取消"], - shadeClose: !1, - yes: async index => { - const $layer = $(`#layui-layer${index}`); - const checked = $layer.find(".jhs-delete-folder-cb:checked"); - if (0 === checked.length) { - show.error("请至少选择一个文件夹"); - return; - } - const selected = checked.map((function () { - return parseInt($(this).data("index")); - })).get(); - layer.close(index); - let loadObj = loading(); - let deletedCount = 0; - try { - for (const i of selected) { - const m = matchList[i]; - const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", { - pid: m.dirId, - "fid[0]": m.folderId - }); - result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result); - } - loadObj.close(); - show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`); - const matchPlugin = this.getBean("WangPan115MatchPlugin"); - const newMatchList = await matchPlugin.searchFiles(carNum2); - matchPlugin.updateMatchStatus($box2, carNum2, newMatchList); - //暂时没有删除离线任务的功能 - //this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2); - } catch (error) { - loadObj.close(); - console.error("删除115文件失败:", error); - show.error(`删除失败: ${error.message || "网络错误"}`); - } - } - }); - $(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () { - const checked = $(this).prop("checked"); - $(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked); + this.getBean("WangPan115MatchPlugin").showDeleteDialog(carNum2, matchList, (async newMatchList => { + this.getBean("WangPan115MatchPlugin").updateMatchStatus($box2, carNum2, newMatchList); + })); })); } showImg($svgElement, $img, carNum2) { diff --git a/src/plugins/wangpan-115.js b/src/plugins/wangpan-115.js index cf010bd..21b8703 100644 --- a/src/plugins/wangpan-115.js +++ b/src/plugins/wangpan-115.js @@ -240,6 +240,19 @@ const _WangPan115MatchPlugin = class _WangPan115MatchPlugin extends BasePlugin { event.stopPropagation(); await this.retryMatch(event.currentTarget); })); + $(document).on("click", ".jhs-detail-delete-btn", (async event => { + event.preventDefault(); + event.stopPropagation(); + const $btn = $(event.currentTarget); + const matchData = $btn.attr("data-match"); + if (!matchData) return; + const matchList = JSON.parse(matchData); + const carNum2 = this.getPageInfo().carNum; + this.showDeleteDialog(carNum2, matchList, (async newMatchList => { + $("#115-match-table").remove(); + await this.matchDetailPage(newMatchList); + })); + })); await this.matchDetailPage(); $(document).on("click", ".jhs-match-detail-error-btn", (async event => { event.preventDefault(); @@ -266,6 +279,8 @@ const _WangPan115MatchPlugin = class _WangPan115MatchPlugin extends BasePlugin { if (this.loginStatus === _WangPan115MatchPlugin.LoginStatus.LOGGED_OUT) $tbody.append(`\n
未登录\n `); else if (matchList.length > 0) { const rowsHtml = matchList.map((match => `\n \n ${match.name}\n ${this.formatSize(match.size)}\n ${match.createTime}\n \n 播放\n \n \n `)).join(""); $tbody.append(rowsHtml); + $detail.css("position", "relative"); + $detail.append(`🗑️ 删除`); } else $tbody.append(`\n 未匹配\n `); } catch (error) { $tbody.append(`\n 加载失败,请重试\n `); @@ -357,6 +372,77 @@ const _WangPan115MatchPlugin = class _WangPan115MatchPlugin extends BasePlugin { } } } + + showDeleteDialog(carNum2, matchList, afterDelete) { + const formatSize = bytes => { + if (!bytes) return "-"; + const units = ["B", "KB", "MB", "GB", "TB"]; + let size = parseFloat(bytes), unit = 0; + for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++; + return size.toFixed(2) + " " + units[unit]; + }; + let html = '
'; + html += `
作品 ${carNum2} 匹配到 ${matchList.length} 个文件夹:
`; + html += '
'; + for (let i = 0; i < matchList.length; i++) { + const m = matchList[i]; + html += `
+ +
`; + } + html += "
"; + const layerIndex = layer.open({ + type: 1, + title: "删除115作品文件夹", + content: html, + area: ["520px", "auto"], + btn: ["确定删除", "取消"], + shadeClose: !1, + yes: async index => { + const $layer = $(`#layui-layer${index}`); + const checked = $layer.find(".jhs-delete-folder-cb:checked"); + if (0 === checked.length) { + show.error("请至少选择一个文件夹"); + return; + } + const selected = checked.map((function () { + return parseInt($(this).data("index")); + })).get(); + layer.close(index); + let loadObj = loading(); + let deletedCount = 0; + try { + for (const i of selected) { + const m = matchList[i]; + const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", { + pid: m.dirId, + "fid[0]": m.folderId + }); + result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result); + } + loadObj.close(); + show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`); + const newMatchList = await this.searchFiles(carNum2); + afterDelete && afterDelete(newMatchList); + this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2); + } catch (error) { + loadObj.close(); + console.error("删除115文件失败:", error); + show.error(`删除失败: ${error.message || "网络错误"}`); + } + } + }); + $(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () { + const checked = $(this).prop("checked"); + $(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked); + })); + } async handleLoginRedirect() { window.open("https://115.com"); }