-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying to gh-pages from @ 8730300 🚀
- Loading branch information
Showing
36 changed files
with
128 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
function onload(event) { | ||
if (window.location.pathname.endsWith("/INSTALLATION.html")) { | ||
enhance_install_page(); | ||
} | ||
} | ||
|
||
function enhance_install_page() { | ||
function retrieve_downloads(target_platform_re) { | ||
var downloads = []; | ||
for (const table of document.querySelectorAll("table")) { | ||
const th = document.querySelector("th"); | ||
if (th) { | ||
if (/Platform/i.test(th.innerText)) { | ||
for (const table_row of table.querySelectorAll("tr")) { | ||
const table_cols = table_row.querySelectorAll("td"); | ||
if (table_cols.length > 1) { | ||
const link = table_cols[1].querySelector("a"); | ||
if (link) { | ||
const platform = table_cols[0].innerText; | ||
if (target_platform_re.test(platform)) | ||
downloads.push([platform, link.innerText, link.href]); | ||
} | ||
} | ||
} | ||
break; // stop after first relevant table | ||
} | ||
} | ||
} | ||
return downloads; | ||
} | ||
|
||
/* check OS: first check for `?os=foo` in the URL, otherwise guess form user agent */ | ||
const params = new URLSearchParams(window.location.search); | ||
const current_os = params.get("os") || guess_client_OS(); | ||
|
||
if (current_os == null) return; | ||
|
||
/* find download links matching the OS */ | ||
const target_platform_re = RegExp(`(${current_os})`, "i"); | ||
const downloads = retrieve_downloads(target_platform_re); | ||
|
||
if (downloads.length < 1) return; | ||
|
||
/* create a box below the first header to insert buttons */ | ||
const header = document.querySelector("h1"); | ||
if (header == null) return; | ||
const div = document.createElement("div"); | ||
div.setAttribute("class", "install-buttons"); | ||
header.parentNode.insertBefore(div, header.nextSibling); | ||
|
||
/* create download button for each matching link */ | ||
var i = 0; | ||
for ([platform, filename, url] of downloads) { | ||
const bolded_platform = platform.replace(target_platform_re, "<b>$1</b>"); | ||
const link = document.createElement("a"); | ||
link.setAttribute("href", url); | ||
link.setAttribute("class", i++ ? "btn" : "btn btn-primary"); | ||
link.innerHTML = `<div>Get <b>F3D</b> for ${bolded_platform}</div><small>${filename}</small>`; | ||
div.append(link); | ||
} | ||
const note = document.createElement("div"); | ||
note.innerHTML = "<small>or see other available versions below</small>"; | ||
div.append(note); | ||
} | ||
|
||
function guess_client_OS() { | ||
/* https://stackoverflow.com/a/38241481 */ | ||
const userAgent = window.navigator.userAgent; | ||
const platform = | ||
window.navigator?.userAgentData?.platform || window.navigator.platform; | ||
const macosPlatforms = ["macOS", "Macintosh", "MacIntel", "MacPPC", "Mac68K"]; | ||
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"]; | ||
const iosPlatforms = ["iPhone", "iPad", "iPod"]; | ||
|
||
if (macosPlatforms.indexOf(platform) !== -1) { | ||
return "MacOS"; | ||
} else if (iosPlatforms.indexOf(platform) !== -1) { | ||
return "iOS"; | ||
} else if (windowsPlatforms.indexOf(platform) !== -1) { | ||
return "Windows"; | ||
} else if (/Android/.test(userAgent)) { | ||
return "Android"; | ||
} else if (/Linux/.test(platform)) { | ||
return "Linux"; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
window.addEventListener("load", onload); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.