@xpoudy/free-tools 0.1.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -7
- package/assets/calculators.js +175 -0
- package/assets/common.js +176 -0
- package/assets/copy.js +140 -0
- package/assets/dns.js +280 -0
- package/assets/lists.js +187 -0
- package/assets/mail.js +302 -0
- package/assets/message.js +47 -0
- package/assets/mirror-index.css +6 -0
- package/assets/reports.js +179 -0
- package/assets/toolbox-auth.js +229 -0
- package/assets/toolbox-campaign.js +154 -0
- package/assets/toolbox-compose.js +212 -0
- package/assets/toolbox-data.js +53 -0
- package/assets/toolbox-disposable-license.txt +24 -0
- package/assets/toolbox-disposable.js +1 -0
- package/assets/toolbox-domain.js +199 -0
- package/assets/toolbox-files.js +250 -0
- package/assets/toolbox-leads.js +133 -0
- package/assets/toolbox-measure.js +153 -0
- package/assets/toolbox-pdf-license.txt +177 -0
- package/assets/toolbox-pdf-worker.js +21 -0
- package/assets/toolbox-pdf.js +21 -0
- package/assets/toolbox-ui.js +285 -0
- package/assets/toolbox-vendor-data.js +6 -0
- package/assets/toolbox-vendor-licenses.txt +75 -0
- package/assets/toolbox-vendor-qr.js +8 -0
- package/assets/toolbox.css +14 -0
- package/assets/tools.css +112 -0
- package/assets/ui.js +257 -0
- package/catalog.json +3 -1
- package/favicon-32x32.png +0 -0
- package/index.html +1 -0
- package/index.js +3 -1
- package/package.json +17 -3
- package/tools/cold-email-volume-calculator/index.html +33 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import {InputError,MAX_FILE_SIZE} from './common.js';
|
|
2
|
+
|
|
3
|
+
const settings=document.querySelector('#tool-config');
|
|
4
|
+
const form=document.querySelector('#tool-form');
|
|
5
|
+
const output=document.querySelector('#tool-output');
|
|
6
|
+
const alertBox=document.querySelector('#tool-error');
|
|
7
|
+
const activity=document.querySelector('#tool-activity');
|
|
8
|
+
const submit=form.querySelector('button[type=submit]');
|
|
9
|
+
const config=JSON.parse(settings.textContent);
|
|
10
|
+
const formFields=Array.from(form.querySelectorAll('[data-field]'));
|
|
11
|
+
const uploadFields=Array.from(form.querySelectorAll('[data-read-into]'));
|
|
12
|
+
|
|
13
|
+
const modules={
|
|
14
|
+
"dns":()=>import('./dns.js'),
|
|
15
|
+
"message":()=>import('./message.js'),
|
|
16
|
+
"toolbox-auth":()=>import('./toolbox-auth.js'),
|
|
17
|
+
"toolbox-campaign":()=>import('./toolbox-campaign.js'),
|
|
18
|
+
"toolbox-compose":()=>import('./toolbox-compose.js'),
|
|
19
|
+
"toolbox-domain":()=>import('./toolbox-domain.js'),
|
|
20
|
+
"toolbox-files":()=>import('./toolbox-files.js'),
|
|
21
|
+
"toolbox-leads":()=>import('./toolbox-leads.js'),
|
|
22
|
+
"toolbox-measure":()=>import('./toolbox-measure.js')
|
|
23
|
+
};
|
|
24
|
+
let modulePromise;
|
|
25
|
+
let working=false;
|
|
26
|
+
let revision=0;
|
|
27
|
+
let fileReads=0;
|
|
28
|
+
const pendingReads=new WeakMap();
|
|
29
|
+
|
|
30
|
+
function element(name,content,className){
|
|
31
|
+
const node=document.createElement(name);
|
|
32
|
+
if(className) node.className=className;
|
|
33
|
+
if(content!==undefined) node.textContent=String(content);
|
|
34
|
+
return node;
|
|
35
|
+
}
|
|
36
|
+
function syncMode(){
|
|
37
|
+
const mode=form.elements.namedItem('mode')?.value;
|
|
38
|
+
for(const wrap of formFields){
|
|
39
|
+
if(!wrap.dataset.when) continue;
|
|
40
|
+
wrap.hidden=wrap.dataset.when!==mode;
|
|
41
|
+
for(const input of wrap.querySelectorAll('input,textarea,select')) input.disabled=wrap.hidden;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function showError(message,focus=false){
|
|
45
|
+
alertBox.textContent=message;
|
|
46
|
+
alertBox.hidden=!message;
|
|
47
|
+
if(message&&focus) alertBox.focus();
|
|
48
|
+
}
|
|
49
|
+
function controlsLocked(){
|
|
50
|
+
submit.disabled=working||fileReads>0;
|
|
51
|
+
}
|
|
52
|
+
async function fileText(file){
|
|
53
|
+
if(file.size>MAX_FILE_SIZE) throw new InputError('Open files no larger than 4 MB.');
|
|
54
|
+
try {
|
|
55
|
+
return new TextDecoder('utf-8',{fatal:true}).decode(await file.arrayBuffer());
|
|
56
|
+
} catch {
|
|
57
|
+
throw new InputError('This file could not be read as UTF-8. Save it as UTF-8 text or CSV and try again.');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for(const fileInput of uploadFields){
|
|
61
|
+
fileInput.addEventListener('change',async()=>{
|
|
62
|
+
const file=fileInput.files[0];
|
|
63
|
+
if(!file) return;
|
|
64
|
+
const token=revision;
|
|
65
|
+
const operation=Symbol();
|
|
66
|
+
pendingReads.set(fileInput,operation);
|
|
67
|
+
fileReads++;
|
|
68
|
+
controlsLocked();
|
|
69
|
+
showError('');
|
|
70
|
+
activity.textContent='Opening '+file.name+' locally…';
|
|
71
|
+
try{
|
|
72
|
+
const text=await fileText(file);
|
|
73
|
+
if(token!==revision||pendingReads.get(fileInput)!==operation) return;
|
|
74
|
+
form.elements.namedItem(fileInput.dataset.readInto).value=text;
|
|
75
|
+
activity.textContent='Opened '+file.name+' locally.';
|
|
76
|
+
}catch(error){
|
|
77
|
+
if(token===revision&&pendingReads.get(fileInput)===operation){
|
|
78
|
+
activity.textContent='';
|
|
79
|
+
showError(error instanceof InputError?error.message:'This file could not be opened.',true);
|
|
80
|
+
}
|
|
81
|
+
}finally{
|
|
82
|
+
if(pendingReads.get(fileInput)===operation) fileInput.value='';
|
|
83
|
+
fileReads--;
|
|
84
|
+
controlsLocked();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
form.addEventListener('change',event=>{if(event.target.name==='mode') syncMode();});
|
|
89
|
+
function inputs(){
|
|
90
|
+
const values={}, files={};
|
|
91
|
+
for(const wrap of formFields){
|
|
92
|
+
const control=form.elements.namedItem(wrap.dataset.field);
|
|
93
|
+
if(control.disabled) continue;
|
|
94
|
+
if(control.type==='file') files[control.name]=Array.from(control.files);
|
|
95
|
+
else values[control.name]=control.value;
|
|
96
|
+
}
|
|
97
|
+
return {values,files};
|
|
98
|
+
}
|
|
99
|
+
function makeButton(label,handler){
|
|
100
|
+
const node=element('button',label,'secondary');
|
|
101
|
+
node.type='button';
|
|
102
|
+
node.addEventListener('click',handler);
|
|
103
|
+
return node;
|
|
104
|
+
}
|
|
105
|
+
async function copyText(text){
|
|
106
|
+
if(navigator.clipboard?.writeText){
|
|
107
|
+
try{await navigator.clipboard.writeText(text);activity.textContent='Copied.';return;}catch{}
|
|
108
|
+
}
|
|
109
|
+
const previous=document.activeElement;
|
|
110
|
+
const field=element('textarea',undefined,'clipboard-fallback');
|
|
111
|
+
field.value=text;
|
|
112
|
+
field.setAttribute('aria-label','Text to copy');
|
|
113
|
+
document.body.append(field);
|
|
114
|
+
field.select();
|
|
115
|
+
const copied=document.execCommand('copy');
|
|
116
|
+
field.remove();
|
|
117
|
+
if(previous instanceof HTMLElement) previous.focus();
|
|
118
|
+
activity.textContent=copied?'Copied.':'Copy is unavailable here. Select and copy the displayed result.';
|
|
119
|
+
}
|
|
120
|
+
function downloadFile(file){
|
|
121
|
+
const data=new Blob([file.text],{type:file.type});
|
|
122
|
+
const url=URL.createObjectURL(data);
|
|
123
|
+
const link=element('a');
|
|
124
|
+
link.href=url;
|
|
125
|
+
link.download=file.name;
|
|
126
|
+
document.body.append(link);
|
|
127
|
+
link.click();
|
|
128
|
+
link.remove();
|
|
129
|
+
setTimeout(()=>URL.revokeObjectURL(url),1000);
|
|
130
|
+
}
|
|
131
|
+
function tableCell(value){
|
|
132
|
+
const text=String(value??'—');
|
|
133
|
+
return text.length>4000 ? text.slice(0,3999)+'…' : text;
|
|
134
|
+
}
|
|
135
|
+
function accessibleTable(table){
|
|
136
|
+
const scroll=element('div',undefined,'table-scroll');
|
|
137
|
+
scroll.setAttribute('aria-label','Detailed results');
|
|
138
|
+
scroll.setAttribute('role','region');
|
|
139
|
+
scroll.tabIndex=0;
|
|
140
|
+
const out=element('table');
|
|
141
|
+
const head=element('thead');
|
|
142
|
+
const headerRow=element('tr');
|
|
143
|
+
for(const name of table.columns){
|
|
144
|
+
const cell=element('th',tableCell(name));
|
|
145
|
+
cell.scope='col';
|
|
146
|
+
headerRow.append(cell);
|
|
147
|
+
}
|
|
148
|
+
head.append(headerRow);
|
|
149
|
+
const body=element('tbody');
|
|
150
|
+
for(const row of table.rows){
|
|
151
|
+
const tr=element('tr');
|
|
152
|
+
for(const value of row) tr.append(element('td',tableCell(value)));
|
|
153
|
+
body.append(tr);
|
|
154
|
+
}
|
|
155
|
+
out.append(head,body);
|
|
156
|
+
scroll.append(out);
|
|
157
|
+
return scroll;
|
|
158
|
+
}
|
|
159
|
+
function present(result){
|
|
160
|
+
const fragment=document.createDocumentFragment();
|
|
161
|
+
const heading=element('h2','Results');
|
|
162
|
+
heading.tabIndex=-1;
|
|
163
|
+
heading.id='result-heading';
|
|
164
|
+
fragment.append(heading);
|
|
165
|
+
const metrics=element('dl',undefined,'metrics');
|
|
166
|
+
for(const [label,value] of result.metrics){
|
|
167
|
+
const metric=element('div');
|
|
168
|
+
metric.append(element('dt',label),element('dd',value));
|
|
169
|
+
metrics.append(metric);
|
|
170
|
+
}
|
|
171
|
+
if(result.metrics.length) fragment.append(metrics);
|
|
172
|
+
if(result.text!==undefined){
|
|
173
|
+
fragment.append(element('pre',result.text,'record-output'),makeButton('Copy result',()=>copyText(result.text)));
|
|
174
|
+
}
|
|
175
|
+
if(result.table?.rows.length){
|
|
176
|
+
fragment.append(accessibleTable(result.table));
|
|
177
|
+
if(result.table.rows.some(row=>row.some(value=>String(value??'').length>4000))){
|
|
178
|
+
fragment.append(element('p','Long values are shortened in this preview.','note'));
|
|
179
|
+
}
|
|
180
|
+
if(result.table.total>result.table.rows.length){
|
|
181
|
+
fragment.append(element('p','Showing '+result.table.rows.length+' of '+result.table.total+' rows.','note'));
|
|
182
|
+
}
|
|
183
|
+
}else if(result.table) fragment.append(element('p','No detail rows to show.','note'));
|
|
184
|
+
if(result.blocks?.length){
|
|
185
|
+
const previews=element('div',undefined,'previews');
|
|
186
|
+
for(const [title,body] of result.blocks){
|
|
187
|
+
const detail=element('details');
|
|
188
|
+
detail.open=previews.childElementCount===0;
|
|
189
|
+
detail.append(element('summary',title),element('pre',body,'record-output'),
|
|
190
|
+
makeButton('Copy text',()=>copyText(body)));
|
|
191
|
+
previews.append(detail);
|
|
192
|
+
}
|
|
193
|
+
fragment.append(previews);
|
|
194
|
+
}
|
|
195
|
+
if(result.downloads?.length){
|
|
196
|
+
const area=element('div',undefined,'downloads');
|
|
197
|
+
for(const file of result.downloads) area.append(makeButton('Download '+file.name,()=>downloadFile(file)));
|
|
198
|
+
fragment.append(area);
|
|
199
|
+
}
|
|
200
|
+
if(result.inboxes?.length){
|
|
201
|
+
for(const inbox of result.inboxes){
|
|
202
|
+
const card=element('div',undefined,'toolbox-inbox'+(inbox.kind.startsWith('Narrow')?' toolbox-inbox-narrow':''));
|
|
203
|
+
card.append(element('p',inbox.kind),element('strong',inbox.sender),element('div',inbox.subject,'toolbox-inbox-subject'),element('p',inbox.pre));
|
|
204
|
+
fragment.append(card);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if(result.preview){
|
|
208
|
+
const {html,width,theme}=result.preview;
|
|
209
|
+
const frame=element('iframe',undefined,'toolbox-preview');
|
|
210
|
+
frame.setAttribute('sandbox','');
|
|
211
|
+
frame.title='Email preview';
|
|
212
|
+
frame.width=String(width);
|
|
213
|
+
const dark=theme==='dark';
|
|
214
|
+
frame.srcdoc=`<!doctype html><meta charset="UTF-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; form-action 'none'; base-uri 'none'"><style>body{background:${dark?'#101519':'#ffffff'};color:${dark?'#ffffff':'#162233'};font:16px system-ui;overflow-wrap:anywhere;padding:16px}</style>${html}`;
|
|
215
|
+
fragment.append(frame);
|
|
216
|
+
}
|
|
217
|
+
if(result.image?.startsWith('data:image/png;base64,')){
|
|
218
|
+
const preview=element('img',undefined,'toolbox-qr');
|
|
219
|
+
preview.alt='Generated campaign QR code';
|
|
220
|
+
preview.src=result.image;
|
|
221
|
+
fragment.append(preview);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if(result.notes?.length){
|
|
225
|
+
const notes=element('ul',undefined,'result-notes');
|
|
226
|
+
for(const text of result.notes) notes.append(element('li',text));
|
|
227
|
+
fragment.append(notes);
|
|
228
|
+
}
|
|
229
|
+
output.replaceChildren(fragment);
|
|
230
|
+
output.dataset.state='done';
|
|
231
|
+
heading.focus({preventScroll:true});
|
|
232
|
+
if(window.matchMedia('(max-width: 760px)').matches) output.scrollIntoView({block:'start',behavior:'instant'});
|
|
233
|
+
}
|
|
234
|
+
async function run(example=false){
|
|
235
|
+
if(working||fileReads) return;
|
|
236
|
+
working=true;
|
|
237
|
+
const submitted=revision;
|
|
238
|
+
controlsLocked();
|
|
239
|
+
showError('');
|
|
240
|
+
activity.textContent='Working…';
|
|
241
|
+
output.dataset.state='working';
|
|
242
|
+
output.setAttribute('aria-busy','true');
|
|
243
|
+
const {values,files}=inputs();
|
|
244
|
+
try{
|
|
245
|
+
modulePromise??=modules[config.module]().catch(error=>{modulePromise=undefined;throw error;});
|
|
246
|
+
const mod=await modulePromise;
|
|
247
|
+
const result=await mod[config.action](values,{files,example});
|
|
248
|
+
if(submitted!==revision) return;
|
|
249
|
+
present(result);
|
|
250
|
+
activity.textContent='Results ready.';
|
|
251
|
+
}catch(error){
|
|
252
|
+
if(submitted!==revision) return;
|
|
253
|
+
const message=error instanceof InputError?error.message:'The tool could not complete that input. Check the file format or try the example.';
|
|
254
|
+
output.dataset.state='error';
|
|
255
|
+
output.replaceChildren(element('h2','Results'),element('p','Review the message beside the form and run the tool again.','note'));
|
|
256
|
+
activity.textContent='';
|
|
257
|
+
showError(message,true);
|
|
258
|
+
}finally{
|
|
259
|
+
output.setAttribute('aria-busy','false');
|
|
260
|
+
working=false;
|
|
261
|
+
controlsLocked();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
form.addEventListener('submit',event=>{event.preventDefault();void run();});
|
|
265
|
+
document.querySelector('#load-example').addEventListener('click',()=>{
|
|
266
|
+
if(working||fileReads) return;
|
|
267
|
+
revision++;
|
|
268
|
+
form.reset();
|
|
269
|
+
for(const [name,value] of Object.entries(config.example)){
|
|
270
|
+
const field=form.elements.namedItem(name);
|
|
271
|
+
if(field&&field.type!=='file') field.value=String(value);
|
|
272
|
+
}
|
|
273
|
+
syncMode();
|
|
274
|
+
void run(true);
|
|
275
|
+
});
|
|
276
|
+
form.addEventListener('reset',()=>{
|
|
277
|
+
revision++;
|
|
278
|
+
showError('');
|
|
279
|
+
activity.textContent='';
|
|
280
|
+
output.dataset.state='idle';
|
|
281
|
+
output.replaceChildren(element('h2','Results'),element('p',config.exampleLine));
|
|
282
|
+
setTimeout(syncMode,0);
|
|
283
|
+
});
|
|
284
|
+
syncMode();
|
|
285
|
+
|