diff --git a/docs/el_GR/get-started.md b/docs/el_GR/get-started.md index ac2cba12574a7..9c8b824ddc954 100644 --- a/docs/el_GR/get-started.md +++ b/docs/el_GR/get-started.md @@ -1,9 +1,10 @@ --- noneSelected: Απαιτείται το μοντέλο συστήματος. invalidVersion: Αυτή δεν φαίνεται να είναι έγκυρη έκδοση συστήματος. -head: - - - script - - src: /assets/js/selecting.js +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/selecting.js'}] +] --- # Έναρξη diff --git a/docs/el_GR/installing-boot9strap-(soundhax).md b/docs/el_GR/installing-boot9strap-(soundhax).md index f0b655060f528..7d564ee073f5a 100644 --- a/docs/el_GR/installing-boot9strap-(soundhax).md +++ b/docs/el_GR/installing-boot9strap-(soundhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/soundhax-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # Εγκατάσταση του boot9strap (Soundhax) :::details Τεχνικές λεπτομέρειες (προαιρετικό) diff --git a/docs/get-started.md b/docs/get-started.md index 8af23008827f6..ed9e9895c6543 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -2,6 +2,7 @@ noneSelected: System model is required. invalidVersion: This doesn't seem to be a valid system version. head: [ + ['script', {src: '/assets/js/common.js'}], ['script', {src: '/assets/js/selecting.js'}] ] --- diff --git a/docs/hu_HU/get-started.md b/docs/hu_HU/get-started.md index c8a1fd1badcdb..cf45161ae222f 100644 --- a/docs/hu_HU/get-started.md +++ b/docs/hu_HU/get-started.md @@ -1,9 +1,10 @@ --- noneSelected: A rendszer modell szükséges. invalidVersion: Ez nem tűnik egy érvényes rendszer verziónak. -head: - - - script - - src: /assets/js/selecting.js +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/selecting.js'}] +] --- # Kezdeti lépések diff --git a/docs/hu_HU/installing-boot9strap-(soundhax).md b/docs/hu_HU/installing-boot9strap-(soundhax).md index 51b7c1be84ef8..0257734424b26 100644 --- a/docs/hu_HU/installing-boot9strap-(soundhax).md +++ b/docs/hu_HU/installing-boot9strap-(soundhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/soundhax-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # Boot9strap telepítése (Soundhax) :::details Technikai részletek (opcionális) diff --git a/docs/installing-boot9strap-(soundhax).md b/docs/installing-boot9strap-(soundhax).md index b28573b9fe856..0fb2a6048072f 100644 --- a/docs/installing-boot9strap-(soundhax).md +++ b/docs/installing-boot9strap-(soundhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/soundhax-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # Installing boot9strap (Soundhax) ::: details Technical Details (optional) diff --git a/docs/installing-boot9strap-(super-skaterhax).md b/docs/installing-boot9strap-(super-skaterhax).md index 7a655b2eb0fb8..3ae564e24196a 100644 --- a/docs/installing-boot9strap-(super-skaterhax).md +++ b/docs/installing-boot9strap-(super-skaterhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/skater-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # Installing boot9strap (super-skaterhax) ::: details Technical Details (optional) diff --git a/docs/it_IT/get-started.md b/docs/it_IT/get-started.md index 60c1f62437570..a4f0f93251230 100644 --- a/docs/it_IT/get-started.md +++ b/docs/it_IT/get-started.md @@ -1,9 +1,10 @@ --- noneSelected: Il modello della console è richiesto. invalidVersion: Questa non sembra essere una versione di sistema valida. -head: - - - script - - src: /assets/js/selecting.js +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/selecting.js'}] +] --- # Cominciamo! diff --git a/docs/it_IT/installing-boot9strap-(soundhax).md b/docs/it_IT/installing-boot9strap-(soundhax).md index f04486a381db0..8cff88d778a13 100644 --- a/docs/it_IT/installing-boot9strap-(soundhax).md +++ b/docs/it_IT/installing-boot9strap-(soundhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/soundhax-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # Installazione di boot9strap (Soundhax) :::details Dettagli tecnici (opzionale) diff --git a/docs/ko_KR/get-started.md b/docs/ko_KR/get-started.md index 5c52d4e22c1bb..cbccb2a6b6880 100644 --- a/docs/ko_KR/get-started.md +++ b/docs/ko_KR/get-started.md @@ -1,9 +1,10 @@ --- noneSelected: 시스템 모델을 선택하세요. invalidVersion: 올바른 시스템 버전으로 확인되지 않습니다. -head: - - - script - - src: /assets/js/selecting.js +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/selecting.js'}] +] --- # 시작하기 diff --git a/docs/ko_KR/installing-boot9strap-(soundhax).md b/docs/ko_KR/installing-boot9strap-(soundhax).md index 45d0b40fd98ab..13acee52a95d3 100644 --- a/docs/ko_KR/installing-boot9strap-(soundhax).md +++ b/docs/ko_KR/installing-boot9strap-(soundhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/soundhax-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # boot9strap 설치 (Soundhax) :::details 기술적 상세 정보 (선택 사항) diff --git a/docs/pt_BR/get-started.md b/docs/pt_BR/get-started.md index f66e1aac4f517..276f961400cc6 100644 --- a/docs/pt_BR/get-started.md +++ b/docs/pt_BR/get-started.md @@ -1,9 +1,10 @@ --- noneSelected: Modelo do sistema é necessário. invalidVersion: Esta não parece ser uma versão válida de sistema. -head: - - - script - - src: /assets/js/selecting.js +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/selecting.js'}] +] --- # Começando diff --git a/docs/pt_BR/installing-boot9strap-(soundhax).md b/docs/pt_BR/installing-boot9strap-(soundhax).md index d212beae3dfdd..e67272e392651 100644 --- a/docs/pt_BR/installing-boot9strap-(soundhax).md +++ b/docs/pt_BR/installing-boot9strap-(soundhax).md @@ -1,3 +1,11 @@ +--- +head: [ + ['script', {src: '/assets/js/common.js'}], + ['script', {src: '/assets/js/soundhax-link.js'}], + ['script', {src: '/assets/js/link-common.js'}], +] +--- + # Instalando boot9strap (Soundhax) :::details Detalhes Técnicos (opcional) diff --git a/docs/public/assets/js/common.js b/docs/public/assets/js/common.js new file mode 100644 index 0000000000000..57825158308ac --- /dev/null +++ b/docs/public/assets/js/common.js @@ -0,0 +1,66 @@ +/* + Copyright (C) 2024 Nintendo Homebrew + + SPDX-License-Identifier: MIT +*/ + +(() => { + +// probably not really needed? +function c(key, value) { + Object.defineProperty(window, key, { value, writable: false, enumerable: true, configurable: false }); +} + +if (!window.COMMON_LOADED) { + c("COMMON_LOADED", true); + + // Possible max minor for each major, major as key + const major_minor_map = { + 0: -1, // invalidate all 0.x + 1: 1, + 2: 2, + 3: 1, + 4: 5, + 5: 1, + 6: 4, + 7: 2, + 8: 1, + 9: 9, + 10: 7, + 11: 17 + } + + // Validate version + // CHN/TWN doesn't have new model + // KOR/CHN/TWN doesn't have 11.17 currently + c("validate_version", (major, minor, native, region, model) => { + if (model == DEVICE_N3DS && ["C", "T"].includes(region)) { + return false; + } + + if (major == 11 && minor == 17 && ["K", "C", "T"].includes(region)) { + return false; + } + + const minor_max = major_minor_map[major]; + if (!isNaN(minor_max) && minor > minor_max) { + return false; + } + + return true; + }); + + c("DEVICE_N3DS", 1); + c("DEVICE_O3DS", 0); + + c("FILENAME_REGION_MAP", { + "U": "usa", + "E": "eur", + "J": "jpn", + "K": "kor", + "C": "cnh", + "T": "twn", + }); +} + +})(); diff --git a/docs/public/assets/js/link-common.js b/docs/public/assets/js/link-common.js new file mode 100644 index 0000000000000..898344573faf7 --- /dev/null +++ b/docs/public/assets/js/link-common.js @@ -0,0 +1,33 @@ +/* + Copyright (C) 2024 DannyAAM + + SPDX-License-Identifier: MIT +*/ + +(() => { + +const selectedVersion = sessionStorage.getItem("selected_version"); +if (selectedVersion && window.MATCH && window.generateLink) { + function replaceLink() { + const {major, minor, nver, region, model} = JSON.parse(selectedVersion); + if (!validate_version(major, minor, nver, region, model)) { + return; + } + + const links = document.querySelectorAll(`a[href*="${MATCH}"]`); + for(const link of links) { + const newLink = generateLink(major, minor, nver, region, model, link.href); + if (newLink) { + link.setAttribute("href", newLink); + } + } + } + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", replaceLink); + } else { + replaceLink(); + } +} + +})(); diff --git a/docs/public/assets/js/selecting.js b/docs/public/assets/js/selecting.js index 6d8d66409e6b9..6d0d5f76fe8ec 100644 --- a/docs/public/assets/js/selecting.js +++ b/docs/public/assets/js/selecting.js @@ -5,44 +5,11 @@ SPDX-License-Identifier: MIT */ -const DEVICE_N3DS = 1; -const DEVICE_O3DS = 0; - -// Possible max minor for each major, major as key -const major_minor_map = { - 0: -1, // invalidate all 0.x - 1: 1, - 2: 2, - 3: 1, - 4: 5, - 5: 1, - 6: 4, - 7: 2, - 8: 1, - 9: 9, - 10: 7, - 11: 17 -} - -// Validate version -// CHN/TWN doesn't have new model -// KOR/CHN/TWN doesn't have 11.17 currently -function validate_version(major, minor, native, region, model) { - if (model == DEVICE_N3DS && ["C", "T"].includes(region)) { - return false; - } +// required as vitepress don't always fully reload page +// without putting script in its own scope will have const redefine issue +(() => { - if (major == 11 && minor == 17 && ["K", "C", "T"].includes(region)) { - return false; - } - - const minor_max = major_minor_map[major]; - if (!isNaN(minor_max) && minor > minor_max) { - return false; - } - - return true; -} +// validate_version moved to common.js // Soundhax // 1.0-11.3 @@ -208,6 +175,9 @@ function redirect() { return; } + // Store selected version for some later pages + sessionStorage.setItem("selected_version", JSON.stringify({major, minor, nver, region, model})); + const redirected = [ can_soundhax, can_ssloth, @@ -221,3 +191,7 @@ function redirect() { document.getElementById("result_methodUnavailable").style.display = "block"; return false; } + +window.redirect = redirect; + +})(); diff --git a/docs/public/assets/js/skater-link.js b/docs/public/assets/js/skater-link.js new file mode 100644 index 0000000000000..05ece661f763d --- /dev/null +++ b/docs/public/assets/js/skater-link.js @@ -0,0 +1,43 @@ +/* + Copyright (C) 2024 DannyAAM + + SPDX-License-Identifier: MIT +*/ + +(() => { + +const BASE = "https://hacksguidewiki.sfo3.digitaloceanspaces.com/hacksguidewiki/Super-skaterhax"; + +window.MATCH = "skater.nintendohomebrew.com"; + +window.generateLink = (major, minor, nver, region, model, link) => { + const fileRegion = FILENAME_REGION_MAP[region]; + + if (model != DEVICE_N3DS || major < 11) { + return null; + } + + let fileVersion; + switch (region) { + case "U": + if (minor == 17) { + fileVersion = "v11.17"; + } else { + fileVersion = "pre17"; + } + break; + case "K": + if (minor == 17) { + return null; + } else { + fileVersion = "pre17"; + } + break; + default: + fileVersion = "all"; + break; + } + return `${BASE}-${fileRegion}-${fileVersion}.zip`; +} + +})(); diff --git a/docs/public/assets/js/soundhax-link.js b/docs/public/assets/js/soundhax-link.js new file mode 100644 index 0000000000000..5dd621add1435 --- /dev/null +++ b/docs/public/assets/js/soundhax-link.js @@ -0,0 +1,54 @@ +/* + Copyright (C) 2024 DannyAAM + + SPDX-License-Identifier: MIT +*/ + +(() => { + +const BASE = "https://github.com/nedwill/soundhax/raw/master/soundhax"; + +window.MATCH = "soundhax.com"; + +window.generateLink = (major, minor, nver, region, model, link) => { + const fileRegion = FILENAME_REGION_MAP[region]; + + if (model == DEVICE_N3DS) { + return `${BASE}-${fileRegion}-n3ds.m4a`; + } + + if (model == DEVICE_O3DS) { + if (major <= 2 && ["K", "C", "T"].includes(region)) { + return null; + } + + let fileVersion; + switch (parseInt(major)) { + case 1: + fileVersion = "pre2.1"; + break; + case 2: + // 2.1 special case: + // - if nver lower than 4, use pre 2.1, as sound app is not updated + // - otherwise, use 2.1/2.2 for newer soundhax app + if (minor == 1 && nver < 4) { + fileVersion = "pre2.1"; + } else { + fileVersion = "v2.1and2.2"; + } + break; + case 3: + case 4: + fileVersion = "v3.xand4.x"; + break; + default: // 5.x and later... maybe reject past 11.3? + fileVersion = "post5.0"; + break; + } + return `${BASE}-${fileRegion}-o3ds-${fileVersion}.m4a`; + } + + return null; // wtf? +} + +})();