mirror of
https://github.com/nh-server/switch-guide.git
synced 2026-08-15 20:19:49 -07:00
minor fix regarding bug when reloading the getting started page, the serial number checker was improperly loaded
This commit is contained in:
+101
-91
@@ -1,111 +1,121 @@
|
||||
const prefix = document.getElementById("serial-prefix");
|
||||
const digits = document.getElementById("serial-digits");
|
||||
const result = document.getElementById("serial-result");
|
||||
const resultSerial = document.getElementById("serial-result-serial");
|
||||
const resultText = document.getElementById("serial-result-text");
|
||||
function initSerialChecker() {
|
||||
const prefix = document.getElementById("serial-prefix");
|
||||
const digits = document.getElementById("serial-digits");
|
||||
const result = document.getElementById("serial-result");
|
||||
const resultSerial = document.getElementById("serial-result-serial");
|
||||
const resultText = document.getElementById("serial-result-text");
|
||||
|
||||
function checkSerial(s) {
|
||||
if (s.match(/^X[KJWT][JWCE]/)) return 'mariko';
|
||||
if (s.match(/^HA[JKWE]/)) return 'switch2';
|
||||
if (!s.match(/^XA[JKW9][1479]/)) return 'invalid';
|
||||
if (!prefix || !digits) return;
|
||||
|
||||
if (s.length >= 10 && s.length < 14) s = s.padEnd(14, 'X');
|
||||
if (s.length !== 14) return 'invalid';
|
||||
function checkSerial(s) {
|
||||
if (s.match(/^X[KJWT][JWCE]/)) return 'mariko';
|
||||
if (s.match(/^HA[JKWE]/)) return 'switch2';
|
||||
if (!s.match(/^XA[JKW9][1479]/)) return 'invalid';
|
||||
|
||||
const region = s[2];
|
||||
const assemblyLine = parseInt(s[3]);
|
||||
const checkingValue = parseInt(s.slice(3, 10));
|
||||
if (s.length >= 10 && s.length < 14) s = s.padEnd(14, 'X');
|
||||
if (s.length !== 14) return 'invalid';
|
||||
|
||||
if (region === 'K') return 'maybe';
|
||||
if (region === '9') return 'maybe';
|
||||
const region = s[2];
|
||||
const assemblyLine = parseInt(s[3]);
|
||||
const checkingValue = parseInt(s.slice(3, 10));
|
||||
|
||||
if (region === 'J') {
|
||||
if (assemblyLine === 1) {
|
||||
if (checkingValue < 1002000) return 'unpatched';
|
||||
if (checkingValue < 1003000) return 'maybe';
|
||||
return 'patched'
|
||||
} else if (assemblyLine === 4) {
|
||||
if (checkingValue < 4004400) return 'unpatched';
|
||||
if (checkingValue < 4008300) return 'maybe';
|
||||
return 'patched'
|
||||
} else if (assemblyLine === 7) {
|
||||
if (checkingValue < 7004000) return 'unpatched';
|
||||
if (checkingValue < 7005000) return 'maybe';
|
||||
return 'patched'
|
||||
if (region === 'K') return 'maybe';
|
||||
if (region === '9') return 'maybe';
|
||||
|
||||
if (region === 'J') {
|
||||
if (assemblyLine === 1) {
|
||||
if (checkingValue < 1002000) return 'unpatched';
|
||||
if (checkingValue < 1003000) return 'maybe';
|
||||
return 'patched'
|
||||
} else if (assemblyLine === 4) {
|
||||
if (checkingValue < 4004400) return 'unpatched';
|
||||
if (checkingValue < 4008300) return 'maybe';
|
||||
return 'patched'
|
||||
} else if (assemblyLine === 7) {
|
||||
if (checkingValue < 7004000) return 'unpatched';
|
||||
if (checkingValue < 7005000) return 'maybe';
|
||||
return 'patched'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (region === 'W') {
|
||||
if (assemblyLine === 1) {
|
||||
if (checkingValue < 1006500) return 'unpatched';
|
||||
if (checkingValue < 1012000) return 'maybe';
|
||||
return 'patched';
|
||||
} else if (assemblyLine === 4) {
|
||||
if (checkingValue < 4001100) return 'unpatched';
|
||||
if (checkingValue < 4001200) return 'maybe';
|
||||
return 'patched';
|
||||
} else if (assemblyLine === 7) {
|
||||
if (checkingValue < 7001750) return 'unpatched';
|
||||
if (checkingValue < 7003000) return 'maybe';
|
||||
return 'patched';
|
||||
} else if (assemblyLine === 9) {
|
||||
return 'maybe';
|
||||
if (region === 'W') {
|
||||
if (assemblyLine === 1) {
|
||||
if (checkingValue < 1006500) return 'unpatched';
|
||||
if (checkingValue < 1012000) return 'maybe';
|
||||
return 'patched';
|
||||
} else if (assemblyLine === 4) {
|
||||
if (checkingValue < 4001100) return 'unpatched';
|
||||
if (checkingValue < 4001200) return 'maybe';
|
||||
return 'patched';
|
||||
} else if (assemblyLine === 7) {
|
||||
if (checkingValue < 7001750) return 'unpatched';
|
||||
if (checkingValue < 7003000) return 'maybe';
|
||||
return 'patched';
|
||||
} else if (assemblyLine === 9) {
|
||||
return 'maybe';
|
||||
}
|
||||
}
|
||||
|
||||
return 'invalid';
|
||||
}
|
||||
|
||||
return 'invalid';
|
||||
}
|
||||
|
||||
const messages = {
|
||||
mariko: { type: 'warning', text: 'This appears to be a <strong>Mariko (V2) Switch or Switch Lite</strong>. These are patched and not hackable via software, only via hardware modchip. Find trusted hardmodders <a href="https://nintendohomebrew.com/hardmodders">here</a>.' },
|
||||
switch2: { type: 'danger', text: 'This appears to be a <strong>Switch 2</strong>. These are currently not hackable.' },
|
||||
refurb: { type: 'warning', text: 'This prefix belongs to officially <strong>refurbished Switch</strong> consoles, it <strong>might be patched</strong>. The only way to know for sure is to manually push a payload. Continue to <a href="/user_guide/rcm/sending_payload.html">this page</a>.' },
|
||||
maybe: { type: 'warning', text: 'This serial <strong>might be patched</strong>. The only way to know for sure is to manually push a payload. Continue to <a href="/user_guide/rcm/sending_payload.html">this page</a>.' },
|
||||
patched: { type: 'danger', text: 'This serial is <strong>patched</strong>. It is not hackable via software. Find trusted hardmodders <a href="https://nintendohomebrew.com/hardmodders">here</a>.' },
|
||||
unpatched: { type: 'tip', text: 'This serial is <strong>not patched</strong>! Click the following link to continue with the <a href="rcm/index">RCM path</a> of the guide.' },
|
||||
invalid: { type: 'danger', text: 'This serial is <strong>invalid</strong>. Double-check you typed it correctly. At minimum, provide 6 digits after the prefix.' },
|
||||
}
|
||||
|
||||
function redact(s) {
|
||||
if (s.length <= 9) return s;
|
||||
return s.slice(0, 9) + 'XXXX';
|
||||
}
|
||||
|
||||
function outputResult(serial, {type, text}) {
|
||||
resultSerial.innerText = serial;
|
||||
resultText.innerHTML = text;
|
||||
result.classList = type;
|
||||
}
|
||||
|
||||
|
||||
function serialChangeEvent() {
|
||||
const d = digits.value.replace(/\D/g, '');
|
||||
const s = (prefix.value + d).toUpperCase();
|
||||
|
||||
const earlyCheck = checkSerial(s.padEnd(14, 'X'));
|
||||
if (earlyCheck === 'mariko' || earlyCheck === 'switch2') {
|
||||
outputResult(prefix.value + "…", messages[earlyCheck]);
|
||||
return;
|
||||
const messages = {
|
||||
mariko: { type: 'warning', text: 'This appears to be a <strong>Mariko (V2) Switch or Switch Lite</strong>. These are patched and not hackable via software, only via hardware modchip. Find trusted hardmodders <a href="https://nintendohomebrew.com/hardmodders">here</a>.' },
|
||||
switch2: { type: 'danger', text: 'This appears to be a <strong>Switch 2</strong>. These are currently not hackable.' },
|
||||
refurb: { type: 'warning', text: 'This prefix belongs to officially <strong>refurbished Switch</strong> consoles, it <strong>might be patched</strong>. The only way to know for sure is to manually push a payload. Continue to <a href="/user_guide/rcm/sending_payload.html">this page</a>.' },
|
||||
maybe: { type: 'warning', text: 'This serial <strong>might be patched</strong>. The only way to know for sure is to manually push a payload. Continue to <a href="/user_guide/rcm/sending_payload.html">this page</a>.' },
|
||||
patched: { type: 'danger', text: 'This serial is <strong>patched</strong>. It is not hackable via software. Find trusted hardmodders <a href="https://nintendohomebrew.com/hardmodders">here</a>.' },
|
||||
unpatched: { type: 'tip', text: 'This serial is <strong>not patched</strong>! Click the following link to continue with the <a href="rcm/index">RCM path</a> of the guide.' },
|
||||
invalid: { type: 'danger', text: 'This serial is <strong>invalid</strong>. Double-check you typed it correctly. At minimum, provide 6 digits after the prefix.' },
|
||||
}
|
||||
|
||||
if (prefix.value === 'XAW9') {
|
||||
outputResult(prefix.value + "…", messages.refurb);
|
||||
return;
|
||||
function redact(s) {
|
||||
if (s.length <= 9) return s;
|
||||
return s.slice(0, 9) + 'XXXX';
|
||||
}
|
||||
|
||||
if (prefix.value === 'XAK1') {
|
||||
outputResult(prefix.value + "…", messages.maybe);
|
||||
return;
|
||||
function outputResult(serial, {type, text}) {
|
||||
resultSerial.innerText = serial;
|
||||
resultText.innerHTML = text;
|
||||
result.classList = type;
|
||||
}
|
||||
|
||||
if (d.length < 6) {
|
||||
result.classList = "serial-result-hidden";
|
||||
return;
|
||||
|
||||
function serialChangeEvent() {
|
||||
const d = digits.value.replace(/\D/g, '');
|
||||
const s = (prefix.value + d).toUpperCase();
|
||||
|
||||
const earlyCheck = checkSerial(s.padEnd(14, 'X'));
|
||||
if (earlyCheck === 'mariko' || earlyCheck === 'switch2') {
|
||||
outputResult(prefix.value + "…", messages[earlyCheck]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prefix.value === 'XAW9') {
|
||||
outputResult(prefix.value + "…", messages.refurb);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prefix.value === 'XAK1') {
|
||||
outputResult(prefix.value + "…", messages.maybe);
|
||||
return;
|
||||
}
|
||||
|
||||
if (d.length < 6) {
|
||||
result.classList = "serial-result-hidden";
|
||||
return;
|
||||
}
|
||||
|
||||
const key = checkSerial(s);
|
||||
outputResult(redact(s), messages[key]);
|
||||
}
|
||||
|
||||
const key = checkSerial(s);
|
||||
outputResult(redact(s), messages[key]);
|
||||
prefix.addEventListener("change", serialChangeEvent);
|
||||
digits.addEventListener("input", serialChangeEvent);
|
||||
}
|
||||
|
||||
prefix.addEventListener("change", serialChangeEvent);
|
||||
digits.addEventListener("input", serialChangeEvent);
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", initSerialChecker);
|
||||
} else {
|
||||
initSerialChecker();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user