-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_capture.html
115 lines (106 loc) · 4.38 KB
/
add_capture.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>我が家の本棚</title>
<link rel="stylesheet" href="css/destyle.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/loader.css">
<script src="js/main.js"></script>
<script src="js/util.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2/dist/quagga.min.js"></script>
<script>
function registerBooksFromCamera() {
const overlay = document.getElementById("overlay");
overlay.style.display = "block";
Quagga.init({
inputStream: {
name: "Live",
type: "LiveStream",
target: document.querySelector("#photo-area"),
constraints: {
width: 640,
height: 480,
decodeBarCodeRate: 3,
successTimeout: 800,
codeRepetition: true,
tryVertical: false,
frameRate: 15,
facingMode: "environment"
}
},
decoder: {
readers: [
"ean_reader"
]
},
}, function (err) {
if (err) {
console.log(err);
return;
}
Quagga.start();
});
let codeBefore;
let successCount = 0;
Quagga.onDetected(success => {
const code = success.codeResult.code;
if (code.startsWith("978")) {
if (code === codeBefore) {
successCount++;
} else {
codeBefore = code;
}
if (successCount === 3) {
let codeArray = code.split("").map(n => parseInt(n));
let remainder = 0;
const checkDigit = codeArray.pop();
codeArray.forEach((num, index) => {
remainder += num * (index % 2 === 0 ? 1 : 3);
});
remainder %= 10;
remainder = remainder === 0 ? 0 : 10 - remainder;
if (checkDigit === remainder) {
Quagga.stop();
const resp = registerISBN(code);
if (resp === "Noexist") {
alert("入力されたISBNの書籍はデータベース上に存在していないため、登録できません");
} else if (resp === "Already registered") {
alert("その書籍は既に登録されています")
}
overlay.style.display = "none";
}
}
}
});
}
</script>
</head>
<body>
<div id="bodyblock">
<h1>書籍登録ページ</h1>
<button class="generalButton" id="registerbook" onclick="registerBooksFromCamera()">書籍を登録する</button>
<div id="overlay">
<div id="overlaywrapper">
<h3 style="color: white;">カメラにISBNバーコードを写してください</h3>
<div id="photo-area" class="viewport"></div>
</div>
</div>
<h3>登録済み書籍</h3>
<div id="registeredbooks">
<!--placeholder-->
<!-- <div class="book">
<span class="bookkey">ISBN: </span><span class="isbnval">9764798160054</span><br>
<span class="bookkey">書名: </span><span class="titleval">図解まるわかり サーバーのしくみ</span><br>
<span class="bookkey">著者: </span><span class="authorval">西村泰洋</span><br>
<button class="remove">削除する</button>
</div> -->
</div>
<div id="postbooksection">
<div class="loader" id="postloader"></div>
<button class="generalButton" id="postbook" onclick="postBook('write')">送信する</button>
</div>
</div>
</body>
</html>