import { BasePlugin } from '../core/base-plugin.js'; import { __publicField, isJavBus, isJavDb, Status_FILTER, Status_FAVORITE, Status_HAS_DOWN, Status_HAS_WATCH, YES } from '../core/constants.js'; import { GM_openInTab } from 'vite-plugin-monkey/dist/client'; import {getDmmVideo, selectDefaultQuality} from '../api/dmm.js'; class CoverButtonPlugin extends BasePlugin { getName() { return "CoverButtonPlugin"; } async initCss() { return `\n \n `; } handle() { if (window.isListPage) { this.addSvgBtn(); this.bindClick().then(); } } async addSvgBtn() { $(this.getSelector().itemSelector).toArray().forEach((ele => { let $box2 = $(ele); if (!($box2.find(".tool-box").length > 0)) { isJavDb && $box2.find(".tags").append(`\n
\n \n \n ${this.screenSvg}\n \n ${this.videoSvg}\n \n
\n
${this.handleSvg}
\n \n \n
\n \n
\n
${this.siteSvg}
\n \n
\n
${this.copySvg}
\n \n
\n ${this.carNumSvg}\n ${this.titleSvg}\n ${this.downSvg}\n
\n
\n
\n `); if (isJavBus) { if ($box2.find(".avatar-box").length > 0) return; $box2.find(".photo-info").append(`\n
\n \n \n ${this.screenSvg}\n\n ${this.videoSvg}\n \n
\n
${this.handleSvg}
\n \n \n
\n \n
\n
${this.siteSvg}
\n \n
\n
${this.copySvg}
\n \n
\n ${this.carNumSvg}\n ${this.titleSvg}\n ${this.downSvg}\n
\n
\n
\n `); } } })); this.enableSvgBtn(); } async enableSvgBtn() { const settingObj = await storageManager.getSetting(), {enableScreenSvg: enableScreenSvg = YES, enableVideoSvg: enableVideoSvg = YES, enableHandleSvg: enableHandleSvg = YES, enableSiteSvg: enableSiteSvg = YES, enableCopySvg: enableCopySvg = YES} = settingObj; [ { selector: ".screenSvg", enabled: enableScreenSvg }, { selector: ".videoSvg", enabled: enableVideoSvg }, { selector: ".handleSvg", enabled: enableHandleSvg }, { selector: ".siteSvg", enabled: enableSiteSvg }, { selector: ".copySvg", enabled: enableCopySvg } ].forEach((({selector: selector, enabled: enabled}) => { $(selector).toggle(enabled === YES); })); } async bindClick() { this.getSelector(); const listPagePlugin = this.getBean("ListPagePlugin"); $(document).on("click", ".more-tools-container", (event => { event.preventDefault(); var $currentTools = $(event.target).closest(".more-tools-container").find(".more-tools"); $(".more-tools").not($currentTools).stop(!0, !0).removeClass("elastic-in").addClass("elastic-out").hide(); $currentTools.is(":visible") ? $currentTools.stop(!0, !0).removeClass("elastic-in").addClass("elastic-out").hide() : $currentTools.stop(!0, !0).removeClass("elastic-out").addClass("elastic-in").show(); })); $(document).on("click", (function(event) { $(event.target).closest(".more-tools-container").length || $(".more-tools").stop(!0, !0).removeClass("elastic-in").addClass("elastic-out").hide(); })); $(document).on("click", ".videoSvg", (event => { event.preventDefault(); $('.videoSvg[title!="播放视频"]').each(((index, element) => { const $otherSvgElement = $(element); let $otherBox = $otherSvgElement.closest(".item"), $otherImg = $otherBox.find("img"), {carNum: carNum2} = this.getBoxCarInfo($otherBox); this.showImg($otherSvgElement, $otherImg, carNum2); $otherSvgElement.html(this.videoSvg).attr("title", "播放视频"); })); const $currentBox = $(event.target).closest(".item"), $svgElement = $currentBox.find(".videoSvg"); if ("播放视频" === $svgElement.attr("title")) { $svgElement.html(this.recoveryVideoSvg).attr("title", "切回封面"); const {carNum: carNum2} = this.getBoxCarInfo($currentBox); let $img = $currentBox.find("img"); if (!$img.length) { show.error("没有找到图片"); return; } this.showVideo($svgElement, $img, carNum2).then(); } })); $(document).on("click", ".screenSvg", (async event => { event.preventDefault(); let loadObj = loading(); try { const $box2 = $(event.currentTarget).closest(".item"); let {carNum: carNum2} = this.getBoxCarInfo($box2); carNum2 = carNum2.replace("FC2-", ""); const imgUrl = await this.getBean("ScreenShotPlugin").getScreenshot(carNum2); loadObj.close(); showPreviewOverlay(imgUrl, carNum2); } catch (error) { console.error("图片预览出错:", error); show.error("图片预览出错:" + error); } finally { loadObj.close(); } })); $(document).on("click", ".filterBtn, .favoriteBtn, .hasDownBtn, .hasWatchBtn", (event => { event.preventDefault(); event.stopPropagation(); const $btn = $(event.target).closest(".menu-btn"), $box2 = $btn.closest(".item"), {carNum: carNum2, url: url, publishTime: publishTime} = this.getBoxCarInfo($box2), handleAction = async status => { let actress = await listPagePlugin.parseActressName(url); await storageManager.saveCar({ carNum: carNum2, url: url, names: actress, actionType: status, publishTime: publishTime }); window.refresh(); show.ok("操作成功"); }; $btn.hasClass("filterBtn") ? utils.q(event, `是否屏蔽${carNum2}?`, (() => handleAction(Status_FILTER))) : $btn.hasClass("favoriteBtn") ? handleAction(Status_FAVORITE).then() : $btn.hasClass("hasDownBtn") ? handleAction(Status_HAS_DOWN).then() : $btn.hasClass("hasWatchBtn") && handleAction(Status_HAS_WATCH).then(); $(".more-tools").stop(!0, !0).removeClass("elastic-in").addClass("elastic-out").hide(); })); const otherSitePlugin = this.getBean("OtherSitePlugin"), missAvUrl = await otherSitePlugin.getMissAvUrl(), jableUrl = await otherSitePlugin.getjableUrl(), av123Url = await otherSitePlugin.getAv123Url(); $(document).on("click", ".site-jable, .site-miss-av, .site-123-av", (event => { event.preventDefault(); event.stopPropagation(); const $currentTarget = $(event.currentTarget), $box2 = $currentTarget.closest(".item"), {carNum: carNum2} = this.getBoxCarInfo($box2); let url = null; $currentTarget.hasClass("site-jable") ? url = `${jableUrl}/search/${carNum2}/` : $currentTarget.hasClass("site-miss-av") ? url = `${missAvUrl}/search/${carNum2}` : $currentTarget.hasClass("site-123-av") && (url = `${av123Url}/ja/search?keyword=${carNum2}`); event && (event.ctrlKey || event.metaKey) ? GM_openInTab(url, { insert: 0 }) : window.open(url); })); $(document).on("click", ".titleSvg, .carNumSvg, .downSvg", (event => { event.preventDefault(); event.stopPropagation(); const $box2 = $(event.currentTarget).closest(".item"), {carNum: carNum2, title: title} = this.getBoxCarInfo($box2), $img = $box2.find(isJavBus ? ".photo-frame img" : ".cover img"); $(event.currentTarget).hasClass("titleSvg") ? utils.copyToClipboard("标题", title) : $(event.currentTarget).hasClass("carNumSvg") ? utils.copyToClipboard("番号", carNum2) : $(event.currentTarget).hasClass("downSvg") && fetch($img.attr("src")).then((response => response.blob())).then((blob => { utils.download(blob, carNum2 + " " + title + ".jpg"); })); })); $(document).on("click", ".markDeleteSvg", (async event => { event.preventDefault(); event.stopPropagation(); const $btn = $(event.currentTarget); const $box2 = $btn.closest(".item"); const {carNum: carNum2, title: title, publishTime: publishTime, url: url} = this.getBoxCarInfo($box2); const score = $box2.find(".score").text().trim() || "无评分"; let markedList = await storageManager.forage.getItem("markedDeleteList") || []; const existingIndex = markedList.findIndex(item => item.carNum === carNum2); if (existingIndex > -1) { markedList.splice(existingIndex, 1); $btn.removeClass("marked"); $btn.attr("title", "标记删除"); show.ok(`已取消标记: ${title}`); } else { markedList.push({ carNum: carNum2, title: title, publishTime: publishTime, score: score, url: url, markedTime: new Date().toISOString() }); $btn.addClass("marked"); $btn.attr("title", "取消标记删除"); show.ok(`已标记删除: ${title}`); } await storageManager.forage.setItem("markedDeleteList", markedList); })); $(document).on("click", ".delete115Svg", (async event => { event.preventDefault(); event.stopPropagation(); const $btn = $(event.currentTarget); const matchData = $btn.attr("data-match"); if (!matchData) { show.error("未找到115匹配数据"); return; } const matchList = JSON.parse(matchData); const $box2 = $btn.closest(".item"); const {carNum: carNum2} = this.getBoxCarInfo($box2); this.getBean("WangPan115MatchPlugin").showDeleteDialog(carNum2, matchList, (async newMatchList => { this.getBean("WangPan115MatchPlugin").updateMatchStatus($box2, carNum2, newMatchList); })); })); } showImg($svgElement, $img, carNum2) { $svgElement.html(this.videoSvg).attr("title", "播放视频"); let $video = $(`#${`${carNum2}_preview_video`}`); if ($video.length > 0) { $video[0].pause(); $video.parent().hide(); } $img.show(); $img.removeClass("loading"); $img.next(".loading-spinner").remove(); } async showVideo($svgElement, $img, carNum2) { const id = `${carNum2}_preview_video`; let $video = $(`#${id}`); if ($video.length > 0) { $video.parent().show(); $video[0].play(); $img.hide(); return; } $img.addClass("loading"); $img.after('
'); const poster = $img.attr("src"), dmmVideoMap = await getDmmVideo(carNum2); if (!dmmVideoMap) { show.error("未解析到视频"); this.showImg($svgElement, $img, carNum2); return; } let defaultVideoQuality = await storageManager.getSetting("videoQuality"); defaultVideoQuality = selectDefaultQuality(Object.keys(dmmVideoMap), defaultVideoQuality); let videoUrl = dmmVideoMap[defaultVideoQuality], videoHtml = `\n
\n \n
\n `; isJavBus && (videoHtml = `\n
\n \n
\n `); $img.parent().append(videoHtml); $img.hide(); $img.removeClass("loading"); $img.next(".loading-spinner").remove(); $video = $(`#${id}`); let videoElement = $video[0]; videoElement.load(); videoElement.muted = !1; videoElement.play(); $video.trigger("focus"); } } export { CoverButtonPlugin };