[CmdletBinding()] param() $LauncherVersion = "v2026-04-24-04" $BaseUri = "https://files.dayv.se/work/pwsh/" # MUST end with / $UiWidth = 74 try { $ProgressPreference = "SilentlyContinue" } catch {} # Trim whitespace incl NBSP using operators that work in constrained language mode. function TrimX { param($s) if ($null -eq $s) { return "" } return ([string]$s) -replace '^[\s\xA0]+|[\s\xA0]+$', '' } function Write-Banner { param( [string]$Title, [string]$Kind # MENU, RUN, END, WARN, ERROR ) $k = TrimX $Kind if (-not $k) { $k = "MENU" } $borderColor = "DarkGray" $titleColor = "Gray" switch ($k) { "MENU" { $borderColor = "Cyan"; $titleColor = "Cyan" } "RUN" { $borderColor = "Green"; $titleColor = "Green" } "END" { $borderColor = "Green"; $titleColor = "Green" } "WARN" { $borderColor = "Yellow"; $titleColor = "Yellow" } "ERROR" { $borderColor = "Red"; $titleColor = "Red" } default { $borderColor = "DarkGray"; $titleColor = "Gray" } } $innerWidth = $UiWidth $text = TrimX $Title if ($text.Length -gt $innerWidth) { $text = $text -replace ("(?s)^(.{0," + $innerWidth + "}).*$"), '$1' } $fmt = "{0,-" + $innerWidth + "}" $line = "╭" + ("─" * $innerWidth) + "╮" $mid = "│" + ($fmt -f $text) + "│" $bot = "╰" + ("─" * $innerWidth) + "╯" Write-Host "" Write-Host $line -ForegroundColor $borderColor Write-Host $mid -ForegroundColor $titleColor Write-Host $bot -ForegroundColor $borderColor } function Write-Box { param( [string[]]$Lines, [string]$Kind # MENU, RUN, END, WARN, ERROR ) $k = TrimX $Kind if (-not $k) { $k = "MENU" } $borderColor = "DarkGray" $textColor = "Gray" switch ($k) { "MENU" { $borderColor = "Cyan"; $textColor = "Cyan" } "RUN" { $borderColor = "Green"; $textColor = "Green" } "END" { $borderColor = "Green"; $textColor = "Green" } "WARN" { $borderColor = "Yellow"; $textColor = "Yellow" } "ERROR" { $borderColor = "Red"; $textColor = "Red" } default { $borderColor = "DarkGray"; $textColor = "Gray" } } $arr = @($Lines) if ($arr.Length -le 0) { $arr = @("") } $width = $UiWidth $top = "╭" + ("─" * $width) + "╮" $sep = "├" + ("─" * $width) + "┤" $bot = "╰" + ("─" * $width) + "╯" Write-Host $top -ForegroundColor $borderColor for ($i = 0; $i -lt $arr.Length; $i++) { $t = [string]$arr[$i] if ($t -eq "__SEP__") { Write-Host $sep -ForegroundColor $borderColor continue } if ($t.Length -gt $width) { $t = $t -replace ("(?s)^(.{0," + $width + "}).*$"), '$1' } $fmt = "{0,-" + $width + "}" $pad = $fmt -f $t Write-Host "│" -ForegroundColor $borderColor -NoNewline Write-Host $pad -ForegroundColor $textColor -NoNewline Write-Host "│" -ForegroundColor $borderColor } Write-Host $bot -ForegroundColor $borderColor } function Get-ListingHtml { param($Uri) $headers = @{ "User-Agent" = "Mozilla/5.0" "Accept" = "text/html,*/*" "Cache-Control" = "no-cache" "Pragma" = "no-cache" } try { return [string](Invoke-WebRequest -UseBasicParsing -Uri $Uri -Headers $headers -Method Get -ErrorAction Stop).Content } catch { return [string](Invoke-WebRequest -Uri $Uri -Headers $headers -Method Get -ErrorAction Stop).Content } } function Normalize-Name { param($Name) $n = TrimX $Name if (-not $n) { return $null } if ($n -match '^(?

[^#?]+)') { $n = $Matches.p } $n = (TrimX $n) -replace '/+$', '' if (-not $n) { return $null } if ($n -eq "." -or $n -eq ".." -or $n -eq "../") { return $null } if ($n -match '[\\/]' ) { return $null } if ($n -notmatch '^[a-zA-Z0-9._-]+$') { return $null } return $n } function Get-ScriptsFromHtml { param($Html) $names = @() $hrefMatches = Select-String -InputObject ([string]$Html) -Pattern '(?is)href\s*=\s*["'']([^"''#?]+)["'']' -AllMatches foreach ($m in @($hrefMatches.Matches)) { $norm = Normalize-Name $m.Groups[1].Value if ($norm) { $names += [string]$norm } } # Dedupe (case-insensitive) + sort $seen = @{} $out = @() foreach ($n in $names) { $k = [string]$n if (-not $seen[$k]) { $seen[$k] = $true $out += [string]$n } } return ($out | Sort-Object) } while ($true) { $html = $null try { $html = Get-ListingHtml -Uri $BaseUri } catch { Write-Banner -Title "ERROR: Failed to download listing" -Kind "ERROR" Write-Host $_ -ForegroundColor Red break } $scripts = @(Get-ScriptsFromHtml -Html $html) | Where-Object { $_ -and (TrimX $_) } $scripts = @($scripts) if ($scripts.Length -le 0) { Write-Banner -Title "WARN: No scripts found" -Kind "WARN" break } # ---- Boxed MENU ---- Write-Host "" Write-Banner -Title "MENU" -Kind "MENU" $menuLines = @() $menuLines += (" Launcher {0}" -f $LauncherVersion) $menuLines += (" Source {0}" -f $BaseUri) $menuLines += "__SEP__" $menuLines += ("") $menuLines += (" Available scripts") for ($i = 0; $i -lt $scripts.Length; $i++) { $menuLines += (" {0,2}. {1}" -f ($i + 1), $scripts[$i]) } $menuLines += ("") $menuLines += "__SEP__" $menuLines += " Pick number or name r = refresh q = quit" Write-Box -Lines $menuLines -Kind "MENU" $choiceRaw = Read-Host "Run" $choice = TrimX $choiceRaw if (-not $choice) { continue } if ($choice -ieq "q") { break } if ($choice -ieq "r") { continue } # Selection logic inline $picked = $null if ($choice -match '^\d+$') { try { $num = [int]$choice if ($num -ge 1 -and $num -le $scripts.Length) { $picked = [string]$scripts[$num - 1] } } catch { } } else { for ($i = 0; $i -lt $scripts.Length; $i++) { $nm = [string]$scripts[$i] if ($nm -and ($nm -ieq $choice)) { $picked = $nm; break } } if ((-not $picked) -and ($choice -match '^[a-zA-Z0-9._-]+$')) { $hits = @() for ($i = 0; $i -lt $scripts.Length; $i++) { $nm = [string]$scripts[$i] if ($nm -and ($nm -ilike "$choice*")) { $hits += $nm } } if (@($hits).Length -eq 1) { $picked = [string]$hits[0] } } } if (-not $picked) { Write-Banner -Title ("WARN: Invalid selection '{0}'" -f [string]$choiceRaw) -Kind "WARN" continue } if ($picked -notmatch '^[a-zA-Z0-9._-]+$') { Write-Banner -Title ("ERROR: Blocked unsafe name '{0}'" -f $picked) -Kind "ERROR" continue } $scriptUri = $BaseUri + $picked Write-Banner -Title ("RUN: {0}" -f $picked) -Kind "RUN" Write-Host ("URL: {0}" -f $scriptUri) -ForegroundColor DarkGray Write-Host "" try { Invoke-Expression (Invoke-RestMethod -Uri $scriptUri -Method Get -ErrorAction Stop) } catch { Write-Banner -Title ("ERROR running {0}" -f $picked) -Kind "ERROR" Write-Host $_ -ForegroundColor Red } Write-Banner -Title ("END: {0}" -f $picked) -Kind "END" Write-Host "Done. (q=quit, r=refresh, or pick another)" -ForegroundColor DarkGray }