Kembali ke Beranda
Gistify Snippet
igStalkV2.jsjavascript
99 baris| 1 | import axios from 'axios'; |
| 2 | import { wrapper } from 'axios-cookiejar-support'; |
| 3 | import { CookieJar } from 'tough-cookie'; |
| 4 | |
| 5 | const jar = new CookieJar(); |
| 6 | const client = wrapper(axios.create({ jar, withCredentials: true })); |
| 7 | |
| 8 | const baseHeaders = { |
| 9 | 'host': 'insta-stories-viewer.com', |
| 10 | 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0', |
| 11 | 'accept': '*/*', |
| 12 | 'accept-language': 'en-US,en;q=0.9', |
| 13 | 'accept-encoding': 'gzip, deflate, br, zstd', |
| 14 | 'origin': 'https://insta-stories-viewer.com', |
| 15 | 'sec-fetch-dest': 'empty', |
| 16 | 'sec-fetch-mode': 'cors', |
| 17 | 'sec-fetch-site': 'same-origin', |
| 18 | 'te': 'trailers' |
| 19 | }; |
| 20 | |
| 21 | async function run(username) { |
| 22 | const referer = `https://insta-stories-viewer.com/${username}/`; |
| 23 | const headers = { ...baseHeaders, referer }; |
| 24 | const t = () => `O${Date.now()}${Math.random().toString(36).substring(2, 7)}`; |
| 25 | |
| 26 | try { |
| 27 | const resHtml = await client.get(`https://insta-stories-viewer.com/${username}/`, { |
| 28 | headers: { |
| 29 | ...baseHeaders, |
| 30 | 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| 31 | 'sec-fetch-dest': 'document', |
| 32 | 'sec-fetch-mode': 'navigate', |
| 33 | 'upgrade-insecure-requests': '1' |
| 34 | } |
| 35 | }); |
| 36 | const html = resHtml.data; |
| 37 | |
| 38 | const getMeta = (regexStr) => { |
| 39 | const match = html.match(new RegExp(regexStr)); |
| 40 | return match ? match[1].trim() : null; |
| 41 | }; |
| 42 | |
| 43 | const metadata = { |
| 44 | posts: getMeta('profile__stats-posts">([^<]+)<'), |
| 45 | followers: getMeta('profile__stats-followers">([^<]+)<'), |
| 46 | following: getMeta('profile__stats-follows">([^<]+)<'), |
| 47 | avatar: getMeta('<img class="profile__avatar-pic" src="([^"]+)"') |
| 48 | }; |
| 49 | |
| 50 | const resConnect = await client.get('https://insta-stories-viewer.com/connect/', { headers }); |
| 51 | const token = resConnect.data.token; |
| 52 | |
| 53 | const resPoll1 = await client.get(`https://insta-stories-viewer.com/socket.io/?EIO=4&transport=polling&t=${t()}`, { headers }); |
| 54 | const sidMatch = resPoll1.data.match(/"sid":"([^"]+)"/); |
| 55 | if (!sidMatch) throw new Error("Failed to connect: sid not found in response."); |
| 56 | const sid = sidMatch[1]; |
| 57 | |
| 58 | await client.post(`https://insta-stories-viewer.com/socket.io/?EIO=4&transport=polling&t=${t()}&sid=${sid}`, '40', { headers: { ...headers, 'content-type': 'text/plain;charset=UTF-8' } }); |
| 59 | |
| 60 | await client.get(`https://insta-stories-viewer.com/socket.io/?EIO=4&transport=polling&t=${t()}&sid=${sid}`, { headers }); |
| 61 | await client.get(`https://insta-stories-viewer.com/socket.io/?EIO=4&transport=polling&t=${t()}&sid=${sid}`, { headers }); |
| 62 | |
| 63 | const date = Date.now(); |
| 64 | const payload = `42["search",{"username":"${username}","date":${date},"token":"${token}"}]`; |
| 65 | await client.post(`https://insta-stories-viewer.com/socket.io/?EIO=4&transport=polling&t=${t()}&sid=${sid}`, payload, { headers: { ...headers, 'content-type': 'text/plain;charset=UTF-8' } }); |
| 66 | |
| 67 | const resPollFinal = await client.get(`https://insta-stories-viewer.com/socket.io/?EIO=4&transport=polling&t=${t()}&sid=${sid}`, { headers }); |
| 68 | const rawData = resPollFinal.data; |
| 69 | |
| 70 | let storiesData = []; |
| 71 | if (typeof rawData === 'string' && rawData.startsWith('42')) { |
| 72 | const parsed = JSON.parse(rawData.substring(2)); |
| 73 | if (Array.isArray(parsed) && parsed.length > 1) { |
| 74 | storiesData = parsed[1]; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return { |
| 79 | status: "success", |
| 80 | code: 200, |
| 81 | username: username, |
| 82 | result: { |
| 83 | metadata: metadata, |
| 84 | stories: storiesData |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | } catch (err) { |
| 89 | return { |
| 90 | status: "error", |
| 91 | code: err.response ? err.response.status : 500, |
| 92 | username: username, |
| 93 | result: { message: err.message } |
| 94 | }; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | const username = process.argv[2] || 'prabowo'; |
| 99 | run(username).then(res => console.log(JSON.stringify(res, null, 2))); |
Diskusi & Komentar0
Belum ada komentar — jadilah yang pertama memberikan masukan atau diskusi kode.
Masuk dengan akun GitHub untuk menulis komentar dan berdiskusi.