-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathConfig-uBlock-Lite.ps1
More file actions
227 lines (175 loc) · 7.83 KB
/
Config-uBlock-Lite.ps1
File metadata and controls
227 lines (175 loc) · 7.83 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<#
.SYNOPSIS
Configure uBlock Origin Lite extension via Group Policy for Microsoft Edge or Google Chrome
.DESCRIPTION
Configures uBlock Origin Lite (Manifest V3) extension via registry-based Group Policy.
Runs in SYSTEM context and writes settings to HKLM registry keys.
.PARAMETER Browser
Target browser(s). Options: "Edge", "Chrome", or both. Default: "Edge"
.PARAMETER RemoveConfiguration
Set to $true to remove all uBlock Origin Lite policies instead of configuring them
.PARAMETER DefaultFiltering
Default filtering mode. Options: "none", "basic", "optimal", "complete"
.PARAMETER ShowBlockedCount
Show blocked count on extension icon. 1 = true, 0 = false
.PARAMETER StrictBlockMode
Strict block mode. 1 = true, 0 = false
.PARAMETER DisableFirstRunPage
Disable first run page. 1 = true, 0 = false
.PARAMETER NoFiltering
Trusted sites where uBlock Lite will be disabled. JSON array format: '["example.com", "trusted-site.org"]'
.PARAMETER DisabledFeatures
Disable specific user-facing features. JSON array format: '["dashboard", "develop", "filteringMode", "picker", "zapper"]'
Options: dashboard (prevent setting changes), develop (prevent developer mode), filteringMode (prevent filtering mode changes), picker (prevent custom filters), zapper (prevent element removal)
.PARAMETER Rulesets
Enable/disable specific rulesets. JSON array format: '["+default", "+adguard-url-tracking", "-easylist-cookies"]'
Use + to enable, - to disable. Special value "-*" disables all non-default rulesets. See https://github.com/uBlockOrigin/uBOL-home/blob/main/chromium/rulesets/ruleset-details.json for ruleset IDs
Default rulesets (already enabled): ublock-filters, ublock-badware, ublock-privacy, ublock-unbreak, easylist, easyprivacy, plowe-0, urlhaus-full
Common additional rulesets to enable:
- adguard-spyware-url: Removes tracking parameters from URLs (AdGuard URL Tracking Protection)
- annoyances-cookies: Blocks cookie consent notices (EasyList/uBO)
- annoyances-overlays: Blocks popups and overlay notices (EasyList/uBO)
- annoyances-social: Blocks social widgets (EasyList)
- annoyances-notifications: Blocks notification prompts (EasyList)
- adguard-mobile: Mobile-specific ad blocking (AdGuard/uBO)
Example: '["+default", "+adguard-spyware-url", "+annoyances-cookies", "+annoyances-overlays"]'
.NOTES
Author: Martin Bengtsson
Blog: https://www.imab.dk
Requires: Administrator privileges
Extension: uBlock Origin Lite (Manifest V3)
Extension ID (Edge): cimighlppcgcoapaliogpjjdehbnofhn
Extension ID (Chrome): ddkjiahejlhfcafbddmgiahcphecmpfh
#>
#Requires -RunAsAdministrator
Param(
[ValidateSet("Edge", "Chrome")]
[string[]]$Browser = @("Edge", "Chrome"),
[bool]$RemoveConfiguration = $false,
[ValidateSet("none", "basic", "optimal", "complete")]
[string]$DefaultFiltering = "optimal",
[ValidateRange(0, 1)]
[int]$ShowBlockedCount = 1,
[ValidateRange(0, 1)]
[int]$StrictBlockMode = 1,
[ValidateRange(0, 1)]
[int]$DisableFirstRunPage = 1,
[string]$NoFiltering = '["imab.dk", "contoso.com", "contoso.sharepoint.com", "app.powerbi.com", "community.powerbi.com", "intranet.contoso.com", "portal.contoso.com", "app.bundledocs.com"]',
# Available features: "dashboard", "develop", "filteringMode", "picker", "zapper"
[string]$DisabledFeatures = '["dashboard"]',
# Use +ruleset to enable, -ruleset to disable, -* to disable all except specified
# Ruleset IDs: https://github.com/uBlockOrigin/uBOL-home/blob/main/chromium/rulesets/ruleset-details.json
[string]$Rulesets = '["+default"]'
)
# Helper Functions
Function Get-BrowserPolicyPath {
Param([string]$Browser)
if ($Browser -eq "Edge") {
return "HKLM:\SOFTWARE\Policies\Microsoft\Edge"
} else {
return "HKLM:\SOFTWARE\Policies\Google\Chrome"
}
}
Function Get-ExtensionID {
Param([string]$Browser)
if ($Browser -eq "Edge") {
return "cimighlppcgcoapaliogpjjdehbnofhn"
} else {
return "ddkjiahejlhfcafbddmgiahcphecmpfh"
}
}
Function Get-ExtensionPolicyPath {
Param(
[string]$Browser,
[string]$ExtensionID
)
return "$(Get-BrowserPolicyPath $Browser)\3rdparty\extensions\$ExtensionID\policy"
}
Function Set-RegistryProperty {
Param(
[string]$Path,
[string]$Name,
[object]$Value,
[ValidateSet("String", "DWord")]
[string]$Type
)
Try {
New-ItemProperty -Path $Path -Name $Name -PropertyType $Type -Value $Value -Force -ErrorAction Stop | Out-Null
Write-Output "$LogPrefix Set '$Name' successfully"
}
Catch {
Write-Output "$LogPrefix ERROR: Failed to set '$Name' - $($_.Exception.Message)"
}
}
Function Initialize-ExtensionPath {
Param(
[string]$Browser,
[string]$ExtensionID
)
$extensionPath = Get-ExtensionPolicyPath -Browser $Browser -ExtensionID $ExtensionID
Try {
if (-not (Test-Path $extensionPath)) {
New-Item -Path $extensionPath -Force -ErrorAction Stop | Out-Null
}
return $extensionPath
}
Catch {
Write-Output "$LogPrefix ERROR: Failed to create registry path - $($_.Exception.Message)"
return $null
}
}
Function Remove-ExtensionConfiguration {
Param(
[string]$Browser,
[string]$ExtensionID
)
Write-Output "$LogPrefix REMOVING configuration for $Browser"
$policyPath = Get-ExtensionPolicyPath -Browser $Browser -ExtensionID $ExtensionID
if (Test-Path -Path $policyPath) {
Try {
Remove-Item -Path $policyPath -Recurse -Force -ErrorAction Stop
Write-Output "$LogPrefix Removed policy configuration"
}
Catch {
Write-Output "$LogPrefix ERROR: Failed to remove configuration - $($_.Exception.Message)"
Exit 1
}
}
Write-Output "$LogPrefix Configuration removal completed!"
Exit 0
}
# Configuration
$LogPrefix = "[uBlock-Lite]"
# Remove Configuration Mode
If ($RemoveConfiguration) {
foreach ($BrowserName in $Browser) {
$extensionID = Get-ExtensionID -Browser $BrowserName
Remove-ExtensionConfiguration -Browser $BrowserName -ExtensionID $extensionID
}
}
# Apply Configuration
$settings = @(
@{ Name = "defaultFiltering"; Value = $DefaultFiltering; Type = "String" }
@{ Name = "showBlockedCount"; Value = $ShowBlockedCount; Type = "DWord" }
@{ Name = "strictBlockMode"; Value = $StrictBlockMode; Type = "DWord" }
@{ Name = "disableFirstRunPage"; Value = $DisableFirstRunPage; Type = "DWord" }
@{ Name = "noFiltering"; Value = $NoFiltering; Type = "String" }
@{ Name = "disabledFeatures"; Value = $DisabledFeatures; Type = "String" }
@{ Name = "rulesets"; Value = $Rulesets; Type = "String" }
)
foreach ($BrowserName in $Browser) {
$extensionID = Get-ExtensionID -Browser $BrowserName
Write-Output "$LogPrefix Configuring for $BrowserName"
$litePolicyPath = Initialize-ExtensionPath -Browser $BrowserName -ExtensionID $extensionID
if (-not $litePolicyPath) {
Write-Output "$LogPrefix ERROR: Failed to initialize extension path for $BrowserName"
Exit 1
}
foreach ($setting in $settings) {
Write-Output "$LogPrefix Applying setting: $($setting.Name) = $($setting.Value)"
Set-RegistryProperty -Path $litePolicyPath -Name $setting.Name -Value $setting.Value -Type $setting.Type | Out-Null
}
Write-Output "$LogPrefix Configuration completed successfully for $BrowserName!"
}
Write-Output "$LogPrefix Restart browser(s) for changes to take effect"
Exit 0