bengou_open.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { Crypto, _, load } from 'assets://js/lib/cat.js';
  2. let key = 'bengou';
  3. let HOST = 'https://www.bengou.co';
  4. let siteKey = '';
  5. let siteType = 0;
  6. const PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36';
  7. async function request(reqUrl) {
  8. let resp = await req(reqUrl, {
  9. headers: {
  10. 'User-Agent': PC_UA,
  11. },
  12. });
  13. return resp.content;
  14. }
  15. // cfg = {skey: siteKey, ext: extend}
  16. async function init(cfg) {
  17. siteKey = cfg.skey;
  18. siteType = cfg.stype;
  19. }
  20. async function home(filter) {
  21. const classes = [{'type_id':'all','type_name':'all'}];
  22. const filterObj = {
  23. 'all':[
  24. {'key':'type','name':'进度','init':'all','value':[{'n':'全部','v':'all'},{'n':'连载','v':'lianzai'},{'n':'完结','v':'wanjie'}]},
  25. {'key':'type','name':'地区','init':'all','value':[{'n':'日韩','v':'rihan'},{'n':'内地','v':'neidi'},{'n':'港台','v':'gangntai'},{'n':'欧美','v':'oumei'},{'n':'其他','v':'qita'}]},
  26. {'key':'type','name':'读者','init':'all','value':[{'n':'少年','v':'shaonianqu'},{'n':'少女','v':'shaonvqu'},{'n':'青年','v':'qingnian'},{'n':'少儿','v':'shaoer'}]},
  27. {'key':'type','name':'题材','init':'all','value':[{'n':'热血','v':'rexue'},{'n':'格斗','v':'gedou'},{'n':'科幻','v':'kehuan'},{'n':'竞技','v':'jingji'},{'n':'搞笑','v':'gaoxiao'},{'n':'推理','v':'tuili'},{'n':'恐怖','v':'kongbu'},{'n':'耽美','v':'danmei'},{'n':'少女','v':'shaonv'},{'n':'恋爱','v':'lianai'},{'n':'生活','v':'shenghuo'},{'n':'战争','v':'zhanzheng'},{'n':'故事','v':'gushi'},{'n':'冒险','v':'maoxian'},{'n':'魔幻','v':'mohuan'},{'n':'玄幻','v':'xuanhuan'},{'n':'校园','v':'xiaoyuan'},{'n':'悬疑','v':'xuanyi'},{'n':'萌系','v':'mengxi'},{'n':'穿越','v':'chuanyue'},{'n':'后宫','v':'hougong'},{'n':'都市','v':'dushi'},{'n':'武侠','v':'wuxia'},{'n':'历史','v':'lishi'},{'n':'同人','v':'tongren'},{'n':'励志','v':'lizhi'},{'n':'百合','v':'baihe'},{'n':'治愈','v':'zhiyu'},{'n':'机甲','v':'jijia'},{'n':'纯爱','v':'chunai'},{'n':'美食','v':'meishi'},{'n':'血腥','v':'xuexing'},{'n':'僵尸','v':'jiangshi'},{'n':'恶搞','v':'egao'},{'n':'虐心','v':'nuexin'},{'n':'动作','v':'dongzuo'},{'n':'惊险','v':'jingxian'},{'n':'唯美','v':'weimei'},{'n':'震撼','v':'zhenhan'},{'n':'复仇','v':'fuchou'},{'n':'侦探','v':'zhentan'},{'n':'脑洞','v':'naodong'},{'n':'奇幻','v':'qihuan'},{'n':'宫斗','v':'gongdou'},{'n':'爆笑','v':'baoxiao'},{'n':'运动','v':'yundong'},{'n':'青春','v':'qingchun'},{'n':'灵异','v':'lingyi'},{'n':'古风','v':'gufeng'},{'n':'权谋','v':'quanmou'},{'n':'节操','v':'jiecao'},{'n':'明星','v':'mingxing'},{'n':'暗黑','v':'anhei'},{'n':'社会','v':'shehui'},{'n':'浪漫','v':'langman'},{'n':'栏目','v':'lanmu'},{'n':'仙侠','v':'xianxia'}]},
  28. {'key':'type','name':'字母','init':'all','value':[{'n':'A','v':'lettera'},{'n':'B','v':'letterb'},{'n':'C','v':'letterc'},{'n':'D','v':'letterd'},{'n':'E','v':'lettere'},{'n':'F','v':'letterf'},{'n':'G','v':'letterg'},{'n':'H','v':'letterh'},{'n':'I','v':'letteri'},{'n':'J','v':'letterj'},{'n':'K','v':'letterk'},{'n':'L','v':'letterl'},{'n':'M','v':'letterm'},{'n':'N','v':'lettern'},{'n':'O','v':'lettero'},{'n':'P','v':'letterp'},{'n':'Q','v':'letterq'},{'n':'R','v':'letterr'},{'n':'S','v':'letters'},{'n':'T','v':'lettert'},{'n':'U','v':'letteru'},{'n':'V','v':'letterv'},{'n':'W','v':'letterw'},{'n':'X','v':'letterx'},{'n':'Y','v':'lettery'},{'n':'Z','v':'letterz'}]},
  29. ],
  30. };
  31. return JSON.stringify({
  32. class: classes,
  33. filters: filterObj,
  34. });
  35. }
  36. async function category(tid, pg, filter, extend) {
  37. if (pg == 0) pg = 1;
  38. let page = '';
  39. if (pg > 1) {
  40. page = `${pg}.html`;
  41. }
  42. const link = HOST + `/${extend.type || 'all'}/${page}`;
  43. const html = await request(link);
  44. const $ = load(html);
  45. const list = $('.dmList li');
  46. const books = _.map(list, (item) => {
  47. const $item = $(item);
  48. const $a = $item.find('dt a:first');
  49. const $img = $item.find('img:first');
  50. const $span = $item.find('span:first');
  51. return {
  52. book_id: $a.attr('href'),
  53. book_name: $a.text(),
  54. book_pic: $img.attr('src'),
  55. book_remarks: $span.text(),
  56. };
  57. });
  58. const hasMore = $('.NewPages a:contains(下一页)').length > 0;
  59. return {
  60. page: pg,
  61. pagecount: hasMore ? pg + 1 : pg,
  62. list: books,
  63. };
  64. }
  65. async function detail(id) {
  66. const html = await request(HOST + id);
  67. const $ = load(html);
  68. const book = {
  69. book_name: $('.title h1').text(),
  70. book_director: $('.info p:contains(原著作者) a').text().trim(),
  71. book_content: $('.introduction').text().trim(),
  72. book_remarks: $('.title a:first').text(),
  73. };
  74. const list = $('.plist a');
  75. const urls = _.map(list, (item) => {
  76. const $item = $(item);
  77. let title = $item.text().trim();
  78. if (_.isEmpty(title)) {
  79. title = '观看'
  80. }
  81. const href = $item.attr('href');
  82. return title + '$' + href;
  83. }).join('#');
  84. book.volumes = '笨狗';
  85. book.urls = urls;
  86. return {
  87. list: [book],
  88. };
  89. }
  90. async function play(flag, id, flags) {
  91. try {
  92. const html = await request(HOST + id);
  93. const matches = html.match(/var qTcms_S_m_murl_e=\"(.*)\";/);
  94. const decoded = base64Decode(matches[1]);
  95. const picList = decoded.split('$');
  96. const content = [];
  97. for (let i = 0; i < picList.length; i += 2) {
  98. content.push(picList[i]);
  99. }
  100. return {
  101. content: content,
  102. };
  103. } catch (e) {
  104. console.debug('error: ' + e);
  105. return {
  106. content: '',
  107. };
  108. }
  109. }
  110. function base64Decode(text) {
  111. return Crypto.enc.Utf8.stringify(Crypto.enc.Base64.parse(text));
  112. }
  113. async function search(wd, quick, pg) {
  114. if (pg == 0) pg = 1;
  115. let page = '';
  116. if (pg > 1) {
  117. page = `&page=${pg}`;
  118. }
  119. const link = HOST + `/statics/search.aspx?key=${encodeURIComponent(wd)}${page}`;
  120. const html = await request(link);
  121. const $ = load(html);
  122. const list = $('.dmList li');
  123. const books = _.map(list, (item) => {
  124. const $item = $(item);
  125. const $a = $item.find('dt a:first');
  126. const $img = $item.find('img:first');
  127. const $span = $item.find('span:first');
  128. return {
  129. book_id: $a.attr('href'),
  130. book_name: $a.text(),
  131. book_pic: $img.attr('src'),
  132. book_remarks: $span.text(),
  133. };
  134. });
  135. const hasMore = $('.NewPages a:contains(下一页)').length > 0;
  136. return {
  137. page: pg,
  138. pagecount: hasMore ? pg + 1 : pg,
  139. list: books,
  140. };
  141. }
  142. export function __jsEvalReturn() {
  143. return {
  144. init: init,
  145. home: home,
  146. category: category,
  147. detail: detail,
  148. play: play,
  149. search: search,
  150. };
  151. }