main.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const axios = require("axios");
  2. const cheerio = require("cheerio");
  3. if (typeof $dora == 'undefined') {
  4. console.error('This project runs only in Dora.js.')
  5. console.error('Please visit https://dorajs.com/ for more information.')
  6. process.exit(-1)
  7. }
  8. console.info('Congratulation, your addon runs successfully!')
  9. module.exports = {
  10. all_url: 'http://www.kmwu6.com',
  11. get_info: async (url) => {
  12. var res = await axios.get(url);
  13. var $ = cheerio.load(res.data);
  14. return {
  15. id: /\/(\d+)/g.exec(url)[1],
  16. title: $('.info > h1').text(),
  17. img: $('.cover img').eq(0).attr('src'),
  18. url: 'http://www.kmwu6.com' + $('.bottom .btn-2').eq(0).attr('href')
  19. }
  20. },
  21. set_url: async (url) => {
  22. var follows = $storage.get('follows');
  23. var id = /m\/(\d+)\//.exec(url)[1];
  24. var new_follows = follows.map(m => {
  25. if (id == m.id) {
  26. return {
  27. id: m.id,
  28. title: m.title,
  29. img: m.img,
  30. url: url
  31. }
  32. } else {
  33. return m;
  34. }
  35. })
  36. $storage.put('follows', new_follows);
  37. }
  38. }