-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
300 lines (287 loc) · 10.2 KB
/
main.html
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" name="google" content="notranslate"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css" id="jsonMaker">
<!--
table{
width:100%;
text-align:center;
}
#transferArea>textarea{
height:90%;
}
textarea{
width:97%;
font-size:2em;
}
button{
font-size:4em;
color:#fff;
background-color:#f00;
border:0px;
width:100%;
height:100%;
}
label {
display:inline;
width:8em;
font-size:2em;
display: inline-block;
padding: 10px 0px;
border: 1px solid transparent;
border-radius: 4px;
background-color: #007bff;
color: white;
font-weight: 400;
text-align: center;
text-decoration: none;
cursor: pointer;
transition: background-color 0.2s;
}
label:hover {
background-color: #0056b3;
}
input[type="button"]{display:none;}
-->
</style>
</head>
<!----------------------------------------------------------------------------->
<body class="notranslate">
<div id="transferArea">
<table id="PPTstructure" border="1"></table>
</div>
<br>
<div id="UI">
<label>添加歌曲<input type="button" onclick="addSong()"/></label>
<br>
<br>
<label style="width:4em;">
匯入
<input type="file" id="fileSelector" style="display:none;" onchange="input(this)"/>
</label>
<label style="width:4em;">匯出<input type="button" onclick="output()"/></label>
<br>
<br>
<label>開始播放<input type="button" onclick="start()"/></label>
</div>
<script language="javascript" id="song_ans_page">
<!--
function addSong(){
let table=document.getElementById("PPTstructure");
let row=table.insertRow(-1);
for(let j=0;j<3;j++){
let cell=row.insertCell(j);
cell.innerHTML=" ";
}
row.cells[0].rowSpan=2;
row.cells[0].style.width="5em";
row.cells[0].innerHTML='<input type="text" placeholder="歌名" style="font-size:3em;width:4em;"/>';
row.cells[0].innerHTML+='<br><br>';
row.cells[0].innerHTML+='<input type="text" placeholder="背景網址"/>';
let obj='<label>添加歌詞段落<input type="button" onclick="addPage(this)"/></label>';
row.cells[1].innerHTML=obj;
row.cells[2].innerHTML='<button type="button" onclick="deletSong(this)">×</button>';
row=table.insertRow(-1);
for(let j=0;j<2;j++){
let cell=row.insertCell(j);
cell.innerHTML=" ";
}
row.cells[0].innerHTML='<textarea placeholder="請輸入段落歌詞" rows="5"></textarea>';
row.cells[1].innerHTML='<button type="button" onclick="deletRow(this)">×</button>';
}
function addPage(obj){
let row=obj.parentNode.parentNode.parentNode;
row.cells[0].rowSpan+=1;
let table=document.getElementById("PPTstructure");
let rowNum=obj.parentNode.parentNode.parentNode.rowIndex;
rowNum+=row.cells[0].rowSpan-1;
table.insertRow(rowNum)
row=table.rows[rowNum];
for(let j=0;j<2;j++){
let cell=row.insertCell(j);
cell.innerHTML=" ";
}
row.cells[0].innerHTML='<textarea placeholder="請輸入段落歌詞"rows="5"></textarea>';
row.cells[1].innerHTML='<button type="button" onclick="deletRow(this)">×</button>';
}
function deletRow(obj){
let table=document.getElementById("PPTstructure");
let rowNum=obj.parentNode.parentNode.rowIndex;
while(table.rows[rowNum].cells.length!=3)
{rowNum--;}
table.rows[rowNum].cells[0].rowSpan-=1;
obj.parentNode.parentNode.remove();
}
function deletSong(obj){
let table=document.getElementById("PPTstructure");
let rowNum=obj.parentNode.parentNode.rowIndex;
rowNum+=obj.parentNode.parentNode.firstElementChild.rowSpan-1;
while(table.rows[rowNum].cells.length!=3){
table.rows[rowNum].remove();
rowNum--;
}
table.rows[rowNum].remove();
}
-->
</script>
<script language="javascript" id="input_and_output">
function download(data, filename = '匯出.json') {
// 將對象轉為 JSON 字串
let jsonString = JSON.stringify(data, null, 2);
// 創建一個 Blob 對象
let blob = new Blob([jsonString], { type: 'application/json' });
// 創建一個 URL 對象
let url = URL.createObjectURL(blob);
// 創建一個隱藏的下載連結
let a = document.createElement('a');
a.href = url;
a.download = filename; // 指定下載文件的名稱
document.body.appendChild(a);
a.click(); // 模擬點擊連結以觸發下載
document.body.removeChild(a); // 移除連結
URL.revokeObjectURL(url); // 釋放內存
}
function table2value(){
let table=document.getElementById("PPTstructure");
let op=[];
let song={};
let lyrics=[];
for(let i=0;i<table.rows.length;i++){
if(table.rows[i].cells.length==3){
song["歌詞"]=lyrics;
lyrics=[]
op.push(song);
song={};
song["標題"]=table.rows[i].cells[0].firstChild.value;
song["背景"]=table.rows[i].cells[0].lastChild.value;
}
else{
lyrics.push(table.rows[i].cells[0].firstChild.value.split("\n"));
}
}
song["歌詞"]=lyrics;
op.push(song);
op.shift();
return(op);
}
function input(fileinfo){
let file = fileinfo.files[0];
let fReader = new FileReader();
fReader.onload = function (event){
lyricsFile=JSON.parse(event.target.result);
console.log(lyricsFile);
input2table(lyricsFile);
};
fReader.readAsText(file);
Clear();
}
function Clear()
{document.getElementById("fileSelector").style.display="none";}
function output(){
download(table2value());
}
function input2table(data){
let table=document.getElementById("PPTstructure");
table.innerHTML="";
let nowRow=-1;
let songRow=null;
for(let i=0;i<data.length;i++){
addSong();
nowRow++;
table.rows[nowRow].cells[0].firstChild.value=data[i]["標題"];
console.log(table.rows[nowRow].cells[0].firstChild);
table.rows[nowRow].cells[0].lastChild.value=data[i]["背景"];
songRow=nowRow;
nowRow++;
table.rows[nowRow].cells[0].firstChild.value=data[i]["歌詞"][0].join("\n");
for(let j=1;j<data[i]["歌詞"].length;j++){
table.rows[songRow].cells[1].firstChild.click();
nowRow++;
table.rows[nowRow].cells[0].firstChild.value=data[i]["歌詞"][j].join("\n");
}
}
}
</script>
<script language="javascript" id="start_PPT">
var childWindow=null;
var lyricsValue;
function start(){
document.getElementById("UI").style.display="none";
lyricsValue=table2value();
childWindow = window.open("show.html", "setPage", 'status=yes,toolbar=yes,menubar=yes,location=yes');
makeOrderTable();
}
function songLengthChack(){
let maxLen=[];
let nowSong=0;
let rowMax=0;
do{
if(lyricsValue[nowSong]['歌詞'].length>rowMax)
{rowMax=lyricsValue[nowSong]['歌詞'].length;}
if(nowSong%5==4){
maxLen.push(rowMax);
rowMax=0;
}
nowSong++;
}while(nowSong<lyricsValue.length);
if(nowSong%5!=4)
{maxLen.push(rowMax);}
return(maxLen);
}
function calcNeedRow(arr){
let op=0;
for(let i=0;i<arr.length;i++){
op+=2;
op+=arr[i];
}
return(op);
}
function makeOrderTable(){
let table=document.getElementById("PPTstructure");
table.innerHTML="";
table.style.width="100%";
table.style.height="100%";
table.style.fontSize="15px";
let maxLen=songLengthChack();
//let NeedRow=calcNeedRow(maxLen);
for(let i=0;i<maxLen.length;i++){
let row=table.insertRow(-1);
let cell=row.insertCell(0);
cell.colSpan=5;
cell.innerHTML=" ";
row=table.insertRow(-1);
for(let j=0;j<5;j++){
cell=row.insertCell(j);
cell.setAttribute("onclick",`sandMessage(${i*5+j},-1)`);
try
{cell.innerHTML=lyricsValue[i*5+j]['標題'];}
catch (error)
{cell.innerHTML="";}
}
for(let j=0;j<maxLen[i];j++){
row=table.insertRow(-1);
for(let k=0;k<5;k++){
cell=row.insertCell(k);
cell.setAttribute("onclick",`sandMessage(${i*5+k},${j})`);
try
{cell.innerHTML=lyricsValue[i*5+k]['歌詞'][j].join('<br>');}
catch (error)
{cell.innerHTML="";}
}
}
}
}
function sandMessage(songId,pageId){
let message={};
message["標題"]=lyricsValue[songId]["標題"];
message["背景"]=lyricsValue[songId]["背景"];
message["內容"]=lyricsValue[songId]["歌詞"][pageId];
if(pageId==-1)
{message["內容"]=[];}
childWindow.postMessage(JSON.stringify(message), "*");
}
</script>
</body>
</html>