Skip to content

Commit b9a25bd

Browse files
authored
Add files via upload
1 parent 710f8b8 commit b9a25bd

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

index.html

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,49 @@
1616
<body>
1717

1818
<h2>Loading Repository…</h2>
19+
1920
<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";
2233

23-
const LOCAL_MODE = true; // toggle this
34+
// -----------------------------------------
35+
// 2. LOCAL MODE SWITCH
36+
// -----------------------------------------
37+
const LOCAL_MODE = false;
2438

2539
let git_url = LOCAL_MODE
2640
? "../../"
2741
: "https://mercwar.github.io/";
2842

29-
// Clean join to avoid double slashes
43+
// -----------------------------------------
44+
// 3. CLEAN URL JOINER (NO DOUBLE SLASHES)
45+
// -----------------------------------------
3046
function joinURL(base, path) {
3147
return base.replace(/\/+$/, "") + "/" + path.replace(/^\/+/, "");
3248
}
3349

50+
// -----------------------------------------
51+
// 4. BUILD FINAL REDIRECT URL
3452
// 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}`;
5557

58+
// -----------------------------------------
59+
// 5. REDIRECT
60+
// -----------------------------------------
61+
window.location.href = clean_url;
5662
</script>
5763

5864
</body>

0 commit comments

Comments
 (0)