From b8a45de02763a2dcce6e2ca0a436a9e6993d1ee4 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sat, 23 Jan 2021 00:30:57 -0600 Subject: [PATCH] Save tab to URL --- assets/js/tabs.js | 36 ++++++++++++++++--------- pages/_en-US/ds-index/3ds-forwarders.md | 4 +-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/assets/js/tabs.js b/assets/js/tabs.js index ac906474..2931c558 100644 --- a/assets/js/tabs.js +++ b/assets/js/tabs.js @@ -1,18 +1,24 @@ -function openTab(event, tabName) { - for(let element of event.currentTarget.parentNode.parentNode.children) { +function openTab(event, target) { + for(let element of target.parentNode.parentNode.children) { if (element.id.includes("tab")) { element.style.display = "none"; } } - for(let element of event.currentTarget.parentNode.children) { + for(let element of target.parentNode.children) { element.classList.remove("btn-secondary"); element.classList.add("btn-outline-secondary"); } - document.getElementById(tabName).style.display = "block"; - event.currentTarget.classList.remove("btn-outline-secondary"); - event.currentTarget.classList.add("btn-secondary"); + document.getElementById(`tab-${target.dataset.tabName}`).style.display = "block"; + target.classList.remove("btn-outline-secondary"); + target.classList.add("btn-secondary"); + + if(event) { + let url = new URL(window.location); + url.searchParams.set("tab", target.dataset.tabName); + history.pushState({}, "", url); + } } // Remove links from tab buttons @@ -22,30 +28,36 @@ for(a of document.getElementsByClassName("tab-link")) { // Open the tabs for the current OS or the default for(let tabGroup of document.getElementsByClassName("tab-container")) { + let tab = new URL(window.location).searchParams.get("tab"); + if(tab) { + openTab(null, Array.from(tabGroup.children[0].children).filter(r => r.dataset.tabName ==tab)[0]); + break; + } + for(let tab of tabGroup.children[0].children) { if(tabGroup.classList.contains("tab-os")) { if(navigator.platform.includes("Win")) { if(tab.classList.contains("tab-windows")) { - tab.click(); + openTab(null, tab); break; } else if(tab.classList.contains("other")) { - tab.click(); + openTab(null, tab); } } else if(navigator.platform.includes("Mac")) { if(tab.classList.contains("tab-macos")) { - tab.click(); + openTab(null, tab); break; } else if(tab.classList.contains("other")) { - tab.click(); + openTab(null, tab); } } else { if(tab.classList.contains("tab-other")) { - tab.click(); + openTab(null, tab); break; } } } else if(tab.classList.contains("tab-default")) { - tab.click(); + openTab(null, tab); break; } } diff --git a/pages/_en-US/ds-index/3ds-forwarders.md b/pages/_en-US/ds-index/3ds-forwarders.md index 90be4008..bd63352f 100644 --- a/pages/_en-US/ds-index/3ds-forwarders.md +++ b/pages/_en-US/ds-index/3ds-forwarders.md @@ -106,8 +106,8 @@ After you extract the pack for your card, you can edit `sd:/_nds/ntr_forwarder.i