sort.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const axios = require("axios");
  2. const cheerio = require("cheerio");
  3. var have_next=true;
  4. async function get_mh_item(url) {
  5. var data = [];
  6. var res = await axios.get(url);
  7. var $ = cheerio.load(res.data);
  8. var mh_item = $('.mh-item');
  9. for (var i=0; i<mh_item.length; i++) {
  10. /star-(\d)/.exec("mh-star-line star-4")[1]
  11. data.push({
  12. style: 'vod',
  13. title: $('.title', mh_item.eq(i)).text(),
  14. thumb: /url\((.*)\)/.exec($('.mh-cover', mh_item.eq(i)).attr('style'))[1],
  15. label: $('.chapter', mh_item.eq(i)).text(),
  16. summary: `评分: ${/star-(\d)/.exec(($('.mh-star-line', mh_item.eq(i)).attr('class')))[1]}`,
  17. route: $route('mulu', {
  18. url: all_url + $('a', mh_item.eq(i)).attr('href')
  19. }),
  20. onLongClick: async () => {
  21. let pd = await $input.confirm({
  22. title: '是否收藏',
  23. message: '收藏',
  24. okBtn: '收藏'
  25. })
  26. if (pd) {
  27. var follows = $storage.get('follows');
  28. if (follows == null) {
  29. follows = [];
  30. }
  31. follows.push(await get_info(all_url + $('a', mh_item.eq(i)).attr('href')));
  32. $storage.put('follows', follows);
  33. $ui.toast("收藏成功");
  34. } else {
  35. $ui.toast("取消收藏");
  36. }
  37. }
  38. })
  39. }
  40. var page_li = $('.page-pagination > li');
  41. for (var j=0; j<page_li.length; j++) {
  42. page_li.eq(j).has('.active') && j+1==page_li.length ? have_next=false : null;
  43. }
  44. return data;
  45. }
  46. module.exports = {
  47. type: 'list',
  48. async fetch({ args, page }) {
  49. page = page || 1;
  50. this.title = args.title;
  51. var url = `${all_url}/sort/${args.id}-${page}.html`;
  52. var data = await get_mh_item(url);
  53. if (have_next) {
  54. return {
  55. nextPage: page+1,
  56. items: data
  57. }
  58. } else {
  59. return data;
  60. }
  61. }
  62. }