13bqg_open.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { _, load } from './lib/cat.js';
  2. let key = '13bqg';
  3. let url = 'https://m.13bqg.cc';
  4. let siteKey = '';
  5. let siteType = 0;
  6. const MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36';
  7. async function request(reqUrl) {
  8. let resp = await req(reqUrl, {
  9. headers: {
  10. 'Accept-Language': 'zh-CN,zh;q=0.8',
  11. 'User-Agent': MOBILE_UA,
  12. },
  13. });
  14. return resp.content;
  15. }
  16. // cfg = {skey: siteKey, ext: extend}
  17. async function init(cfg) {
  18. siteKey = cfg.skey;
  19. siteType = cfg.stype;
  20. }
  21. async function home(filter) {
  22. var html = await request(url);
  23. const $ = load(html);
  24. let classes = [];
  25. for (const a of $('div.nav > ul > li > a[href!="/"]')) {
  26. classes.push({
  27. type_id: a.attribs.href.replace(/\//g, ''),
  28. type_name: a.children[0].data.trim(),
  29. tline: 2,
  30. });
  31. }
  32. return {
  33. class: classes,
  34. };
  35. }
  36. async function category(tid, pg, filter, extend) {
  37. if (pg == 0) pg = 1;
  38. var html = await request(url + `/${tid}/${pg}.html`);
  39. const $ = load(html);
  40. let books = [];
  41. for (const item of $('div.item')) {
  42. const a = $(item).find('a:first')[0];
  43. const img = $(a).find('img:first')[0];
  44. const span = $(item).find('span:first')[0];
  45. books.push({
  46. book_id: a.attribs.href,
  47. book_name: img.attribs.alt,
  48. book_pic: img.attribs.src,
  49. book_remarks: span.children[0].data.trim(),
  50. });
  51. }
  52. return {
  53. page: pg,
  54. pagecount: $('div.page > a:contains(>)').length > 0 ? pg + 1 : pg,
  55. list: books,
  56. };
  57. }
  58. async function detail(id) {
  59. var html = await request(url + id);
  60. var $ = load(html);
  61. let book = {
  62. book_name: $('[property$=book_name]')[0].attribs.content,
  63. book_year: $('[property$=update_time]')[0].attribs.content,
  64. book_director: $('[property$=author]')[0].attribs.content,
  65. book_content: $('[property$=description]')[0].attribs.content,
  66. };
  67. html = await request(url + id + `list.html`);
  68. $ = load(html);
  69. let urls = [];
  70. const links = $('dl>dd>a[href*="/html/"]');
  71. for (const l of links) {
  72. var name = $(l).text().trim();
  73. var link = l.attribs.href;
  74. urls.push(name + '$' + link);
  75. }
  76. book.volumes = '全卷';
  77. book.urls = urls.join('#');
  78. return {
  79. list: [book],
  80. };
  81. }
  82. async function play(flag, id, flags) {
  83. try {
  84. var content = '';
  85. while (true) {
  86. var html = await request(url + id);
  87. var $ = load(html);
  88. content += $('#chaptercontent')
  89. .html()
  90. .replace(/<br>|请收藏.*?<\/p>/g, '\n')
  91. .trim();
  92. id = $('a.Readpage_down')[0].attribs.href;
  93. if (id.indexOf('_') < 0) break;
  94. }
  95. return {
  96. content: content + '\n\n',
  97. };
  98. } catch (e) {
  99. return {
  100. content: '',
  101. };
  102. }
  103. }
  104. async function search(wd, quick, pg) {
  105. const cook = await req(`${url}/user/hm.html?q=${encodeURIComponent(wd)}`, {
  106. headers: {
  107. accept: 'application/json',
  108. 'User-Agent': MOBILE_UA,
  109. Referer: `${url}/s?q=${encodeURIComponent(wd)}`,
  110. },
  111. });
  112. const set_cookie = _.isArray(cook.headers['set-cookie']) ? cook.headers['set-cookie'].join(';;;') : cook.headers['set-cookie'];
  113. const cks = set_cookie.split(';;;');
  114. const cookie = {};
  115. for (const c of cks) {
  116. const tmp = c.trim();
  117. const idx = tmp.indexOf('=');
  118. const k = tmp.substr(0, idx);
  119. const v = tmp.substr(idx + 1, tmp.indexOf(';') - idx - 1);
  120. cookie[k] = v;
  121. }
  122. const resp = await req(`${url}/user/search.html?q=${encodeURIComponent(wd)}&so=undefined`, {
  123. headers: {
  124. accept: 'application/json',
  125. 'User-Agent': MOBILE_UA,
  126. cookie: 'hm=' + cookie['hm'],
  127. Referer: `${url}/s?q=${encodeURIComponent(wd)}`,
  128. },
  129. });
  130. var data = JSON.parse(resp.content);
  131. let books = [];
  132. for (const book of data) {
  133. books.push({
  134. book_id: book.url_list,
  135. book_name: book.articlename,
  136. book_pic: book.url_img,
  137. book_remarks: book.author,
  138. });
  139. }
  140. return {
  141. tline: 2,
  142. list: books,
  143. };
  144. }
  145. export function __jsEvalReturn() {
  146. return {
  147. init: init,
  148. home: home,
  149. category: category,
  150. detail: detail,
  151. play: play,
  152. search: search,
  153. };
  154. }