Advertisement
WILDAN_IZZUDIN

[TS] NOTED.LOL

Mar 17th, 2025
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as cheerio from 'cheerio'
  2. import axios from 'axios'
  3.  
  4. const instance = axios.create({
  5.    timeout: 60000,
  6.    headers: {
  7.       'origin': 'https://noted.lol',
  8.       'referer': 'https://noted.lol/'
  9.    }
  10. })
  11.  
  12. interface Homepage {
  13.    creator: string,
  14.    status: boolean,
  15.    msg?: string,
  16.    data?: any
  17. }
  18.  
  19. class Noted {
  20.    baseUrl: string
  21.    creator: string
  22.  
  23.    constructor() {
  24.       this.baseUrl = 'https://noted.lol'
  25.       this.creator = '@neoxr.js - Wildan Izzudin'
  26.    }
  27.  
  28.    homepage = (): Promise<Homepage> => new Promise(async (resolve) => {
  29.       try {
  30.          const html = await (await instance.get(this.baseUrl)).data
  31.          const $ = cheerio.load(html)
  32.          const data: {
  33.             thumbnail?: string,
  34.             title: string,
  35.             read: string,
  36.             author: {
  37.                avatar?: string,
  38.                name: string,
  39.                about: string
  40.             },
  41.             url?: string
  42.          }[] = []
  43.  
  44.          $('ul.posts-list').find('li').each((i: number, e: any) => {
  45.             const title = $(e).find('h3.card-post-title').text()
  46.             if (title) data.push({
  47.                thumbnail: this.baseUrl + $(e).find('picture > img').attr('src'),
  48.                title,
  49.                read: $(e).find('.card-post-time').text(),
  50.                author: {
  51.                   avatar: $(e).find('.tooltip-custom-author > a > picture > img').attr('src'),
  52.                   name: $(e).find('.tooltip-custom-author > a').text()?.trim(),
  53.                   about: $(e).find('.tooltip-custom-author > div').text()?.trim()
  54.                },
  55.                url: this.baseUrl + $(e).find('a').attr('href')
  56.             })
  57.          })
  58.  
  59.          if (!data.length) throw new Error('Data not found')
  60.  
  61.          resolve({
  62.             creator: this.creator,
  63.             status: true,
  64.             data
  65.          })
  66.       } catch (e: any) {
  67.          resolve({
  68.             creator: this.creator,
  69.             status: false,
  70.             msg: e.message
  71.          })
  72.       }
  73.    })
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement