-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
99 lines (81 loc) · 2.58 KB
/
Copy pathmain.html
File metadata and controls
99 lines (81 loc) · 2.58 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
<!DOCTYPE html>
<html>
<head>
<title>geml</title>
<script>
const fs = require("fs").promises;
const csv = require("csv-parse");
let sCSVPath;
let sTplPath;
let sOutPath;
window.onload = function(){
idCSVFile.ondragover =
idCSVFile.ondragenter =
idCSVFile.ondrop =
idCSVFile.ondragleave = (e) => {
if(e.type == 'drop') {
const files = e.dataTransfer.files;
console.log(files);
idCSVFile.textContent = files[0].name;
sCSVPath = files[0].path;
}
e.preventDefault();
};
idTemplate.ondragover =
idTemplate.ondragenter =
idTemplate.ondrop =
idTemplate.ondragleave = (e) => {
if(e.type == 'drop') {
const files = e.dataTransfer.files;
console.log(files);
idTemplate.textContent = files[0].name;
sTplPath = files[0].path;
}
e.preventDefault();
};
idOutDir.ondragover =
idOutDir.ondragenter =
idOutDir.ondrop =
idOutDir.ondragleave = (e) => {
if(e.type == 'drop') {
const files = e.dataTransfer.files;
console.log(files);
idOutDir.textContent = files[0].name;
sOutPath = files[0].path;
}
e.preventDefault();
};
};
async function onGenerate(){
if(!sCSVPath || !sTplPath || !sOutPath){
alert('set CSV, Template and Out-dir.');
return;
}
let oTable; csv(await fs.readFile(sCSVPath), {columns: true}, (e, d)=>{oTable=d;});
let sTemplate = (await fs.readFile(sTplPath)).toString();
let i=0;
while(i < oTable.length){
let sMail = sTemplate;
for(let s in oTable[i]){
sMail = sMail.replace('{{'+s+'}}', oTable[i][s]);
}
await fs.writeFile(sOutPath+'/'+i+'.eml', sMail);
++i;
}
alert('eml has been generated.');
}
</script>
</head>
<body>
<p id="idCSVFile" style="border:3px dotted; height:3em;">
[ここにCSVファイルをドロップ]
</p>
<p id="idTemplate" style="border:3px dotted; height:3em;">
[ここにメールテンプレートをドロップ]
</p>
<p id="idOutDir" style="border:3px dotted; height:3em;">
[ここに生成されたメールを保存するフォルダをドロップ]
</p>
<button onclick="onGenerate();">生成!</button>
</body>
</html>