-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.ps1
98 lines (86 loc) · 2.27 KB
/
generate.ps1
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
#!/usr/bin/env pwsh
[CmdletBinding()]
param (
[parameter()]
[string] $out,
[Parameter(Position = 0, ValueFromRemainingArguments)]
[ValidateSet("ddg", "google", "brave", "startpage", "ecosia", "block-access")]
[string[]] $filter
)
function join {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline, Position = 0)]
[string] $str
)
begin {
$list = [Collections.Generic.List[string]]::new(8)
}
process {
if($str) {
[void] $list.add($str)
}
}
end {
if($list.count -lt 3) {
return $list -join " and "
}
$list `
| select-object -skipLast 1 `
| join-string -separator ", " -outputSuffix " and $($list[-1])"
}
}
$ErrorActionPreference = "stop"
$rules = [ordered] @{
"block-access" = {
param([string] $domain)
if($domain.contains("/")) {
'||{0}$all' -f $domain
} else {
'||{0}^$all' -f $domain
}
}
ddg = 'duckduckgo.com##.react-results--main > li:has(a[href*="{0}"])'
# google = 'google.*###rso .MjjYud a[href*="{0}"]:upward(.MjjYud)'
google = 'google.*##.g:has(a[href*="{0}"])' + "`n" + 'google.*##a[href*="{0}"]:upward(1)'
brave = 'search.brave.com###results > div:has(a[href*="{0}"])'
startpage = 'startpage.com##.w-gl__result:has(a[href*="{0}"])'
ecosia = 'ecosia.org###main .result:has(a[href*="{0}"])'
}
if(!$filter) {
$filter = $rules.keys
}
$header = @"
! Title: Insomnia's Garbage Sites Filter
! Expires: 1 day
! Description: $(
$s = "AI generated sites, sites that carry little real info but tons of SEO douchebaggery or otherwise sites with no useful content"
if($filter.count -eq 1 -and $filter -eq "block-access") {
"Blocks access to $s"
} else {
$engines = $filter | where-object { $_ -ne "block-access" } | join
"Removes $s, from search results in $engines"
}
)
! Homepage: https://github.com/insomnimus/seo-garbage
! License: https://github.com/insomnimus/seo-garbage/blob/main/LICENSE`n`n
"@.replace("`r", "")
$filters = $filter | foreach-object { $rules[$_] }
$data = get-content -lp "$PSScriptRoot/list.txt" `
| foreach-object Trim `
| where-object { $_ } `
| foreach-object {
foreach($f in $filters) {
if($f -is [ScriptBlock]) {
&$f $_
} else {
$f -f $_
}
}
} `
| join-string -separator "`n" -outputPrefix $header -outputSuffix "`n"
if($out) {
$data | out-file -noNewLine -encoding utf8 $out
} else {
$data
}