-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-Chrome-Bridge.ps1
More file actions
70 lines (60 loc) · 2.35 KB
/
Copy pathInstall-Chrome-Bridge.ps1
File metadata and controls
70 lines (60 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
param(
[string]$ExtensionId = ""
)
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$extensionDir = Join-Path $root "chrome-extension"
$hostDir = Join-Path $root "chrome-helper"
$hostManifestPath = Join-Path $hostDir "yt_dlp_native_host.json"
$hostBatPath = Join-Path $hostDir "yt_dlp_native_host.bat"
if (-not (Test-Path -LiteralPath $extensionDir)) {
throw "Missing extension directory: $extensionDir"
}
if (-not (Test-Path -LiteralPath $hostBatPath)) {
throw "Missing native host launcher: $hostBatPath"
}
if ([string]::IsNullOrWhiteSpace($ExtensionId)) {
Write-Host "Chrome extension folder:"
Write-Host " $extensionDir"
Write-Host ""
try {
Set-Clipboard -Value $extensionDir
Write-Host "The extension folder path was copied to the clipboard."
} catch {
Write-Host "Could not copy the extension folder path automatically."
}
Write-Host ""
Write-Host "Steps:"
Write-Host " 1. Open chrome://extensions manually."
Write-Host " 2. Enable Developer mode."
Write-Host " 3. Click Load unpacked and choose the chrome-extension folder above."
Write-Host " 4. Copy the extension ID from the extension card."
Write-Host ""
$ExtensionId = (Read-Host "Paste Chrome extension ID").Trim()
}
if ($ExtensionId -notmatch "^[a-p]{32}$") {
throw "Invalid Chrome extension ID: $ExtensionId"
}
$manifest = Get-Content -LiteralPath $hostManifestPath -Raw | ConvertFrom-Json
$manifest.path = $hostBatPath
$origin = "chrome-extension://$ExtensionId/"
$origins = @()
if ($manifest.PSObject.Properties["allowed_origins"] -and $manifest.allowed_origins) {
$origins += @($manifest.allowed_origins | ForEach-Object { [string]$_ })
}
if ($origins -notcontains $origin) {
$origins += $origin
}
$manifest.allowed_origins = @($origins | Sort-Object -Unique)
$manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $hostManifestPath -Encoding UTF8
$keyPath = "HKCU:\Software\Google\Chrome\NativeMessagingHosts\com.local.ytdlp_helper"
New-Item -Path $keyPath -Force | Out-Null
Set-Item -Path $keyPath -Value $hostManifestPath
Write-Host "Native host registered:"
Write-Host " $hostManifestPath"
Write-Host ""
Write-Host "Allowed extension origin added: $origin"
Write-Host ""
Write-Host "Chrome extension folder:"
Write-Host " $extensionDir"