Archived
Show real IPv6 examples when available
This commit is contained in:
1 parent
9ec3d5c0fb
commit
0fc220b90b
3 files changed
+41
-3
No files matched your search
+39
-1
@@ -234,10 +234,48 @@ VISITOR_IP_JS = """
|
||||
replaceInCopyValues(search, replacement);
|
||||
};
|
||||
|
||||
const updateCopyCommand = (button, ipv6Command) => {
|
||||
const value = button.dataset.copy || "";
|
||||
if (!value || value.includes("?myipv6=")) return;
|
||||
const lines = value.split("\\n");
|
||||
const output = [];
|
||||
let inserted = false;
|
||||
lines.forEach((line) => {
|
||||
output.push(line);
|
||||
if (!inserted && line.includes("/api/v1/router/update/") && line.includes("?myip=")) {
|
||||
output.push(ipv6Command);
|
||||
inserted = true;
|
||||
}
|
||||
});
|
||||
if (inserted) button.dataset.copy = output.join("\\n");
|
||||
};
|
||||
|
||||
const insertIpv6Examples = (ip) => {
|
||||
if (!ip) return;
|
||||
document.querySelectorAll(".terminal-card.manual-code").forEach((card) => {
|
||||
if (card.textContent.includes("?myipv6=")) return;
|
||||
const lines = [...card.querySelectorAll("code")];
|
||||
const ipv4Line = lines.find((line) => line.textContent.includes("/api/v1/router/update/") && line.textContent.includes("?myip="));
|
||||
if (!ipv4Line) return;
|
||||
const base = ipv4Line.textContent.split("?myip=", 1)[0].replace(/'$/, "");
|
||||
const ipv6Command = `${base}?myipv6=${ip}'`;
|
||||
const code = document.createElement("code");
|
||||
code.textContent = ipv6Command;
|
||||
ipv4Line.after(code);
|
||||
const copyButton = card.querySelector("[data-copy]");
|
||||
if (copyButton) updateCopyCommand(copyButton, ipv6Command);
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const tasks = [];
|
||||
if (needsIpv4()) tasks.push(fetchIp("https://api4.ipify.org?format=json").then((ip) => replaceEverywhere(ipv4Placeholder, ip)));
|
||||
if (needsIpv6()) tasks.push(fetchIp("https://api6.ipify.org?format=json").then((ip) => replaceEverywhere(ipv6Placeholder, ip)));
|
||||
if (needsIpv6() || document.querySelector(".terminal-card.manual-code")) {
|
||||
tasks.push(fetchIp("https://api6.ipify.org?format=json").then((ip) => {
|
||||
replaceEverywhere(ipv6Placeholder, ip);
|
||||
insertIpv6Examples(ip);
|
||||
}));
|
||||
}
|
||||
await Promise.allSettled(tasks);
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in new issue
Block a user