File size: 3,255 Bytes
6c3ddee
 
 
 
 
 
 
 
 
 
4d3b003
1511aba
6c3ddee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { chromium } = require('playwright');
const express = require('express');
const archiver = require('archiver');
const { tmpdir } = require('os');
const { join } = require('path');
const { mkdirSync, rmSync } = require('fs');

const app = express();
app.use(express.json());

app.get('/run', async (req, res) => {
  const { url = 'https://ysmteam.io.vn/keys/free?admin=YSMTEAM&region=Global', game = 'com.dts.freefireth' } = req.body;
  const ts = Date.now();
  const dir = join(tmpdir(), `ysm-${ts}`);
  mkdirSync(dir, { recursive: true });

  const browser = await chromium.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
  const context = await browser.newContext({ recordHar: { path: join(dir, 'traffic.har'), mode: 'full' } });

  context.on('page', async p => {
    await p.addInitScript(() => {
      if (window.h) return; window.h = 1;
      (() => {
        const h = location.hostname;
        if (['biharkhabar.net', 'newkhabar24.com', 'insurance.odiadance.com', 'goodmorningimg.com', 'sarkarikhoj.com', 'metavise.in', 'vbnmx.online', 'property.vbnmx.online', 'earnbox.in'].includes(h)) {
          const i = setInterval(() => {
            const b = document.querySelector('center a button#tp-snp2') || [...document.querySelectorAll('center a button')].find(b => b.innerText.toUpperCase().includes('COUNTIUE'));
            if (b?.closest('a')?.href) { clearInterval(i); location.href = b.closest('a').href; }
          }, 100);
        }
        if (h === 'go.just2earn.com') {
          const i = setInterval(() => {
            const t = document.querySelector('#timer'); const b = document.querySelector('.get-link');
            if (t && b && +t.innerText === 0 && !b.classList.contains('disabled')) { clearInterval(i); b.click(); }
          }, 300);
        }
      })();
    });
  });

  const page = await context.newPage();
  await page.goto(url, { waitUntil: 'networkidle' });
  await page.selectOption('select#game', game);
  await page.click('button#btn_submit');

  let lastPage = page;
  while (true) {
    try {
      const [p] = await Promise.race([
        context.waitForEvent('page', { timeout: 8000 }),
        page.waitForTimeout(8000).then(() => null)
      ]);
      if (!p) break;
      lastPage = p;
      await lastPage.waitForLoadState('networkidle');
    } catch { break; }
  }

  const html = await lastPage.content();
  const css = await lastPage.evaluate(() => [...document.styleSheets].map(s => s.href ? `@import "${s.href}";` : [...s.cssRules].map(r => r.cssText).join('')).join('\n'));
  const js = await lastPage.evaluate(() => [...document.scripts].map(s => s.src ? `// ${s.src}` : s.textContent).join('\n\n'));

  const zip = archiver('zip', { zlib: { level: 9 } });
  res.setHeader('Content-Type', 'application/zip');
  res.setHeader('Content-Disposition', `attachment; filename="ysm-${ts}.zip"`);

  zip.pipe(res);
  zip.append(html, { name: 'index.html' });
  zip.append(css, { name: 'styles.css' });
  zip.append(js, { name: 'scripts.js' });
  zip.finalize();

  await browser.close();
  res.on('finish', () => rmSync(dir, { recursive: true, force: true }));
});

const PORT = process.env.PORT || 7860;
app.listen(PORT, () => console.log(`API ready on ${PORT}`));