返回列表 发帖
本帖最后由 went 于 2022-4-6 19:43 编辑
#&cls&cd /d "%~dp0"&@powershell -sta -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
cls
#挖空函数
function Hide-Src($num1,$num2,[System.IO.FileInfo]$srt){
    $arr = Get-Content $srt.FullName
    if($arr.Count -lt 4){ return $null }
    $txt = $arr | Select-Object -First 3 | Select-Object -Skip 2
    #正则
    $r = [regex]::new('(?<=>[^<]*)[a-zA-Z](?=[^<]*<)')
    #所有字母个数
    $char_len = $txt.Length - $r.Replace($txt,'').Length
    if($char_len -lt $num2){ return $null }
    #随机位置挖空
    $char_del = $char_len/$num2*$num1
    $r.Matches($txt) | Sort-Object { return Get-Random } | Select-Object -First $char_del | foreach {
        $txt = $txt.SubString(0,$_.Index) + '_' + $txt.SubString($_.Index+1,$txt.Length-$_.Index-1)
    }
    return &{
        '{0}\{1}[{2}分之{3}挖空].srt' -f $srt.Directory.FullName,$srt.BaseName,$num1,$num2
        $arr[0..1]
        $txt
        $arr[3..($arr.Count-1)]
    }
}
$msg = @'
1.全部所有的字母挖空请按1
2.五分之四的字母挖空请按2
3.四分之三的字母挖空请按3
4.三分之二的字母挖空请按4
5.二分之一的字母挖空请按5
6.三分之一的字母挖空请按6
7.四分之一的字母挖空请按7
8.五分之一的字母挖空请按8
请输入
'@
#主循环
while($true){
$a = $b = 0
$chs = Read-Host -Prompt $msg
switch($chs){
'1' { $a=1; $b=1 }
'2' { $a=4; $b=5 }
'3' { $a=3; $b=4 }
'4' { $a=2; $b=3 }
'5' { $a=1; $b=2 }
'6' { $a=1; $b=3 }
'7' { $a=1; $b=4 }
'8' { $a=1; $b=5 }
}
if($a -ne 0 -and $b -ne 0){
Get-ChildItem -Recurse '*.srt' | foreach {
if($_.BaseName -notmatch '\[.*?\]'){
Write-Host $_.FullName
$res = Hide-Src -num1 $a -num2 $b -srt $_
if($res -ne $null){
$res[1..($res.Count-1)] | Out-File -LiteralPath $res[0]
Write-Host $res[0]
}
'-------------------'
}
}
} else { Write-Host '输入无效' }
Write-Host "`r`n按任意键回到主菜单"
[void][System.Console]::ReadKey();cls
}COPY
1

评分人数

    • 5i365: 技术牛X, 感谢分享技术 + 1

TOP

点签名就行了

TOP

返回列表