mirror of
https://github.com/rvtr/wiki.git
synced 2025-10-31 06:31:13 -04:00
- They now work as tabs without JS - Use an include for cleaner markdown - A little bit nicer code overall, annoying that the split is needed, but otherwise pretty nice now
33 lines
834 B
JavaScript
33 lines
834 B
JavaScript
const platforms = {
|
|
"Win32": "tab-windows",
|
|
"MacIntel": "tab-macos"
|
|
};
|
|
|
|
function setTab(tab) {
|
|
let url = new URL(window.location);
|
|
url.searchParams.set("tab", tab);
|
|
history.pushState({}, "", url);
|
|
}
|
|
|
|
// Open the tabs for the current OS or the one in the URL
|
|
for(let tabGroup of document.getElementsByClassName("tab-container")) {
|
|
let tab = null;
|
|
|
|
// Try get tab from URL
|
|
let urlTab = new URL(window.location).searchParams.get("tab");
|
|
if(urlTab)
|
|
tab = Array.from(tabGroup.children).filter(r => r.id == `tab-${urlTab}`)[0];
|
|
|
|
// Try get tab for OS
|
|
if(!tab)
|
|
tab = Array.from(tabGroup.children).filter(r => r.id == platforms[navigator.platform])[0];
|
|
|
|
// Fall back to "other" tab
|
|
if(!tab)
|
|
tab = Array.from(tabGroup.children).filter(r => r.id == "tab-other")[0];
|
|
|
|
// If a tab was found, open it
|
|
if(tab)
|
|
tab.click();
|
|
}
|