egoist's notebooks

  • sponsors-count - /egoist/sponsors-count
    Last edited 3 years ago
    const fetch = require('node-fetch') exports.endpoint = async (req, res) => { const username = req.url.replace('/', '') console.log(req.url) const html = await fetch(`https://github.com/sponsors/${username}`, { headers: { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36' } }).then(res => res.text()) const m = /(\d+)[\s\n]+sponsors[\s\n]+are[\s\n]+funding[\s\n]+[a-zA-Z0-9-_]+’s work/.exec(html) res.end(JSON.stringify({ subject: 'Sponsors', status: m && m[1] || '0', color: 'purple' })) }