-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.html
More file actions
199 lines (193 loc) · 5.96 KB
/
Copy pathextract.html
File metadata and controls
199 lines (193 loc) · 5.96 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CRX to ZIP Extractor</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<style>
body {
font-family: 'Roboto', Arial, sans-serif;
margin: 0;
background: #eaf6fb;
}
.container {
max-width: 400px;
margin: 48px auto;
background: #fff;
box-shadow: 0 2px 12px #a6b8e922;
border-radius: 10px;
padding: 32px 16px;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5em;
}
h2 {
color: #1869ad;
font-size: 1.5em;
margin-bottom: 18px;
text-align: center;
font-weight: 700;
}
label {
font-weight: 500;
color: #3171c4;
margin-bottom: 5px;
display: block;
}
input[type="file"] {
width: 100%;
padding: 8px;
margin-bottom: 14px;
font-size: 1em;
border-radius: 6px;
border: 1px solid #b8c3d1;
box-sizing: border-box;
outline: none;
background: #f5faff;
color: #1a4060;
}
button {
width: 100%;
padding: 8px;
margin-bottom: 14px;
font-size: 1em;
border-radius: 6px;
border: none;
font-weight: 700;
background: #44a3ee;
color: #fff;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background: #2283ee;
}
/* Download ZIP button styling */
.download-btn {
display: inline-block;
width: auto;
padding: 12px 32px;
margin: 1em 0;
font-size: 1.1em;
font-weight: bold;
text-align: center;
background: linear-gradient(90deg, #44a3ee 40%, #1869ad 100%);
color: #fff;
border: none;
border-radius: 8px;
text-decoration: none;
box-shadow: 0 2px 12px #a6b8e933;
cursor: pointer;
transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
}
.download-btn:hover, .download-btn:focus {
background: linear-gradient(90deg, #2283ee 40%, #09468a 100%);
box-shadow: 0 4px 16px #1869ad33;
transform: translateY(-2px) scale(1.03);
text-decoration: none;
outline: none;
}
#progress {
width: 100%;
min-height: 20px;
color: #1a4060;
text-align: center;
font-size: 1em;
}
#result {
margin-top: 20px;
font-size: 1em;
background: #f2f7fa;
border-radius: 7px;
padding: 12px;
color: #1a4060;
word-break: break-all;
width: 100%;
text-align: center;
}
small {
color: #2c537c;
font-size: 0.93em;
margin-top: 6px;
display: block;
}
hr {
width: 100%;
border: none;
border-top: 1px solid #eaf0f7;
margin: 14px 0 8px 0;
}
@media (max-width: 500px) {
.container {
padding: 12px 4px;
max-width: 96vw;
}
}
</style>
</head>
<body>
<div class="container">
<h2>CRX-to-ZIP Extractor</h2>
<input type="file" id="crxfile" accept=".crx" />
<div id="progress"></div>
<button id="extractBtn">Extract to ZIP</button>
<div id="result" style="display: none;"></div>
<hr>
<small>Upload your .crx file to extract its contents. Supports CRX2, CRX3, CRX4.</small>
</div>
<script>
function readCRXPayload(arrayBuffer) {
const arr = new Uint8Array(arrayBuffer);
if (!(arr[0] === 0x43 && arr[1] === 0x72 && arr[2] === 0x32 && arr[3] === 0x34)) {
throw new Error('Not a valid CRX file (bad magic number).');
}
const version = arr[4] | (arr[5]<<8) | (arr[6]<<16) | (arr[7]<<24);
let zipStart = 0;
if (version === 2) {
const pubKeyLen = arr[8] | (arr[9]<<8) | (arr[10]<<16) | (arr[11]<<24);
const sigLen = arr[12] | (arr[13]<<8) | (arr[14]<<16) | (arr[15]<<24);
zipStart = 16 + pubKeyLen + sigLen;
} else if (version === 3 || version === 4) {
const headerSize = arr[8] | (arr[9]<<8) | (arr[10]<<16) | (arr[11]<<24);
zipStart = 12 + headerSize;
} else {
throw new Error('Unsupported CRX version: ' + version);
}
return arrayBuffer.slice(zipStart);
}
document.getElementById('extractBtn').onclick = async function() {
const fileInput = document.getElementById('crxfile');
const resultDiv = document.getElementById('result');
const progressDiv = document.getElementById('progress');
resultDiv.innerHTML = ''; resultDiv.style.display = 'none'; progressDiv.textContent = '';
if (!fileInput.files[0]) return alert('Please select a .crx file!');
try {
progressDiv.textContent = 'Reading CRX file...';
const arrayBuffer = await fileInput.files[0].arrayBuffer();
const zipBuffer = readCRXPayload(arrayBuffer);
progressDiv.textContent = 'Extracting ZIP...';
const zip = new JSZip();
await zip.loadAsync(zipBuffer);
progressDiv.textContent = 'Preparing ZIP for download...';
const zipBase64 = await zip.generateAsync({type:"blob"});
const zipFileName = fileInput.files[0].name.replace(/\.crx$/i, '.zip');
const down = document.createElement('a');
down.href = URL.createObjectURL(zipBase64);
down.download = zipFileName;
down.textContent = 'Download ZIP';
down.className = 'download-btn';
resultDiv.innerHTML = '';
resultDiv.appendChild(down);
resultDiv.style.display = '';
progressDiv.textContent = 'Done!';
} catch(e) {
progressDiv.textContent = '';
resultDiv.innerHTML = `<span style="color:red">${e.message}</span>`;
resultDiv.style.display = '';
}
};
</script>
</body>
</html>