/** * Generator.email Scraper & TempMail Client * Author: Vamz Spectre / VamxAPI * Website: https://vamxapi.my.id * * Cara Instalasi Dependencies: * npm install axios cheerio ws * * Cara Download File Ini 1:1: * curl -sL "https://code.vamxapi.my.id/snippet/raw/generator-email" -o generator-email.js * * Contoh Penggunaan CLI: * - Generate email baru: * node generator-email.js * - Custom email: * node generator-email.js "user@domain.com" * - Cek inbox email: * node generator-email.js --inbox="user@domain.com" * - Cari domain tempmail: * node generator-email.js --search="gmail" * - Cek semua domain aktif: * node generator-email.js --domains * - Cek uptime domain email: * node generator-email.js --uptime="user@domain.com" */ const axios = require('axios'); const cheerio = require('cheerio'); const WebSocket = require('ws'); const BASE_URL = 'https://generator.email'; const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'; class GeneratorEmail { constructor() { this.cookies = {}; this.token = ''; this.currentEmail = ''; this.currentUser = ''; this.currentDomain = ''; } _parseCookies(setCookieHeader) { if (!setCookieHeader) return; const headerArr = Array.isArray(setCookieHeader) ? setCookieHeader : [setCookieHeader]; headerArr.forEach(c => { const part = c.split(';')[0]; const [k, ...v] = part.split('='); if (k && v) { this.cookies[k.trim()] = v.join('=').trim(); } }); } _cookieHeader() { return Object.entries(this.cookies).map(([k, v]) => `${k}=${v}`).join('; '); } async init(customEmail) { const res = await axios.get(BASE_URL, { headers: { 'User-Agent': USER_AGENT, 'Cookie': this._cookieHeader() } }); this._parseCookies(res.headers['set-cookie']); const $ = cheerio.load(res.data); this.token = $('meta[name="api-token"]').attr('content') || ''; this.currentUser = $('#userName').val() || ''; this.currentDomain = $('#domainName2').val() || ''; this.currentEmail = `${this.currentUser}@${this.currentDomain}`; if (customEmail && customEmail.includes('@')) { return await this.switchMailbox(customEmail); } return { email: this.currentEmail, user: this.currentUser, domain: this.currentDomain, token: this.token }; } async getDomains() { if (!this.token) await this.init(); const res = await axios.get(`${BASE_URL}/api/domains.php`, { headers: { 'User-Agent': USER_AGENT, 'X-API-Token': this.token, 'X-Requested-With': 'XMLHttpRequest', 'Referer': `${BASE_URL}/`, 'Cookie': this._cookieHeader() } }); return res.data; } async searchDomains(query) { if (!this.token) await this.init(); const res = await axios.get(`${BASE_URL}/search.php?key=${encodeURIComponent(query)}`, { headers: { 'User-Agent': USER_AGENT, 'X-API-Token': this.token, 'X-Requested-With': 'XMLHttpRequest', 'Referer': `${BASE_URL}/`, 'Cookie': this._cookieHeader() } }); return res.data; } async switchMailbox(email) { if (!email || !email.includes('@')) { throw new Error('Format email tidak valid. Gunakan user@domain.com'); } const [user, domain] = email.split('@'); const res = await axios.get(`${BASE_URL}/${encodeURIComponent(user)}@${encodeURIComponent(domain)}`, { maxRedirects: 5, headers: { 'User-Agent': USER_AGENT, 'Referer': `${BASE_URL}/`, 'Cookie': this._cookieHeader() } }); this._parseCookies(res.headers['set-cookie']); this.currentUser = user; this.currentDomain = domain; this.currentEmail = email; const $ = cheerio.load(res.data); const newToken = $('meta[name="api-token"]').attr('content'); if (newToken) this.token = newToken; return { status: true, email: this.currentEmail, user: this.currentUser, domain: this.currentDomain }; } async getInbox(email) { if (email && email !== this.currentEmail) { await this.switchMailbox(email); } else if (!this.currentEmail) { await this.init(); } const res = await axios.get(`${BASE_URL}/inbox7/`, { headers: { 'User-Agent': USER_AGENT, 'Referer': `${BASE_URL}/`, 'Cookie': this._cookieHeader() } }); this._parseCookies(res.headers['set-cookie']); const $ = cheerio.load(res.data); const messages = []; $('#email-table .list-group-item').each((_, el) => { const from = $(el).find('.from_div_45g45gg').text().trim(); const subject = $(el).find('.subj_div_45g45gg').text().trim(); const time = $(el).find('.time_div_45g45gg').text().trim(); const onclick = $(el).attr('onclick') || ''; const match = onclick.match(/loadInboxClientSide\(['"]([^'"]+)['"]\)/); const link = match ? match[1] : ''; if (from || subject) { messages.push({ from, subject, time, link: link ? `${BASE_URL}${link.startsWith('/') ? '' : '/'}${link}` : '' }); } }); return { status: true, email: this.currentEmail, totalMessages: messages.length, messages }; } async checkUptime(email) { if (!email) email = this.currentEmail; if (!email) await this.init(); const [user, domain] = email.split('@'); const res = await axios.post(`${BASE_URL}/uptime.php`, `dmn=${encodeURIComponent(domain)}&usr=${encodeURIComponent(user)}`, { headers: { 'User-Agent': USER_AGENT, 'Content-Type': 'application/x-www-form-urlencoded', 'X-API-Token': this.token, 'Referer': `${BASE_URL}/`, 'Cookie': this._cookieHeader() } }); return res.data; } listenInbox(email, onMessage, timeoutMs = 60000) { const targetEmail = (email || this.currentEmail).toLowerCase(); const wsUrl = `wss://generator.email/notificon/ws?email=${encodeURIComponent(targetEmail)}`; const ws = new WebSocket(wsUrl, { headers: { 'User-Agent': USER_AGENT, 'Origin': BASE_URL } }); let timer = null; return new Promise((resolve, reject) => { if (timeoutMs > 0) { timer = setTimeout(() => { ws.close(); resolve({ status: true, message: 'Listening timeout reached' }); }, timeoutMs); } ws.on('open', () => {}); ws.on('message', (data) => { try { const parsed = JSON.parse(data.toString()); if (onMessage) onMessage(parsed); } catch (e) {} }); ws.on('close', () => { if (timer) clearTimeout(timer); resolve({ status: true, message: 'Closed' }); }); ws.on('error', (err) => { if (timer) clearTimeout(timer); reject(err); }); }); } } async function main() { const arg = process.argv[2] || '--generate'; const api = new GeneratorEmail(); try { if (arg === '--domains') { const domains = await api.getDomains(); console.log(JSON.stringify({ status: true, total: domains.length, domains: domains.slice(0, 30) }, null, 2)); } else if (arg.startsWith('--search=')) { const q = arg.replace('--search=', ''); const results = await api.searchDomains(q); console.log(JSON.stringify({ status: true, query: q, results }, null, 2)); } else if (arg.startsWith('--inbox=')) { const mail = arg.replace('--inbox=', ''); const inbox = await api.getInbox(mail); console.log(JSON.stringify(inbox, null, 2)); } else if (arg.startsWith('--uptime=')) { const mail = arg.replace('--uptime=', ''); const uptime = await api.checkUptime(mail); console.log(JSON.stringify({ status: true, email: mail, uptime }, null, 2)); } else { const custom = arg === '--generate' ? null : arg; const res = await api.init(custom); const uptime = await api.checkUptime(res.email); console.log(JSON.stringify({ status: true, email: res.email, user: res.user, domain: res.domain, uptime, actions: { checkInbox: `node generator-email.js --inbox=${res.email}`, checkUptime: `node generator-email.js --uptime=${res.email}`, searchDomain: `node generator-email.js --search=mail`, listDomains: `node generator-email.js --domains` } }, null, 2)); } } catch (err) { console.error(JSON.stringify({ status: false, error: err.message }, null, 2)); process.exit(1); } } if (require.main === module) { main(); } module.exports = GeneratorEmail;