/**
* ========================================================
* Name: VPLink.in URL Resolver & Safelink Scraper
*
* Cara Download:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/vplink-scraper" -o vplink-scraper.js
*
* Cara Eksekusi:
* node vplink-scraper.js "https://vplink.in/GuKTR"
* node vplink-scraper.js "https://vplink.in/7UyP"
*
* Author: Vamz Spectre
* Source: https://vamxapi.my.id
* ========================================================
*/
const DEFAULT_USER_AGENT =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
class CookieJar {
constructor() {
this.cookies = new Map();
}
ingest(headers) {
if (!headers) return;
let list = [];
if (typeof headers.getSetCookie === "function") {
list = headers.getSetCookie();
} else if (headers.get && headers.get("set-cookie")) {
list = [headers.get("set-cookie")];
} else if (headers["set-cookie"]) {
list = Array.isArray(headers["set-cookie"]) ? headers["set-cookie"] : [headers["set-cookie"]];
}
for (const item of list) {
if (!item) continue;
const [pair] = item.split(";");
const idx = pair.indexOf("=");
if (idx > 0) {
const k = pair.slice(0, idx).trim();
const v = pair.slice(idx + 1).trim();
if (v && v !== "deleted") {
this.cookies.set(k, v);
} else if (v === "deleted") {
this.cookies.delete(k);
}
}
}
}
get(name) {
return this.cookies.get(name);
}
set(name, value) {
this.cookies.set(name, value);
}
header() {
return [...this.cookies.entries()].map(([k, v]) => `${k}=${v}`).join("; ");
}
}
/**
* Helper fetch with CookieJar and timeout
*/
async function fetchWithJar(targetUrl, opts = {}, jar = null) {
const method = opts.method || "GET";
const headers = {
"User-Agent": DEFAULT_USER_AGENT,
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,application/json,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9,id;q=0.8",
...(opts.headers || {}),
};
if (jar) {
const c = jar.header();
if (c) headers["Cookie"] = c;
}
const controller = new AbortController();
const timeoutMs = opts.timeout || 15000;
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(targetUrl, {
method,
headers,
body: opts.body,
redirect: opts.redirect || "follow",
signal: controller.signal,
});
clearTimeout(timeoutId);
if (jar) jar.ingest(res.headers);
const text = await res.text();
return {
status: res.status,
headers: res.headers,
url: res.url,
text,
};
} catch (err) {
clearTimeout(timeoutId);
throw err;
}
}
/**
* Resolves vplink.in shortened link to destination URL & metadata
* @param {string} shortUrl Target shortened URL e.g. https://vplink.in/GuKTR
* @param {object} options Optional settings { proxy, timeout }
*/
async function scrapeVpLink(shortUrl, options = {}) {
const rawUrl = (shortUrl || "").trim();
if (!rawUrl) throw new Error("Parameter 'url' wajib disertakan.");
const codeMatch = rawUrl.match(/vplink\.(?:in|com)\/([a-zA-Z0-9_-]+)/i);
if (!codeMatch) {
throw new Error(
"URL tidak valid. Format harus berupa link vplink.in (contoh: https://vplink.in/GuKTR)"
);
}
const code = codeMatch[1];
const canonicalUrl = `https://vplink.in/${code}`;
const redirectChain = [canonicalUrl];
const jar = new CookieJar();
let metadata = {
title: null,
description: null,
ogImage: null,
};
// Helper parser for metadata
function extractMetadata(html) {
const titleMatch =
html.match(/]*property=["']og:title["'][^>]*content=["']([^"']+)["']/i) ||
html.match(/
]*>([^<]+)<\/title>/i);
const descMatch =
html.match(/]*property=["']og:description["'][^>]*content=["']([^"']+)["']/i) ||
html.match(/]*name=["']description["'][^>]*content=["']([^"']+)["']/i);
const imgMatch =
html.match(/]*property=["']og:image["'][^>]*content=["']([^"']+)["']/i);
if (titleMatch && !metadata.title) metadata.title = titleMatch[1].trim();
if (descMatch && !metadata.description) metadata.description = descMatch[1].trim();
if (imgMatch && !metadata.ogImage) metadata.ogImage = imgMatch[1].trim();
}
let finalDestination = null;
let isVpnBlocked = false;
// Step 1: Request inisial ke vplink landing page
const initialRes = await fetchWithJar(canonicalUrl, { timeout: options.timeout }, jar);
const initialHtml = initialRes.text;
extractMetadata(initialHtml);
if (initialHtml.includes("VPN Detected") || initialHtml.includes("isVPNDetected = true")) {
isVpnBlocked = true;
}
// Cari redirect script ke blog partner (pipefitter.in dsb)
let hopMatch =
initialHtml.match(/window\.location\.href\s*=\s*["']([^"']+)["']/i) ||
initialHtml.match(/]*href=["']([^"']+)["'][^>]*>click here<\/a>/i);
if (hopMatch) {
let nextUrl = hopMatch[1].replace(/\\\//g, "/");
if (!redirectChain.includes(nextUrl)) redirectChain.push(nextUrl);
let currentReferer = canonicalUrl;
let currentHop = nextUrl;
const maxHops = 10;
for (let i = 0; i < maxHops; i++) {
try {
const hopRes = await fetchWithJar(
currentHop,
{
headers: { Referer: currentReferer },
timeout: options.timeout || 10000,
},
jar
);
currentReferer = currentHop;
extractMetadata(hopRes.text);
// Deteksi direct URL redirect di blog partner
const nextJsRedir =
hopRes.text.match(/window\.location\.href\s*=\s*["']([^"']+)["']/i) ||
hopRes.text.match(/document\.location\.href\s*=\s*['"]([^'"]+)['"]/i);
if (nextJsRedir) {
let resolved = nextJsRedir[1].replace(/\\\//g, "/");
if (resolved.startsWith("/")) {
const origin = new URL(currentHop).origin;
resolved = origin + resolved;
}
if (resolved === currentHop || redirectChain.includes(resolved)) {
// Cek apakah ada script learn_more
if (currentHop.includes("studyinsurances") && !currentHop.includes("learn_more.php")) {
const origin = new URL(currentHop).origin;
resolved = `${origin}/studyinsurances/learn_more.php`;
} else if (currentHop.includes("educatestudy") && !currentHop.includes("learn_more.php")) {
const origin = new URL(currentHop).origin;
resolved = `${origin}/educatestudy/learn_more.php`;
} else {
break;
}
}
redirectChain.push(resolved);
currentHop = resolved;
continue;
}
// Jika tidak ada redirect langsung, cek form submission /links/go atau final button
if (currentHop.includes("vplink.in")) {
// Final landing di vplink
const getLinkMatch = hopRes.text.match(/]*id=["']get-link["'][^>]*href=["']([^"']+)["']/i);
if (getLinkMatch && getLinkMatch[1] && !getLinkMatch[1].startsWith("javascript") && getLinkMatch[1] !== "#") {
finalDestination = getLinkMatch[1];
}
// Cek token AroShield
const aroMatch = hopRes.text.match(/token:\s*["']([^"']+)["']/i);
const formTokenMatch = hopRes.text.match(/name=["']_csrfToken["'][^>]*value=["']([^"']+)["']/i);
const adFormDataMatch = hopRes.text.match(/name=["']ad_form_data["'][^>]*value=["']([^"']+)["']/i);
if (formTokenMatch && adFormDataMatch) {
jar.set("csrfToken", formTokenMatch[1]);
jar.set("ab", "2");
const postData = new URLSearchParams({
_method: "POST",
_csrfToken: formTokenMatch[1],
ad_form_data: adFormDataMatch[1],
...(aroMatch ? { arolinks_sec_token: aroMatch[1] } : {}),
});
// Kirim request links/go
const goRes = await fetchWithJar(
"https://vplink.in/links/go",
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
Referer: currentHop,
},
body: postData.toString(),
timeout: 10000,
},
jar
);
try {
const goJson = JSON.parse(goRes.text);
if (goJson.url && goJson.url !== "#") {
finalDestination = goJson.url;
if (!redirectChain.includes(finalDestination)) redirectChain.push(finalDestination);
}
} catch {}
}
break;
}
break;
} catch {
break;
}
}
}
const isResolved = Boolean(finalDestination && finalDestination !== "#");
return {
status: isResolved || !isVpnBlocked,
shortUrl: canonicalUrl,
code,
destination: finalDestination,
resolved: isResolved,
...(isVpnBlocked && !isResolved
? {
note: "IP Datacenter/VPS terdeteksi oleh vplink edge (VPN Detected). Jalankan melalui koneksi IP residensial/lokal atau proxy.",
}
: {}),
metadata: {
title: metadata.title || null,
description: metadata.description || null,
ogImage: metadata.ogImage || null,
},
redirectChain,
};
}
if (typeof module !== "undefined" && module.exports) {
module.exports = { scrapeVpLink };
}
// CLI Runner
const targetUrl = process.argv[2];
if (targetUrl) {
scrapeVpLink(targetUrl)
.then((res) => {
console.log(JSON.stringify(res, null, 2));
})
.catch((err) => {
console.error(JSON.stringify({ status: false, error: err.message }, null, 2));
process.exit(1);
});
} else if (process.argv[1] && process.argv.length <= 2) {
console.log('Usage: node vplink-scraper.js "https://vplink.in/GuKTR"');
}