XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
param([string]$ReferenceFile)
$ErrorActionPreference = 'Stop'
$newsRoot = Join-Path (Split-Path -Parent $PSScriptRoot) 'XFEEDToolBox\Assets\Galnet'
New-Item -ItemType Directory -Path (Join-Path $newsRoot 'fonts') -Force | Out-Null
$source = 'https://www.elitedangerous.com/news/galnet/faulcon-delacy-plans-anaconda-mk-ii-field-trials'
$html = if ($ReferenceFile) { Get-Content -LiteralPath $ReferenceFile -Raw } else { (Invoke-WebRequest -Uri $source -TimeoutSec 40).Content }
$entry = [regex]::Match($html, '<link rel="stylesheet" href="([^" ]*entry\.[^" ]+\.css)"').Groups[1].Value
if (!$entry) { throw 'Official global stylesheet was not found.' }
$entryUri = [uri]::new([uri]$source, $entry)
$css = (Invoke-WebRequest -Uri $entryUri -TimeoutSec 30).Content
$article = [regex]::Matches($html, '<style[^>]*>([\s\S]*?)</style>') | Where-Object { $_.Groups[1].Value.Contains('.v-news-galnet-article[') } | Select-Object -First 1
if (!$article) { throw 'Official Galnet article stylesheet was not found.' }
$articleCss = [regex]::Replace($article.Groups[1].Value, '\[data-v-[a-f0-9]+\]', '[data-galnet]')
$meta = [regex]::Match($html, '<div class="v-news-galnet-article__meta"[\s\S]*?</div>').Value
$logo = [Net.WebUtility]::HtmlDecode([regex]::Match($meta, '<img src="(data:image/svg\+xml,[^"]+)"').Groups[1].Value)
if (!$logo) { throw 'Official Galnet logo was not found.' }
Set-Content -LiteralPath (Join-Path $newsRoot 'logo.svg') -Value ([uri]::UnescapeDataString($logo.Substring($logo.IndexOf(',') + 1))) -Encoding utf8
$css = [regex]::Replace($css, 'url\(([^)]+)\)', { param($match)
    $url = $match.Groups[1].Value.Trim('"', "'")
    if ($url.StartsWith('data:')) { return $match.Value }
    'url("' + [uri]::new($entryUri, $url).AbsoluteUri + '")'
})
foreach ($font in @(@{Name='century-gothic'; Pattern='Century Gothic ';}, @{Name='montserrat'; Pattern='Montserrat';})) {
    $face = [regex]::Matches($css, '@font-face\{[^}]+\}') | Where-Object { $_.Value.Contains('font-family:' + $(if ($font.Pattern.Contains(' ')) {'"'+$font.Pattern+'"'} else {$font.Pattern}) + ';') -and $_.Value.Contains('font-style:normal') } | Select-Object -First 1
    $url = [regex]::Match($face.Value, 'url\("(https:[^"]+\.woff2)"\)').Groups[1].Value
    if (!$url) { throw ('Official font was not found: ' + $font.Name) }
    Invoke-WebRequest -Uri $url -OutFile (Join-Path $newsRoot ('fonts\' + $font.Name + '.woff2')) -TimeoutSec 30
    $css = $css.Replace($url, 'fonts/' + $font.Name + '.woff2')
}
$space = [regex]::Match($css, 'url\("(https:[^"]*space\.[^"]+\.png)"\)').Groups[1].Value
if (!$space) { throw 'Official starfield background was not found.' }
Invoke-WebRequest -Uri $space -OutFile (Join-Path $newsRoot 'space.png') -TimeoutSec 30
$css = $css.Replace($space, 'space.png')
$notice = "/* Frontier Elite Dangerous official site CSS. Retrieved 2026-10-23. Source: $source . Only asset URLs and Vue scope attribute names are adapted for the local reader. */`n"
Set-Content -LiteralPath (Join-Path $newsRoot 'official.css') -Value ($notice + $css + "`n" + $articleCss) -Encoding utf8
[pscustomobject]@{Stylesheet=$entryUri.AbsoluteUri; ArticleCssBytes=$articleCss.Length; Destination=$newsRoot} | ConvertTo-Json