Skip to content

Instantly share code, notes, and snippets.

@phoenixthrush
Last active August 13, 2025 01:58
Show Gist options
  • Select an option

  • Save phoenixthrush/deaee4ae3b7ec9de4c3bbef59ba8a75c to your computer and use it in GitHub Desktop.

Select an option

Save phoenixthrush/deaee4ae3b7ec9de4c3bbef59ba8a75c to your computer and use it in GitHub Desktop.
Sets a random Rule34 image of Albedo or Shalltear as your desktop wallpaper #Windows #Rule34 #Wallpaper
param()
function Get-RandomTag {
$tags = @('albedo_(overlord)','shalltear_bloodfallen')
Get-Random -InputObject $tags
}
function Get-RandomWallpaperUrl {
$tag = Get-RandomTag
$encodedTag = [System.Net.WebUtility]::UrlEncode($tag)
# https://rule34.xxx/index.php?page=help&topic=dapi
$apiUrl = "https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&tags=$encodedTag"
$response = Invoke-RestMethod -Uri $apiUrl -Method Get -ErrorAction Stop
if (-not $response.posts.post) {Throw "No posts found for tag $tag"}
$post = Get-Random -InputObject $response.posts.post
$post.file_url
}
function Set-Wallpaper {
param([string]$ImageUrl,[string]$OutputPath)
$dir = Split-Path -Parent $OutputPath
if (-not (Test-Path $dir)) {New-Item -ItemType Directory -Path $dir | Out-Null}
(New-Object System.Net.WebClient).DownloadFile($ImageUrl, $OutputPath)
$key = 'HKCU:\Control Panel\Desktop'
Set-ItemProperty -Path $key -Name WallpaperStyle -Value '6'
Set-ItemProperty -Path $key -Name TileWallpaper -Value '0'
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Wallpaper {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
"@
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa
$SPI_SETDESKWALLPAPER = 0x0014
$SPIF_UPDATEINIFILE = 0x01
$SPIF_SENDCHANGE = 0x02
$flags = $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE
[Wallpaper]::SystemParametersInfo($SPI_SETDESKWALLPAPER,0,$OutputPath,$flags) | Out-Null
}
function Main {
$outputPath = Join-Path $env:USERPROFILE 'Pictures\wallpaper.jpg'
$url = Get-RandomWallpaperUrl
Set-Wallpaper -ImageUrl $url -OutputPath $outputPath
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment