I am slightly embarrassed to show this off and it is a bit of a Sh#tpost but…
I have been spending a lot of time on many complex dashboard/tools made with Universal Dashboard that I hope to show off soon, so I took a quick break to do something fun. In order to get more familiar with the basics of UDElements I created a goofy little meme dashboard.
When I found out “Meme APIs” are a thing I couldn’t help myself…
New-UDButton -Text "Get New Meme" -OnClick {
$NewRandomMeme = Get-RandomMeme
# Toast
Show-UDToast -Message "Now Loading: $($NewRandomMeme.name)"
# Set Image
Set-UDElement -Id "imgMeme" -Attributes @{
src = $NewRandomMeme.url
}
# Set Label
Set-UDElement -Id "lblMeme" -Content {$NewRandomMeme.name}
}
New-UDHtml -Markup "<br />"
New-UDElement -ID "lblMeme" -Tag "div" -Content {""}
New-UDElement -ID "imgMeme" -Tag "img" -Attributes @{src = ""}
And here is my quick “Get-RandomMeme” function that uses the imgflip.com API:
Function Get-RandomMeme
{
$Meme = Invoke-WebRequest -Uri 'https://api.imgflip.com/get_memes'
$Memes = ($Meme.Content | ConvertFrom-Json).data.memes
$RandomMeme =($Memes | Get-Random | Select-Object name, url, width, height, box_count)
return $RandomMeme
}
Hopefully, this will help beginners trying to use New-UDElement and Set-UDElement