|
| 1 | +// Tab switching |
| 2 | +function initTabs() { |
| 3 | + const tabButtons = document.querySelectorAll('.tab-btn'); |
| 4 | + const tabPanels = document.querySelectorAll('.tab-panel'); |
| 5 | + |
| 6 | + tabButtons.forEach(function(btn) { |
| 7 | + btn.addEventListener('click', function() { |
| 8 | + var tabId = this.getAttribute('data-tab'); |
| 9 | + |
| 10 | + tabButtons.forEach(function(b) { b.classList.remove('active'); }); |
| 11 | + tabPanels.forEach(function(p) { p.classList.remove('active'); }); |
| 12 | + |
| 13 | + this.classList.add('active'); |
| 14 | + document.getElementById('tab-' + tabId).classList.add('active'); |
| 15 | + }); |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +// Fetch latest release information from GitHub |
| 20 | +async function fetchLatestRelease() { |
| 21 | + const GITHUB_API = 'https://api.github.com/repos/sanny32/OpenModSim/releases/latest'; |
| 22 | + |
| 23 | + try { |
| 24 | + console.log('Fetching latest release from GitHub...'); |
| 25 | + const response = await fetch(GITHUB_API); |
| 26 | + if (!response.ok) { |
| 27 | + throw new Error(`HTTP error! status: ${response.status}`); |
| 28 | + } |
| 29 | + |
| 30 | + const release = await response.json(); |
| 31 | + updateDownloadLinks(release); |
| 32 | + } catch (error) { |
| 33 | + console.error('Error fetching release:', error); |
| 34 | + console.warn('Download links will point to releases page instead of direct downloads'); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +function updateDownloadLinks(release) { |
| 39 | + const assets = release.assets; |
| 40 | + |
| 41 | + // Find specific file patterns |
| 42 | + const files = { |
| 43 | + winx64Qt6: assets.find(a => a.name.match(/qt6-omodsim-.*_x64\.exe$/i)), |
| 44 | + winx64Qt5: assets.find(a => a.name.match(/qt5-omodsim-.*_x64\.exe$/i)), |
| 45 | + winx86: assets.find(a => a.name.match(/qt5-omodsim-.*_x86\.exe$/i)), |
| 46 | + debQt6: assets.find(a => a.name.match(/qt6-omodsim_.*_amd64\.deb$/i)), |
| 47 | + debQt5: assets.find(a => a.name.match(/qt5-omodsim_.*_amd64\.deb$/i)), |
| 48 | + rpmQt6: assets.find(a => a.name.match(/qt6-omodsim-.*\.x86_64\.rpm$/i)), |
| 49 | + rpmPubkey: assets.find(a => a.name.match(/qt6-omodsim\.rpm\.pubkey$/i)), |
| 50 | + flatpak: assets.find(a => a.name.match(/io\.github\.sanny32\.omodsim.*\.flatpak$/i)) |
| 51 | + }; |
| 52 | + |
| 53 | + // Helper function to update link |
| 54 | + function updateLink(id, file, name) { |
| 55 | + const link = document.getElementById(id); |
| 56 | + if (link && file) { |
| 57 | + link.href = file.browser_download_url; |
| 58 | + } else if (link && !file) { |
| 59 | + console.warn(`✗ File not found for ${name}`); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + // Update all download links |
| 64 | + updateLink('win-x64-qt6-link', files.winx64Qt6, 'Windows x64 Qt6'); |
| 65 | + updateLink('win-x64-qt5-link', files.winx64Qt5, 'Windows x64 Qt5'); |
| 66 | + updateLink('win-x86-qt5-link', files.winx86, 'Windows x86 Qt5'); |
| 67 | + updateLink('deb-qt6-link', files.debQt6, 'DEB Qt6'); |
| 68 | + updateLink('deb-qt5-link', files.debQt5, 'DEB Qt5'); |
| 69 | + updateLink('rpm-qt6-link', files.rpmQt6, 'RPM Qt6'); |
| 70 | + updateLink('rpm-pubkey-link', files.rpmPubkey, 'RPM Public Key'); |
| 71 | + updateLink('flatpak-link', files.flatpak, 'Flatpak'); |
| 72 | + |
| 73 | + // Update all install commands with actual file names |
| 74 | + updateInstallCommands(files); |
| 75 | + |
| 76 | + // Update version display if available |
| 77 | + if (release.tag_name) { |
| 78 | + updateVersionDisplay(release.tag_name); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +function updateVersionDisplay(version) { |
| 83 | + // Update the download subtitle to include version |
| 84 | + const subtitle = document.querySelector('.download-subtitle'); |
| 85 | + if (subtitle) { |
| 86 | + subtitle.textContent = `Get the latest version (${version}) for your platform`; |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +function updateInstallCommands(files) { |
| 91 | + if (files.debQt5) { |
| 92 | + const debName = files.debQt5.name; |
| 93 | + document.querySelectorAll('.qt5-deb-package-name').forEach(el => { |
| 94 | + el.textContent = debName; |
| 95 | + }); |
| 96 | + } |
| 97 | + |
| 98 | + if (files.debQt6) { |
| 99 | + const debName = files.debQt6.name; |
| 100 | + document.querySelectorAll('.qt6-deb-package-name').forEach(el => { |
| 101 | + el.textContent = debName; |
| 102 | + }); |
| 103 | + } |
| 104 | + |
| 105 | + if (files.rpmQt6) { |
| 106 | + const rpmName = files.rpmQt6.name; |
| 107 | + document.querySelectorAll('.qt6-rpm-package-name').forEach(el => { |
| 108 | + el.textContent = rpmName; |
| 109 | + }); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +function initCopyButtons() { |
| 114 | + document.querySelectorAll('.install-instructions .code-block .copy-btn').forEach(btn => { |
| 115 | + btn.addEventListener('click', () => { |
| 116 | + const codeEl = btn.closest('.code-block').querySelector('code'); |
| 117 | + if (!codeEl) return; |
| 118 | + |
| 119 | + navigator.clipboard.writeText(codeEl.innerText.trim()).then(() => { |
| 120 | + btn.classList.add('copied'); |
| 121 | + btn.innerHTML = `<svg viewBox="0 0 16 16" fill="currentColor"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>`; |
| 122 | + |
| 123 | + setTimeout(() => { |
| 124 | + btn.classList.remove('copied'); |
| 125 | + btn.innerHTML = ` |
| 126 | + <svg viewBox="0 0 16 16" fill="currentColor"> |
| 127 | + <path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"/> |
| 128 | + <path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"/> |
| 129 | + </svg> |
| 130 | + `; |
| 131 | + }, 1500); |
| 132 | + }); |
| 133 | + }); |
| 134 | +}); |
| 135 | +} |
| 136 | + |
| 137 | + |
| 138 | +// Initialize when page loads |
| 139 | +document.addEventListener('DOMContentLoaded', function() { |
| 140 | + initTabs(); |
| 141 | + fetchLatestRelease(); |
| 142 | + initCopyButtons(); |
| 143 | +}); |
0 commit comments