Created
July 12, 2023 11:14
-
-
Save ohaiibuzzle/bc0e15bfd4e6fc8abd9c06c7126c124d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$TargetUrl = "https://pixiv.net/ranking.php?mode=daily&content=illust&p=" | |
$Pages = 4 | |
Add-Type -TypeDefinition @' | |
using System.Runtime.InteropServices; | |
public class Wallpaper { | |
public const uint SPI_SETDESKWALLPAPER = 0x0014; | |
public const uint SPIF_UPDATEINIFILE = 0x01; | |
public const uint SPIF_SENDWININICHANGE = 0x02; | |
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
private static extern int SystemParametersInfo (uint uAction, uint uParam, string lpvParam, uint fuWinIni); | |
public static void SetWallpaper (string path) { | |
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); | |
} | |
} | |
'@ | |
$UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4464.5 Safari/537.36" | |
function Get-Works() { | |
$Works = [System.Collections.ArrayList]@() | |
$Headers = @{ | |
"User-Agent" = $UserAgent | |
} | |
for ($i = 1; $i -le $Pages; $i++) { | |
$Url = $TargetUrl + $i | |
$Html = Invoke-WebRequest $Url -Headers $Headers | |
$Html.ParsedHtml.getElementsByClassName("work _work ") | ForEach-Object { | |
$_.attributes | ForEach-Object { | |
if ($_.name -eq "href") { | |
$Works.Add($_.value) | Out-Null | |
} | |
} | |
} | |
} | |
$ReturnWorks = [System.Collections.ArrayList]@() | |
$Works | ForEach-Object { | |
# Get the last element separated by `/` | |
$Id = $_.Split("/")[-1] | |
$Url = "https://pixiv.cat/" + $Id + ".png" | |
$ReturnWorks.Add($Url) | Out-Null | |
} | |
return $ReturnWorks | |
} | |
function Get-WorkFile($Url, $FileName = "wallpaper.png") { | |
$Headers = @{ | |
"User-Agent" = $UserAgent | |
} | |
Invoke-WebRequest $Url -Headers $Headers -OutFile $FileName | |
return $FileName | |
} | |
function Set-Wallpaper($Path) { | |
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value 6 -Force | Out-Null | |
[Wallpaper]::SetWallpaper($Path) | |
} | |
$Works = Get-Works | |
$Work = $Works | Get-Random | |
$FileName = Get-WorkFile $Work | |
$FullPath = (Get-Item -Path ".\$FileName").FullName | |
Set-Wallpaper $FullPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment