Untitled
2 weeks ago in Powershell
Add-Type -AssemblyName System.Windows.Forms
function New-Rule {
param
(
[Parameter(Mandatory)]
$match_rule,
[Parameter(Mandatory)]
$replace_rule
)
return New-Object 'Tuple[String,String]' $match_rule, $replace_rule
}
$rules = @(
New-Rule '^https://twitter.com/(.+/status/.+)$' 'https://vxtwitter.com/$1'
)
$poll_time = 1000
$old_clipboard = ''
do {
Start-Sleep -Milliseconds $poll_time
if (![System.Windows.Forms.Clipboard]::ContainsText()) {
continue
}
$new_text = [System.Windows.Forms.Clipboard]::GetText()
Write-Host "$new_text $old_clipboard"
if ($new_text -eq $old_clipboard) {
continue
}
$matched = $false
foreach ($rule in $rules) {
Write-Host $rule
if ($new_text -match $rule.Item1) {
Write-Host "Matched"
$matched = $true
$new_text = $new_text -replace $rule.Item1, $rule.Item2
}
}
if ($matched) {
[System.Windows.Forms.Clipboard]::SetText($new_text)
}
$old_clipboard = $new_text
} while ($true)