-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
136 lines (119 loc) · 4.26 KB
/
index.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
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>VisiBible -> Holyrics</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
</head>
<body translate="no">
<div class="container">
<div class="row">
<div class="col-12 pt-3">
<h1>
VisioBible -> Holyrics
</h1>
<details class="mb-3 pt-3">
<summary>Инструкция</summary>
<p>
В первую очередь нужна версия VisioBible 2.4. Экспортируй песенник в текстовый файл. Затем загрузи этот файл сюда.
</p>
<p>
<img src="screenshot_vb-export.png" class="mw-100 rounded shadow-sm">
</p>
<p>
Полученый архив распакуй и импортируй через пункт <i>Песни</i> -> <i>Импортировать</i> -> <i>Другое</i> -> <i>TXT File (UTF-8)</i>
</p>
<p>
<img src="screenshot_holyrics-import.png" class="mw-100 rounded shadow-sm">
</p>
</details>
<p class="alert alert-secondary">
Файл обрабатывается локально в браузере. Никакие данные не отправляются на сервер.
</p>
<input type="file" accept="text/plain" class="form-control mb-3 js-file">
<div class="js-process d-none">
<p>
Найдено <b class="js-processed-count">0</b> песен.
</p>
<p>
<a class="btn btn-primary w-100 js-download">
Скачать архив
</a>
</p>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script>
const fileInput = document.querySelector(".js-file");
const processContainer = document.querySelector(".js-process");
const countContainer = document.querySelector(".js-processed-count");
const downloadButton = document.querySelector(".js-download");
const getFileContent = (file) =>
new Promise((resolve, _) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsText(file);
});
const parseTextToSongs = (text) => {
const resultSongs = [];
const songs = ("\n\n" + text).replace(/\r/g, "").split(/\n\n\d+\.\s/g);
for (const song of songs) {
const rows = song.split("\n");
const title = rows.shift().trim();
const songRows = rows
.map((row) => row.trim())
.join("\n")
.replace(/\n +/g, "\n")
.replace(/#([^\n]+)/g, "##($1)")
.replace(/\n{2,}/g, "\n\n")
.replace(/^\n+/g, "")
.replace(/ +/g, " ")
.replace(/ +/g, " ")
.replace(/^ */g, "")
.replace(/\n */g, "\n")
.replace(/ *\n/g, "\n")
.replace(/^d+. */g, "")
.replace(/\nd+. */g, "\n");
const firstRow = (
songRows
.split("\n")
.filter((row) => !row.includes("#") && row.length > 5)
.shift() || ""
).replace(/[.,!?-]$/g, "");
if (title || songRows) {
resultSongs.push({
title,
firstRow,
text: songRows
});
}
}
return resultSongs;
};
const handleFileSelect = async () => {
const file = fileInput.files[0];
if (!file) {
return;
}
const fileContent = await getFileContent(file);
const songsArray = parseTextToSongs(fileContent);
countContainer.innerText = songsArray.length;
const zip = new JSZip();
for (const song of songsArray) {
const fileName = `${song.title}${
song.firstRow ? ` (${song.firstRow})` : ""
}.txt`;
zip.file(fileName, song.text);
}
const zipBlob = await zip.generateAsync({ type: "blob" });
downloadButton.href = URL.createObjectURL(zipBlob);
downloadButton.download = `${file.name.replace(/\.txt$/i, "").replace(/\s/ig, "_")}_VisioBible2Holyrics_${Date.now()}.zip`;
processContainer.classList.remove("d-none");
};
fileInput.addEventListener("change", handleFileSelect);
</script>
</body>
</html>