From 2c1031865f0811683ad2fdc827309c1c321c720a Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Sun, 14 Jul 2024 18:50:40 -0500 Subject: [PATCH] Sponsors Easter Egg --- functions/private/Invoke-WinUtilSponsors.ps1 | 45 ++++++++++++++++++++ functions/private/Show-CustomDialog.ps1 | 23 +++++++--- scripts/main.ps1 | 27 ++++++++++++ xaml/inputXML.xaml | 1 + 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 functions/private/Invoke-WinUtilSponsors.ps1 diff --git a/functions/private/Invoke-WinUtilSponsors.ps1 b/functions/private/Invoke-WinUtilSponsors.ps1 new file mode 100644 index 00000000..cf75dc27 --- /dev/null +++ b/functions/private/Invoke-WinUtilSponsors.ps1 @@ -0,0 +1,45 @@ +Function Invoke-WinUtilSponsors { + <# + .SYNOPSIS + Lists Sponsors from ChrisTitusTech + .DESCRIPTION + Lists Sponsors from ChrisTitusTech + .EXAMPLE + Invoke-WinUtilSponsors + .NOTES + This function is used to list sponsors from ChrisTitusTech + #> + try { + # Define the URL and headers + $url = "https://github.com/sponsors/ChrisTitusTech" + $headers = @{ + "User-Agent" = "Chrome/58.0.3029.110" + } + + # Fetch the webpage content + try { + $html = Invoke-RestMethod -Uri $url -Headers $headers + } catch { + Write-Output $_.Exception.Message + exit + } + + # Use regex to extract the content between "Current sponsors" and "Past sponsors" + $currentSponsorsPattern = '(?s)(?<=Current sponsors).*?(?=Past sponsors)' + $currentSponsorsHtml = [regex]::Match($html, $currentSponsorsPattern).Value + + # Use regex to extract the sponsor usernames from the alt attributes in the "Current Sponsors" section + $sponsorPattern = '(?<=alt="@)[^"]+' + $sponsors = [regex]::Matches($currentSponsorsHtml, $sponsorPattern) | ForEach-Object { $_.Value } + + # Exclude "ChrisTitusTech" from the sponsors + $sponsors = $sponsors | Where-Object { $_ -ne "ChrisTitusTech" } + + # Return the sponsors + return $sponsors + } + catch { + Write-Error "An error occurred while fetching or processing the sponsors: $_" + return $null + } +} \ No newline at end of file diff --git a/functions/private/Show-CustomDialog.ps1 b/functions/private/Show-CustomDialog.ps1 index dc6eb0de..236a3d62 100644 --- a/functions/private/Show-CustomDialog.ps1 +++ b/functions/private/Show-CustomDialog.ps1 @@ -24,6 +24,9 @@ function Show-CustomDialog { .PARAMETER IconSize The Size to use for Icon inside the custom dialog window. + .PARAMETER EnableScroll + A flag indicating whether to enable scrolling if the content exceeds the window size. + .EXAMPLE Show-CustomDialog -Message "This is a custom dialog with a message and an image above." -Width 300 -Height 200 @@ -34,7 +37,8 @@ function Show-CustomDialog { [int]$Height = 200, [int]$FontSize = 10, [int]$HeaderFontSize = 14, - [int]$IconSize = 25 + [int]$IconSize = 25, + [bool]$EnableScroll = $false ) Add-Type -AssemblyName PresentationFramework @@ -246,11 +250,18 @@ $cttLogoPath = @" $messageTextBlock.Inlines.Add((New-Object Windows.Documents.Run($Message))) } - - # Add the TextBlock to the Grid - $grid.Children.Add($messageTextBlock) - [Windows.Controls.Grid]::SetRow($messageTextBlock, 1) # Set the row to the second row (0-based index) - + # Create a ScrollViewer if EnableScroll is true + if ($EnableScroll) { + $scrollViewer = New-Object System.Windows.Controls.ScrollViewer + $scrollViewer.VerticalScrollBarVisibility = 'Auto' + $scrollViewer.HorizontalScrollBarVisibility = 'Disabled' + $scrollViewer.Content = $messageTextBlock + $grid.Children.Add($scrollViewer) + [Windows.Controls.Grid]::SetRow($scrollViewer, 1) # Set the row to the second row (0-based index) + } else { + $grid.Children.Add($messageTextBlock) + [Windows.Controls.Grid]::SetRow($messageTextBlock, 1) # Set the row to the second row (0-based index) + } # Add OK button $okButton = New-Object Windows.Controls.Button diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e17b7225..0c83c54c 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -505,5 +505,32 @@ Version : Current sponsors for ChrisTitusTech: +"@ + $authorInfo += "`n" + try { + # Call the function to get the sponsors + $sponsors = Invoke-WinUtilSponsors + + # Append the sponsors to the authorInfo + $sponsors | ForEach-Object { $authorInfo += "$_`n" } + } + catch { + $authorInfo += "An error occurred while fetching or processing the sponsors: $_`n" + } + + $FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize + $HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader + $IconSize = $sync.configs.themes.$ctttheme.CustomDialogIconSize + $Width = $sync.configs.themes.$ctttheme.CustomDialogWidth + $Height = $sync.configs.themes.$ctttheme.CustomDialogHeight + Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize -EnableScroll $true +}) $sync["Form"].ShowDialog() | out-null Stop-Transcript diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml index 4648924f..3c0eaf8f 100644 --- a/xaml/inputXML.xaml +++ b/xaml/inputXML.xaml @@ -697,6 +697,7 @@ +