|
16 | 16 | <body> |
17 | 17 |
|
18 | 18 | <h2>Loading Repository…</h2> |
| 19 | + |
19 | 20 | <script> |
20 | | -const params = new URLSearchParams(window.location.search); |
21 | | -let repo_name = params.get("index") || "mercwar"; |
| 21 | +// ----------------------------------------- |
| 22 | +// 1. DETECT THIS FILE'S REPO NAME |
| 23 | +// ----------------------------------------- |
| 24 | +const path = window.location.pathname.split("/").filter(Boolean); |
| 25 | + |
| 26 | +// Example paths: |
| 27 | +// /Mercwar/index.html → repo = Mercwar |
| 28 | +// /Constellation/index.html → repo = Constellation |
| 29 | +// ../../Mercwar/index.html → repo = Mercwar |
| 30 | + |
| 31 | +// Repo name is ALWAYS the folder BEFORE this file |
| 32 | +const repo_name = path[path.length - 2] || "mercwar"; |
22 | 33 |
|
23 | | -const LOCAL_MODE = true; // toggle this |
| 34 | +// ----------------------------------------- |
| 35 | +// 2. LOCAL MODE SWITCH |
| 36 | +// ----------------------------------------- |
| 37 | +const LOCAL_MODE = false; |
24 | 38 |
|
25 | 39 | let git_url = LOCAL_MODE |
26 | 40 | ? "../../" |
27 | 41 | : "https://mercwar.github.io/"; |
28 | 42 |
|
29 | | -// Clean join to avoid double slashes |
| 43 | +// ----------------------------------------- |
| 44 | +// 3. CLEAN URL JOINER (NO DOUBLE SLASHES) |
| 45 | +// ----------------------------------------- |
30 | 46 | function joinURL(base, path) { |
31 | 47 | return base.replace(/\/+$/, "") + "/" + path.replace(/^\/+/, ""); |
32 | 48 | } |
33 | 49 |
|
| 50 | +// ----------------------------------------- |
| 51 | +// 4. BUILD FINAL REDIRECT URL |
34 | 52 | // LIVE is ALWAYS inside Constellation |
35 | | -const clean_url = joinURL(git_url, "Constellation/LIVE/index.html") + `?index=${repo_name}`; |
36 | | - |
37 | | -// GitHub API URL for repo existence check |
38 | | -const apiURL = `https://api.github.com/repos/mercwar/${repo_name}`; |
39 | | - |
40 | | -// Check repo existence BEFORE redirecting |
41 | | -fetch(apiURL) |
42 | | - .then(res => { |
43 | | - if (res.ok || LOCAL_MODE) { |
44 | | - window.location.href = clean_url; |
45 | | - } else { |
46 | | - document.body.innerHTML = |
47 | | - `<h2 style="color:red;">Repository '${repo_name}' not found.</h2>`; |
48 | | - } |
49 | | - }) |
50 | | - .catch(err => { |
51 | | - document.body.innerHTML = |
52 | | - `<h2 style="color:red;">GitHub API error.</h2>`; |
53 | | - }); |
54 | | -</script> |
| 53 | +// ----------------------------------------- |
| 54 | +const clean_url = |
| 55 | + joinURL(git_url, "Constellation/LIVE/index.html") + |
| 56 | + `?index=${repo_name}`; |
55 | 57 |
|
| 58 | +// ----------------------------------------- |
| 59 | +// 5. REDIRECT |
| 60 | +// ----------------------------------------- |
| 61 | +window.location.href = clean_url; |
56 | 62 | </script> |
57 | 63 |
|
58 | 64 | </body> |
|
0 commit comments