diff --git a/repo/wnacg.com.js b/repo/wnacg.com.js index 0b9bfb6..3e6fafd 100644 --- a/repo/wnacg.com.js +++ b/repo/wnacg.com.js @@ -1,6 +1,6 @@ // ==MiruExtension== // @name 紳士漫畫 -// @version v0.0.1 +// @version v0.0.2 // @author appdevelpo // @lang zh-tw // @license MIT @@ -12,89 +12,329 @@ // ==/MiruExtension== export default class Mangafx extends Extension { - async latest(page) { - const res = await this.request(`/albums-index-page-${page}.html`); - const bsxList = res.match(/
  • a"); + let num_str = ""; + for (let page_num of pre_page_nums) + { + num_str = page_num.content.match(/(\d+)/g)[0]; + } + const num = parseInt(num_str); + if (res.search(`${num + 1}`) != -1) + { + return num + 1; + } + return num; + } + + //获取收藏列表 + async get_fav_lists() + { + var headers = this.headers; + headers["Cookie"] = `MPIC_bnS5=${await this.getSetting("cookies")}`; + var fav_lists = {}; + const res = await this.request(`/users-users_fav.html`, {headers: headers}); + this.favnum = await this.get_maxnum(res); //获取收藏总页数 + const items = await this.querySelectorAll(res, "label.nav_list > a"); + for (const item of items) + { + let id = ""; + try + { + id = "c-" + item.content.match(/(\d+)/g)[0]; + } + catch (e) + { + id = "all"; + } + const name = item.content.match(/">(.*?)<\/a>/)[1]; + fav_lists[id] = name; + } + this.fav_lists = fav_lists; + } + + //获取收藏 + async get_fav(id, page) { + //包含用户信息的headers + var headers = this.headers; + headers["Cookie"] = `MPIC_bnS5=${await this.getSetting("cookies")}`; + if (id == "all") + { + id = "c-0"; + } + const res = await this.request(`/users-users_fav-page-${page}-${id}.html`, {headers: headers}); + const bsxList = await this.querySelectorAll(res, "div.asTB"); + const maxnum = await this.get_maxnum(res); + console.log(`${page}/${maxnum}`); + if (id == "c-0") + { + //获取收藏最大页数 + this.favnum = maxnum; + } + if (page > maxnum) + { + return []; + } + const mangas = []; + for (const element of bsxList) + { + const html = element.content; + const url = await this.getAttributeText(html, "div.box_cel > p.l_title > a", "href"); + const title = await this.querySelector(html, "div.box_cel > p.l_title > a").text; + const cover = "https:" + await this.getAttributeText(html, "img", "src"); mangas.push({ - title, - url, - cover, + title: title, + url: url, + cover: cover, }); - }); - return mangas; - } - - async search(kw, page) { - const res = await this.request(`/search/index.php?q=${kw}&m=&syn=yes&f=_all&s=create_time_DESC&p=${page}`); - const bsxList = res.match(/
  • 1)) + { + //首页不支持翻页 + return []; + } + const res = await this.request(url_str, {headers: this.headers}); + if ((url_str != "") && (url_str.search("cate") == -1)) //获取目前最大可跳转页数 + { + this.maxnum = await this.get_maxnum(res); + } + const bsxList = await this.querySelectorAll(res, "li.gallary_item"); + const mangas = []; + for (const element of bsxList) + { + const html = element.content; + const url = await this.getAttributeText(html, "div.pic_box > a", "href"); + let title = await this.getAttributeText(html, "div.pic_box > a", "title"); + title = title.replaceAll("", "").replaceAll("", ""); + const cover = "https:" + await this.getAttributeText(html, "div.pic_box > a > img", "src"); mangas.push({ - title, - url, - cover, + title: title, + url: url, + cover: cover, + headers: this.headers, }); - }); - return mangas; - } - - async detail(url) { - - const res = await this.request(url); - const titleRegex = /

    (.+?)<\/h2>/; - const titleMatch = res.match(titleRegex); - const title = titleMatch ? titleMatch[1] : null; - const coverRegex = /.+src=([\s\S^]+?)<\/p>/; - const descriptionMatch = res.match(descriptionRegex); - const desc = descriptionMatch ? descriptionMatch[1] : null; + } + return mangas; + } + + async latest(page) { + await this.load_settings(); + return await this.get_mangas("", page); + } - const button_match = res.match(//g) - const id = button_match[0].match(/\d{6}/)[0]; - return { - title: title || "Unknown Title", + async search(kw, page, filter) { + if (kw) + { + //随机页面 + if (kw == "random") + { + if (page > 1) + { + return []; + } + const random_page = Math.floor(Math.random() * this.maxnum) + 1; + return await this.get_mangas(this.url_strs["new"]["all"], random_page); + } + //随机收藏页面 + if (kw == "random_fav") + { + if (page > 1) + { + return []; + } + const random_page = Math.floor(Math.random() * this.favnum) + 1; + console.log(this.favnum); + return await this.get_fav("all", random_page); + } + //搜索 + return await this.get_mangas(`/search/index.php?q=${kw}&m=&syn=yes&f=_all&s=create_time_DESC&p=$`, page); + } + else + { + if (filter["categories"][0] == "fav") + { + //收藏 + return await this.get_fav(filter["lists"][0], page); + } + else + { + //其他界面 + return await this.get_mangas(this.url_strs[filter["categories"][0]][filter["lists"][0]], page); + } + } + } + + async detail(url) { + const res = await this.request(url, {headers: this.headers}); + const title = await this.querySelector(res, "h2").text; + let cover = await this.getAttributeText(res, "div.uwthumb > img", "src"); + if (cover[3] == "/") { + cover = "https:" + cover.substring(2, cover.length); + } + else { + cover = "https:" + cover; + } + const desc = await this.querySelector(res, "div.uwconn > p").text; + const id = url.match(/-aid-(.+?).html/)[1]; + return { + title: title || "Unknown title", cover: cover || "", desc: desc || "No description available.", episodes: [ - { - title: "正常畫質", - urls: [{name:"1",url:`/photos-gallery-aid-${id}.html`}], - }, - { - title: "低畫質", - urls: [{name:"1",url:`/photos-webp-aid-${id}.html`}], - } - ], - }; - } - - async watch(url) { - const res = await this.request(url,{ - headers: {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/237.84.2.178 Safari/537.36", - referer: "https://www.wnacg.com"} - }); - const urls = [] - const url_list = res.match(/\/\/img4.qy0.ru\/data.+?.jpg/g) - url_list.forEach((element) => { - urls.push("https:"+element) - }) - return { - urls, - header: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537.36", - referer: "https://www.wnacg.com" + { + title: "正常画质", + urls: [{name:"开始阅读",url:`/photos-gallery-aid-${id}.html`}], + }, + { + title: "低画质", + urls: [{name:"开始阅读",url:`/photos-webp-aid-${id}.html`}], } - }; + ], + }; + } + + async watch(url) { + const res = await this.request(url, {headers: this.headers}); + const urls = []; + let urls_str = res.substring(res.search("imglist") + 12, res.search("喜歡紳士漫畫的同學請加入收藏哦!") + 17); + const url_list = urls_str.split("},{"); + for (let url_str of url_list) { + urls.push("https:" + url_str.substring(url_str.search("img_host") + 11, url_str.search("\", ") - 1)); } - } - + return { + urls: urls, + header: this.headers + }; + } +}