Skip to content

Commit 47ca38b

Browse files
minor fix regarding bug when reloading the getting started page, the serial number checker was improperly loaded
1 parent 71d807e commit 47ca38b

File tree

1 file changed

+103
-93
lines changed

1 file changed

+103
-93
lines changed

docs/public/scripts/ssnc.js

Lines changed: 103 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,121 @@
1-
const prefix = document.getElementById("serial-prefix");
2-
const digits = document.getElementById("serial-digits");
3-
const result = document.getElementById("serial-result");
4-
const resultSerial = document.getElementById("serial-result-serial");
5-
const resultText = document.getElementById("serial-result-text");
6-
7-
function checkSerial(s) {
8-
if (s.match(/^X[KJWT][JWCE]/)) return 'mariko';
9-
if (s.match(/^HA[JKWE]/)) return 'switch2';
10-
if (!s.match(/^XA[JKW9][1479]/)) return 'invalid';
11-
12-
if (s.length >= 10 && s.length < 14) s = s.padEnd(14, 'X');
13-
if (s.length !== 14) return 'invalid';
14-
15-
const region = s[2];
16-
const assemblyLine = parseInt(s[3]);
17-
const checkingValue = parseInt(s.slice(3, 10));
18-
19-
if (region === 'K') return 'maybe';
20-
if (region === '9') return 'maybe';
21-
22-
if (region === 'J') {
23-
if (assemblyLine === 1) {
24-
if (checkingValue < 1002000) return 'unpatched';
25-
if (checkingValue < 1003000) return 'maybe';
26-
return 'patched'
27-
} else if (assemblyLine === 4) {
28-
if (checkingValue < 4004400) return 'unpatched';
29-
if (checkingValue < 4008300) return 'maybe';
30-
return 'patched'
31-
} else if (assemblyLine === 7) {
32-
if (checkingValue < 7004000) return 'unpatched';
33-
if (checkingValue < 7005000) return 'maybe';
34-
return 'patched'
1+
function initSerialChecker() {
2+
const prefix = document.getElementById("serial-prefix");
3+
const digits = document.getElementById("serial-digits");
4+
const result = document.getElementById("serial-result");
5+
const resultSerial = document.getElementById("serial-result-serial");
6+
const resultText = document.getElementById("serial-result-text");
7+
8+
if (!prefix || !digits) return;
9+
10+
function checkSerial(s) {
11+
if (s.match(/^X[KJWT][JWCE]/)) return 'mariko';
12+
if (s.match(/^HA[JKWE]/)) return 'switch2';
13+
if (!s.match(/^XA[JKW9][1479]/)) return 'invalid';
14+
15+
if (s.length >= 10 && s.length < 14) s = s.padEnd(14, 'X');
16+
if (s.length !== 14) return 'invalid';
17+
18+
const region = s[2];
19+
const assemblyLine = parseInt(s[3]);
20+
const checkingValue = parseInt(s.slice(3, 10));
21+
22+
if (region === 'K') return 'maybe';
23+
if (region === '9') return 'maybe';
24+
25+
if (region === 'J') {
26+
if (assemblyLine === 1) {
27+
if (checkingValue < 1002000) return 'unpatched';
28+
if (checkingValue < 1003000) return 'maybe';
29+
return 'patched'
30+
} else if (assemblyLine === 4) {
31+
if (checkingValue < 4004400) return 'unpatched';
32+
if (checkingValue < 4008300) return 'maybe';
33+
return 'patched'
34+
} else if (assemblyLine === 7) {
35+
if (checkingValue < 7004000) return 'unpatched';
36+
if (checkingValue < 7005000) return 'maybe';
37+
return 'patched'
38+
}
3539
}
36-
}
3740

38-
if (region === 'W') {
39-
if (assemblyLine === 1) {
40-
if (checkingValue < 1006500) return 'unpatched';
41-
if (checkingValue < 1012000) return 'maybe';
42-
return 'patched';
43-
} else if (assemblyLine === 4) {
44-
if (checkingValue < 4001100) return 'unpatched';
45-
if (checkingValue < 4001200) return 'maybe';
46-
return 'patched';
47-
} else if (assemblyLine === 7) {
48-
if (checkingValue < 7001750) return 'unpatched';
49-
if (checkingValue < 7003000) return 'maybe';
50-
return 'patched';
51-
} else if (assemblyLine === 9) {
52-
return 'maybe';
41+
if (region === 'W') {
42+
if (assemblyLine === 1) {
43+
if (checkingValue < 1006500) return 'unpatched';
44+
if (checkingValue < 1012000) return 'maybe';
45+
return 'patched';
46+
} else if (assemblyLine === 4) {
47+
if (checkingValue < 4001100) return 'unpatched';
48+
if (checkingValue < 4001200) return 'maybe';
49+
return 'patched';
50+
} else if (assemblyLine === 7) {
51+
if (checkingValue < 7001750) return 'unpatched';
52+
if (checkingValue < 7003000) return 'maybe';
53+
return 'patched';
54+
} else if (assemblyLine === 9) {
55+
return 'maybe';
56+
}
5357
}
58+
59+
return 'invalid';
5460
}
5561

56-
return 'invalid';
57-
}
62+
const messages = {
63+
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>.' },
64+
switch2: { type: 'danger', text: 'This appears to be a <strong>Switch 2</strong>. These are currently not hackable.' },
65+
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>.' },
66+
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>.' },
67+
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>.' },
68+
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.' },
69+
invalid: { type: 'danger', text: 'This serial is <strong>invalid</strong>. Double-check you typed it correctly. At minimum, provide 6 digits after the prefix.' },
70+
}
5871

59-
const messages = {
60-
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>.' },
61-
switch2: { type: 'danger', text: 'This appears to be a <strong>Switch 2</strong>. These are currently not hackable.' },
62-
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>.' },
63-
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>.' },
64-
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>.' },
65-
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.' },
66-
invalid: { type: 'danger', text: 'This serial is <strong>invalid</strong>. Double-check you typed it correctly. At minimum, provide 6 digits after the prefix.' },
67-
}
72+
function redact(s) {
73+
if (s.length <= 9) return s;
74+
return s.slice(0, 9) + 'XXXX';
75+
}
6876

69-
function redact(s) {
70-
if (s.length <= 9) return s;
71-
return s.slice(0, 9) + 'XXXX';
72-
}
77+
function outputResult(serial, {type, text}) {
78+
resultSerial.innerText = serial;
79+
resultText.innerHTML = text;
80+
result.classList = type;
81+
}
7382

74-
function outputResult(serial, {type, text}) {
75-
resultSerial.innerText = serial;
76-
resultText.innerHTML = text;
77-
result.classList = type;
78-
}
7983

84+
function serialChangeEvent() {
85+
const d = digits.value.replace(/\D/g, '');
86+
const s = (prefix.value + d).toUpperCase();
8087

81-
function serialChangeEvent() {
82-
const d = digits.value.replace(/\D/g, '');
83-
const s = (prefix.value + d).toUpperCase();
88+
const earlyCheck = checkSerial(s.padEnd(14, 'X'));
89+
if (earlyCheck === 'mariko' || earlyCheck === 'switch2') {
90+
outputResult(prefix.value + "…", messages[earlyCheck]);
91+
return;
92+
}
8493

85-
const earlyCheck = checkSerial(s.padEnd(14, 'X'));
86-
if (earlyCheck === 'mariko' || earlyCheck === 'switch2') {
87-
outputResult(prefix.value + "…", messages[earlyCheck]);
88-
return;
89-
}
94+
if (prefix.value === 'XAW9') {
95+
outputResult(prefix.value + "…", messages.refurb);
96+
return;
97+
}
9098

91-
if (prefix.value === 'XAW9') {
92-
outputResult(prefix.value + "…", messages.refurb);
93-
return;
94-
}
99+
if (prefix.value === 'XAK1') {
100+
outputResult(prefix.value + "…", messages.maybe);
101+
return;
102+
}
95103

96-
if (prefix.value === 'XAK1') {
97-
outputResult(prefix.value + "…", messages.maybe);
98-
return;
99-
}
104+
if (d.length < 6) {
105+
result.classList = "serial-result-hidden";
106+
return;
107+
}
100108

101-
if (d.length < 6) {
102-
result.classList = "serial-result-hidden";
103-
return;
109+
const key = checkSerial(s);
110+
outputResult(redact(s), messages[key]);
104111
}
105112

106-
const key = checkSerial(s);
107-
outputResult(redact(s), messages[key]);
113+
prefix.addEventListener("change", serialChangeEvent);
114+
digits.addEventListener("input", serialChangeEvent);
108115
}
109116

110-
prefix.addEventListener("change", serialChangeEvent);
111-
digits.addEventListener("input", serialChangeEvent);
117+
if (document.readyState === "loading") {
118+
document.addEventListener("DOMContentLoaded", initSerialChecker);
119+
} else {
120+
initSerialChecker();
121+
}

0 commit comments

Comments
 (0)