TL;DR 在底部。
美化首选项文件后,我发现这是正确的路径:
$Preferences = Get-Content -Path "C:\Users\xxx\AppData\Local\Google\Chrome\User Data\default\Preferences" | ConvertFrom-Json
$CookieExceptions = $Preferences.profile.content_settings.exceptions.cookies
$CookieExceptions 返回一个 PSCustomObject:
stackexchange.com,*
-------------------
@{expiration=0; last_modified=13287790992647427; model=0; setting=1}
其中包含一个也具有 PSCustomObject 类型的成员。
$CookieExceptions.'stackexchange.com,*' 返回:
expiration last_modified model setting
---------- ------------- ----- -------
0 13287790939152770 0 1
使用 Get-Member cmdlet,您可以查看 PSCustomObject 具有哪些成员:
$CookieExceptions.'stackoverflow.com,*' | Get-Member -MemberType NoteProperty 返回:
Name MemberType Definition
---- ---------- ----------
expiration NoteProperty string expiration=0
last_modified NoteProperty string last_modified=13287790939152770
model NoteProperty int model=0
setting NoteProperty int setting=1
所以要添加一个新站点,你可以创建一个类似的对象:
$SiteProperties = [PSCustomObject]@{
expiration = 0
last_modified = 13287790939152770
model = 0
setting = 1
}
然后使用正确的站点名称将其添加到 $CookiePreference:
$CookieExceptions | Add-Member -MemberType NoteProperty -Name "stackoverflow.com,*" -Value $SiteProperties
现在你有两个网站了!
stackexchange.com,* stackoverflow.com,*
------------------- -------------------
@{expiration=0; last_modified=13287790939152770; model=0; setting=1} @{expiration=0; last_modified=13287790939152770; model=0; setting=1}
不要忘记将其保存到 JSON 首选项文件中。
Set-Content -Path "C:\Users\xxx\AppData\Local\Google\Chrome\User Data\default\Preferences" -Value ($Preferences | ConvertTo-Json -Depth 32)
TL;DR 我不知道所有站点属性的作用以及 Chrome 对外部更改首选项文件的反应。我已经对此进行了简短的测试,它似乎有效。下面是整个脚本。祝你好运!
$Preferences = Get-Content -Path $PathToPreferencesFile | ConvertFrom-Json
$CookieExceptions = $Preferences.profile.content_settings.exceptions.cookies
$SiteProperties = [PSCustomObject]@{
expiration = 0
last_modified = 13287793933254853 #WebKit timestamp?
model = 0
setting = 1
}
$CookieExceptions | Add-Member -MemberType NoteProperty -Name "stackoverflow.com,*" -Value $SiteProperties
Set-Content -Path $PathToPreferencesFile -Value ($Preferences | ConvertTo-Json -Depth 32)