-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.html
98 lines (95 loc) · 2.88 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Web-Z39.50 Demo</title>
<link rel="stylesheet" href="style.css">
<style>
form * {
margin: 5px;
}
textarea {
display: block;
}
input[type=radio] {
margin-left: 20px;
}
</style>
</head>
<body>
<header>
<h1>Web-Z39.50 Demo</h1>
</header>
<main>
<section>
<form>
<label for="isbn_list">Searched <abbr title="International Standard Book Number">ISBN</abbr> (one per line):</label>
<textarea id="isbn_list" name="isbn_list"></textarea>
<label for="server">Z39.50 Server:</label><input type="text" name="server" id="server">
<p>Desired MARC output format:</p>
<input type="radio" name="flavour" value="usmarc" checked>MARC 21<br>
<input type="radio" name="flavour" value="unimarc">UNIMARC<br>
<input type="submit" value="Submit" id="ok">
</form>
</section>
</main>
<footer>
Developed by Clément CORBIN - <a href="https://github.com/corbin-c/web-z3950/" title="web-z3950 by corbin-c on Github">View code on Github</a>
</footer>
</body>
<script type="module">
const SEPARATOR = "\\u001d";
const LIMIT = 100;
let server = document.querySelector("#server");
let isbn = document.querySelector("#isbn_list");
server.value = (window.location.search == "?sudoc")
?"carmin.sudoc.abes.fr:10646/abes-z39-public":"";
let button = document.querySelector("#ok");
let output = (filename, data, type) => {
var a = window.document.createElement('a');
a.setAttribute("target","_blank");
a.href = window.URL.createObjectURL(new Blob([data], {type: type}));
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
let shrinkArray = (array, limit) => {
let output = [];
for (let i=0;i<array.length;i=i+limit) {
output.push(array.slice(i,i+limit));
}
return output;
}
button.addEventListener("click", async (e) => {
e.preventDefault();
let format = [...document.querySelectorAll("input[type=radio]")]
.filter(e => e.checked == true)[0].value;
let list = shrinkArray(isbn.value.split("\n").filter(e => e != ""),LIMIT);
let out = [];
let err = [];
console.log(list);
await Promise.all(list.map(async f => {
let url = window.location.origin+"/?server="+server.value
+"&format="+format
+"&isbn="+f.join(",");
url = await fetch(url);
try {
let empty = url.headers.get("Void").split(",").filter(e => e != "");
if (empty.length > 0) {
err.push(...empty);
}
} catch {
console.warn("no Void header");
}
url = await url.text();
out.push(url);
}));
alert(err.join(","));
output("results.mrc",
out.filter(e => e != "").join(JSON.parse('"'+SEPARATOR+'"')),
"application/octet-stream");
});
</script>
</html>