99 lines
3.2 KiB
JavaScript
99 lines
3.2 KiB
JavaScript
(function () {
|
|
// Ambil router_id dari <script src="?router_id=...">
|
|
function getRouterIdFromScriptSrc() {
|
|
const script = document.currentScript;
|
|
if (script && script.src) {
|
|
const url = new URL(script.src);
|
|
return url.searchParams.get("i");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
const i = getRouterIdFromScriptSrc() || "unknown";
|
|
console.log("Halaman login diakses dari MikroTik:", i);
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const container = document.getElementById("voucher-container");
|
|
|
|
if (container) {
|
|
const iframe = document.createElement("iframe");
|
|
iframe.id = "voucherFrame";
|
|
iframe.src = "https://manjapro.net/voucherpay/?i=" + encodeURIComponent(i);
|
|
iframe.style.width = "100%";
|
|
iframe.style.border = "none";
|
|
iframe.style.display = "block";
|
|
iframe.setAttribute("scrolling", "no");
|
|
container.appendChild(iframe);
|
|
}
|
|
|
|
// Cek jika status sudah "Lunas", isi otomatis input login
|
|
const status = localStorage.getItem("status");
|
|
const voucher = localStorage.getItem("voucher");
|
|
|
|
if (status === "Lunas" && voucher) {
|
|
console.log("Mendeteksi status Lunas, mengisi otomatis input dengan voucher:", voucher);
|
|
const inputs = [
|
|
document.querySelector('#voucher'),
|
|
document.querySelector('input[name="username"]'),
|
|
document.querySelector('input[name="password"]')
|
|
];
|
|
|
|
inputs.forEach((input, i) => {
|
|
if (input) {
|
|
input.value = voucher;
|
|
console.log(`Input otomatis (${input.name || input.id}): ${voucher}`);
|
|
}
|
|
});
|
|
|
|
// Cegah reload berulang dengan flag khusus
|
|
if (!sessionStorage.getItem("voucher_reloaded")) {
|
|
sessionStorage.setItem("voucher_reloaded", "1");
|
|
console.log("Melakukan reload sekali untuk mengaktifkan form login");
|
|
location.reload();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Terima pesan tinggi dari iframe dan isi otomatis voucher jika lunas
|
|
window.addEventListener("message", function (event) {
|
|
const data = event.data;
|
|
|
|
// Atur tinggi iframe jika ada
|
|
if (typeof data === "object" && data.frameHeight) {
|
|
const iframe = document.getElementById("voucherFrame");
|
|
if (iframe) {
|
|
iframe.style.height = data.frameHeight + "px";
|
|
console.log("Iframe height disesuaikan:", data.frameHeight);
|
|
}
|
|
}
|
|
|
|
// Isi voucher otomatis dan reload
|
|
if (data.type === "voucher_paid" && data.voucher) {
|
|
console.log("Menerima voucher_paid dari iframe:", data.voucher);
|
|
|
|
// localStorage.setItem("status", "Lunas");
|
|
// localStorage.setItem("voucher", data.voucher);
|
|
|
|
const inputs = [
|
|
document.querySelector('#voucher'),
|
|
document.querySelector('input[name="username"]'),
|
|
document.querySelector('input[name="password"]')
|
|
];
|
|
|
|
inputs.forEach((input, i) => {
|
|
if (input) {
|
|
input.value = data.voucher;
|
|
console.log(`Input dari iframe (${input.name || input.id}): ${data.voucher}`);
|
|
}
|
|
});
|
|
|
|
// Reload supaya auto-fill login aktif
|
|
if (!sessionStorage.getItem("voucher_reloaded")) {
|
|
sessionStorage.setItem("voucher_reloaded", "1");
|
|
console.log("Melakukan reload sekali untuk auto login");
|
|
location.reload();
|
|
}
|
|
}
|
|
});
|
|
})();
|