import { BasePlugin } from '../core/base-plugin.js'; import { __publicField, currentHref, Status_FILTER, Status_FAVORITE, Status_HAS_DOWN, Status_HAS_WATCH, YES } from '../core/constants.js'; class Fc2By123AvPlugin extends BasePlugin { constructor() { super(...arguments); __publicField(this, "$contentBox", $(".section .container")); __publicField(this, "urlParams", new URLSearchParams(window.location.search)); __publicField(this, "sortVal", this.urlParams.get("sort") || "release_date"); __publicField(this, "currentPage", this.urlParams.get("page") ? parseInt(this.urlParams.get("page")) : 1); __publicField(this, "maxPage", null); __publicField(this, "keyword", this.urlParams.get("keyword") || null); } getName() { return "Fc2By123AvPlugin"; } async getBaseUrl() { const otherSitePlugin = this.getBean("OtherSitePlugin"); return await otherSitePlugin.getAv123Url() + "/ja"; } handle() { $("#navbar-menu-hero > div > div:nth-child(1) > div > a:nth-child(4)").after('123Av-Fc2'); $('.tabs li:contains("FC2")').after('
  • 123Av-Fc2
  • '); if (currentHref.includes("/advanced_search?type=100")) { this.hookPage(); this.handleQuery().then(); } } hookPage() { let $h2 = $("h2.section-title"); $h2.contents().first().replaceWith("123Av"); $h2.css("marginBottom", "0"); $h2.append('\n
    \n \n 搜索\n 重置\n
    \n '); $("#search-123av-keyword").val(this.keyword); $("#search-123av-btn").on("click", (async () => { let keyword = $("#search-123av-keyword").val().trim(); if (keyword) { this.keyword = keyword; utils.setHrefParam("keyword", keyword); await this.handleQuery(); } })); $("#clear-123av-btn").on("click", (async () => { $("#search-123av-keyword").val(""); this.keyword = ""; utils.setHrefParam("keyword", ""); $(".page-box").show(); $(".tool-box").show(); await this.handleQuery(); })); $(".empty-message").remove(); $("#foldCategoryBtn").remove(); $(".section .container .box").remove(); $("#sort-toggle-btn").remove(); this.$contentBox.append('
    '); this.$contentBox.append('
    '); this.$contentBox.append('
    '); $(".tool-box").append('\n
    \n
    \n 发布日期\n 最近更新\n 热门\n 今天最多观看\n 本周最多观看\n 本月最多观看\n 最多观看\n 最受欢迎\n
    \n
    \n '); $(`#conditionBox a[data-sort="${this.sortVal}"]`).addClass("is-info"); utils.setHrefParam("sort", this.sortVal); utils.setHrefParam("page", this.currentPage); $("#conditionBox").on("click", "a.button", (e => { let $target = $(e.target); this.sortVal = $target.data("sort"); utils.setHrefParam("sort", this.sortVal); $target.siblings().removeClass("is-info"); $target.addClass("is-info"); this.handleQuery(); })); $(".page-box").append('\n \n '); $(document).on("click", ".pagination-link", (e => { e.preventDefault(); this.currentPage = parseInt($(e.target).data("page")); utils.setHrefParam("page", this.currentPage); this.renderPagination(); this.handleQuery(); })); $(".pagination-previous").on("click", (e => { e.preventDefault(); if (this.currentPage > 1) { this.currentPage--; utils.setHrefParam("page", this.currentPage); this.renderPagination(); this.handleQuery(); } })); $(".pagination-next").on("click", (e => { e.preventDefault(); if (this.currentPage < this.maxPage) { this.currentPage++; utils.setHrefParam("page", this.currentPage); this.renderPagination(); this.handleQuery(); } })); } renderPagination() { const $paginationList = $(".pagination-list"); $paginationList.empty(); let startPage = Math.max(1, this.currentPage - 2), endPage = Math.min(this.maxPage, this.currentPage + 2); this.currentPage <= 3 ? endPage = Math.min(6, this.maxPage) : this.currentPage >= this.maxPage - 2 && (startPage = Math.max(this.maxPage - 5, 1)); if (startPage > 1) { $paginationList.append('
  • 1
  • '); startPage > 2 && $paginationList.append('
  • …
  • '); } for (let i = startPage; i <= endPage; i++) { const activeClass = i === this.currentPage ? " is-current" : ""; $paginationList.append(`
  • ${i}
  • `); } if (endPage < this.maxPage) { endPage < this.maxPage - 1 && $paginationList.append('
  • …
  • '); $paginationList.append(`
  • ${this.maxPage}
  • `); } } async handleQuery() { let loadObj = loading(); try { let pagesToFetch = []; pagesToFetch = 1 === this.currentPage ? [ 1, 2 ] : [ 2 * this.currentPage - 1, 2 * this.currentPage ]; if (this.keyword) { pagesToFetch = [ 1 ]; $(".page-box").hide(); $(".tool-box").hide(); } const baseUrl = await this.getBaseUrl(), fetchPromises = pagesToFetch.map((page => { let url = `${baseUrl}/tags/fc2?sort=${this.sortVal}&page=${page}`; this.keyword && (url = `${baseUrl}/search?keyword=${this.keyword}`); return gmHttp.get(url); })), htmlResults = await Promise.all(fetchPromises); let dataList = []; for (const html of htmlResults) { let $dom = $(html); $dom.find(".box-item").each(((index, element) => { const $item = $(element), imgSrc = $item.find("img").attr("data-src"); let carNum2 = $item.find("img").attr("title"); const detailLink = $item.find(".detail a"), link = detailLink.attr("href"), href = baseUrl + (link.startsWith("/") ? link : "/" + link), title = detailLink.text().trim().replace(carNum2 + " - ", ""); carNum2 = carNum2.replace("FC2-PPV", "FC2"); dataList.push({ imgSrc: imgSrc, carNum: carNum2, href: href, title: title }); })); if (!this.maxPage) { let rawMaxPage, lastPageItem = $dom.find(".page-item:not(.disabled)").last(); if (lastPageItem.find("a.page-link").length) { let href = lastPageItem.find("a.page-link").attr("href"); rawMaxPage = parseInt(href.split("page=")[1]); } else rawMaxPage = parseInt(lastPageItem.find("span.page-link").text()); this.maxPage = Math.ceil(rawMaxPage / 2); this.renderPagination(); } } if (0 === dataList.length) { console.log(dataList); show.error("无结果"); let errorUrl = `${baseUrl}/dm4/tags/fc2?sort=${this.sortVal}`; this.keyword && (errorUrl = `${baseUrl}/search?keyword=${this.keyword}`); console.error("获取数据失败!", errorUrl); } let movieHtml = this.markDataListHtml(dataList); $(".movie-list").html(movieHtml); await utils.smoothScrollToTop(); } catch (e) { console.error(e); } finally { loadObj.close(); } } async open123AvFc2Dialog(carNum2, href) { let otherHtml = ""; await storageManager.getSetting("enableLoadOtherSite", YES) === YES && (otherHtml = '
    第三方站点:
    '); let pageHtml = `\n
    \n \x3c!--
    \n \n
    \n
    --\x3e\n
    \n
    加载中...
    \n
    \n \n ${otherHtml}\n \n
    \n 🚫 屏蔽\n ⭐ 收藏\n 📥️ 已下载\n 🔍 已观看\n \n \n 字幕搜索\n \n \n
    \n
    \n \n
    \n
    \n
    \n \n \n \x3c!--
    --\x3e\n
    \n `; layer.open({ type: 1, title: carNum2, content: pageHtml, area: utils.getDefaultArea(), skin: "movie-detail-layer", scrollbar: !1, success: (layero, index) => { utils.setupEscClose(index); this.loadData(carNum2, href); let keyword = carNum2.replace("FC2-", ""); $("#magnets-content").append(this.getBean("MagnetHubPlugin").createMagnetHub(keyword)); $("#favoriteBtn").on("click", (async event => { const actress = $("#data-actress").text(), publishTime = $("#data-publishTime").text(); await storageManager.saveCar({ carNum: carNum2, url: href, names: actress, actionType: Status_FAVORITE, publishTime: publishTime }); window.refresh(); layer.closeAll(); })); $("#filterBtn").on("click", (event => { utils.q(event, `是否屏蔽${carNum2}?`, (async () => { const actress = $("#data-actress").text(), publishTime = $("#data-publishTime").text(); await storageManager.saveCar({ carNum: carNum2, url: href, names: actress, actionType: Status_FILTER, publishTime: publishTime }); window.refresh(); layer.closeAll(); window.location.href.includes("collection_codes?movieId") && utils.closePage(); })); })); $("#hasDownBtn").on("click", (async event => { const actress = $("#data-actress").text(), publishTime = $("#data-publishTime").text(); await storageManager.saveCar({ carNum: carNum2, url: href, names: actress, actionType: Status_HAS_DOWN, publishTime: publishTime }); window.refresh(); layer.closeAll(); })); $("#hasWatchBtn").on("click", (async event => { const actress = $("#data-actress").text(), publishTime = $("#data-publishTime").text(); await storageManager.saveCar({ carNum: carNum2, url: href, names: actress, actionType: Status_HAS_WATCH, publishTime: publishTime }); window.refresh(); layer.closeAll(); })); $("#subtitleSearchBtn").on("click", (() => { window.JavPackSubtitle.openSearchModal({details: {code: carNum2}}); })); window.JavPackSubtitle.preload115Matches(carNum2); // $("#search-subtitle-btn").on("click", (event => utils.openPage(`https://subtitlecat.com/index.php?search=${carNum2}`, carNum2, !1, event))); // $("#xunLeiSubtitleBtn").on("click", (() => this.getBean("DetailPageButtonPlugin").searchXunLeiSubtitle(carNum2))); let tempCarNum = carNum2.replace("FC2-", ""); this.getBean("OtherSitePlugin").loadOtherSite(tempCarNum, carNum2).then(); } }); } async loadData(carNum2, href) { let loadObj = loading(); try { const {id: id, publishDate: publishDate, title: title, moviePoster: moviePoster} = await this.get123AvVideoInfo(href); $(".movie-info-container").html(`\n

    ${title || "无标题"}

    \n
    \n 番号: ${carNum2 || "未知"}\n 年份: ${publishDate || "未知"}\n \n 站点: \n fc2ppvdb\n fc2电子市场\n \n
    \n
    \n
    主演:
    \n
    \n
    \n 販売者: \n
    \n \n \n \n\n `); this.getImgList(carNum2).then(); this.getActressInfo(carNum2).then(); this.getBean("TranslatePlugin").translate(carNum2, !1).then(); } catch (e) { console.error(e); } finally { loadObj.close(); } } handleLongImg(carNum2) { utils.loopDetector((() => $(".movie-gallery .image-list").length > 0), (async () => { $(".movie-gallery .image-list").prepend('
    正在加载缩略图
    '); const imgUrl = await this.getBean("ScreenShotPlugin").getScreenshot(carNum2); if (imgUrl) { $(".screen-container").html(``); $(".screen-container").on("click", (event => { event.stopPropagation(); event.preventDefault(); showPreviewOverlay(imgUrl, carNum2); })); } })); } async get123AvVideoInfo(href) { const html = await gmHttp.get(href), match = html.match(/v-scope="Movie\({id:\s*(\d+),/), id = match ? match[1] : null, $dom = utils.htmlTo$dom(html); return { id: id, publishDate: $dom.find('span:contains("リリース日:")').next("span").text(), title: $dom.find("h1").text().trim(), moviePoster: $dom.find("#player").attr("data-poster") }; } async getActressInfo(fc2Num) { let url = `https://fc2ppvdb.com/articles/${fc2Num.replace("FC2-", "")}`; const html = await gmHttp.get(url), $dom = $(html), actressNodeList = $dom.find("div").filter((function() { return 0 === $(this).text().trim().indexOf("女優:"); })); if (0 === actressNodeList.length || actressNodeList.length > 1) { show.error("解析女优信息失败"); return; } const $actress = $(actressNodeList[0]).find("a"); let actorsHtml = "主演: "; if ($actress.length > 0) { let actress = ""; $actress.each(((index, ele) => { let $actor = $(ele), name2 = $actor.text(), actressHref = $actor.attr("href"); actorsHtml += `${name2}`; actress += name2 + " "; })); $("#data-actress").text(actress); } else actorsHtml += "暂无演员信息"; $(".actor-list").html(actorsHtml); const sellerNodeList = $dom.find("div").filter((function() { return 0 === $(this).text().trim().indexOf("販売者:"); })); if (sellerNodeList.length > 0) { const $sellerA = $(sellerNodeList[0]).find("a"); if ($sellerA.length > 0) { const $seller = $($sellerA[0]); let name2 = $seller.text(), sellerHref = $seller.attr("href"); $(".movie-seller").html(`販売者: ${name2}`); } } } async getImgList(fc2Num) { let tempCarNum = fc2Num.replace("FC2-", ""), url = `https://adult.contents.fc2.com/article/${fc2Num.replace("FC2-", "")}/`; const html = await gmHttp.get(url, null, { referer: url }); let imgList = $(html).find(".items_article_SampleImagesArea img").map((function() { return $(this).attr("src"); })).get(), imagesHtml = ""; Array.isArray(imgList) && imgList.length > 0 ? imagesHtml = imgList.map(((img, index) => `\n \n \n \n `)).join("") : $(".movie-gallery").html("

    剧照: 暂无剧照

    "); $(".image-list").html(imagesHtml); this.handleLongImg(tempCarNum); } async getMovie(id, moviePoster) { let url = `${await this.getBaseUrl()}/ajax/v/${id}/videos`, loadObj = loading(); try { let movieList = (await gmHttp.get(url)).result.watch; if (movieList.length > 0) { movieList.forEach((movieItem => { movieItem.url = movieItem.url + "?poster=" + moviePoster; })); return movieList; } return null; } catch (e) { console.error(e); } finally { loadObj.close(); } } markDataListHtml(movies) { let moviesHtml = ""; movies.forEach((movie => { moviesHtml += `\n
    \n \n
    \n \n
    \n
    ${movie.carNum} ${movie.title}
    \n
    \n
    \n
    \n
    \n
    \n
    \n
    \n
    \n `; })); return moviesHtml; } } export { Fc2By123AvPlugin };