forked from baturayp/Bingo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateBangs.ps1
More file actions
93 lines (73 loc) · 2.51 KB
/
Copy pathgenerateBangs.ps1
File metadata and controls
93 lines (73 loc) · 2.51 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
# PowerShell script to generate bangs.js from bang.ts
# Run this in the project root: ./js/generateBangs.ps1
param(
[string]$bangTsPath = "C:\Users\Moheshwar\Downloads\bang.ts",
[string]$outputPath = "./js/bangs.js"
)
function Generate-BangsFile {
param(
[string]$sourcePath,
[string]$targetPath
)
Write-Host "Reading bang.ts from: $sourcePath" -ForegroundColor Cyan
if (-not (Test-Path $sourcePath)) {
Write-Host "Error: bang.ts not found at $sourcePath" -ForegroundColor Red
exit 1
}
# Read the entire file
$content = Get-Content $sourcePath -Raw
# Extract bangs using regex: t: "tag", u: "url"
$pattern = 't:\s*"([^"]+)",\s*u:\s*"([^"]*)"'
$matches = [regex]::Matches($content, $pattern)
Write-Host "Found $($matches.Count) bangs" -ForegroundColor Green
# Start building the JavaScript file
$jsContent = @"
/**
* GENERATED FILE - Complete Bang definitions for BingEnhancer
* Source: $sourcePath
* Generated: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
* Total bangs: $($matches.Count)
*
* This file was auto-generated from bang.ts
* To regenerate, run: ./generateBangs.ps1
*/
const BANGS = {
"@
# Group matches by tag to avoid duplicates (use the last/most specific one)
$bangDict = @{}
foreach ($match in $matches) {
$tag = $match.Groups[1].Value
$url = $match.Groups[2].Value
# Escape backslashes in URL
$url = $url -replace '\\', '\\'
$bangDict[$tag] = $url
}
# Add all bangs to the output
$count = 0
foreach ($tag in ($bangDict.Keys | Sort-Object)) {
$url = $bangDict[$tag]
# Escape quotes in URL
$url = $url -replace '"', '\"'
$jsContent += "`n `"$tag`": `"$url`","
$count++
}
# Remove trailing comma from last entry
$jsContent = $jsContent -replace ',$', ''
$jsContent += @"
};
// Export for use in content script
if (typeof window !== 'undefined') {
window.BANGS = BANGS;
}
// For Node.js compatibility
if (typeof module !== 'undefined' && module.exports) {
module.exports = BANGS;
}
"@
# Write to output file
Write-Host "Writing $count bangs to: $targetPath" -ForegroundColor Cyan
Set-Content -Path $targetPath -Value $jsContent -Encoding UTF8
Write-Host "✓ Successfully generated bangs.js with $count bang definitions" -ForegroundColor Green
}
# Run the generation
Generate-BangsFile -sourcePath $bangTsPath -targetPath $outputPath