-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
152 lines (135 loc) · 4.35 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<!--
formato immagini(nome file): lato + numero + .png
lato: L o R
numero: da 1 in su
copyright 2022 Samuele Facenda
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Image catalogger</h1>
<img alt="image">
<br>
<br>
<button onclick="isLetter('h')">h</button>
<button onclick="isLetter('s')">s</button>
<button onclick="isLetter('u')">u</button>
<button onclick="isLetter('none')">none</button>
<br>
<br>
<button onclick="download()">download json</button>
<button onclick="saveOnServer()">save on server</button>
<br>
<br>
<button onclick="setLato('L')">left</button>
<button onclick="setLato('R')">right</button>
<br>
<br>
<div id="image_status"></div>
<div id="image_name"></div>
<br>
<br>
<form id="upload">
<label for="file">File to upload</label>
<input type="file" id="file" accept=".json">
<button>Upload</button>
</form>
<br>
<br>
<input type="number" id="image_number" value="0" min="0" onchange="changeNumber()">
<script>
var lato = 'L';
var data = {};
var num = 0;
function download() {
let filename = 'data.json';
let text = JSON.stringify(data);
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function setImageStatus(done){
if (done)
document.getElementById("image_status").innerHTML = "already processed";
else
document.getElementById("image_status").innerHTML = "not processed";
}
function setLato(l){
lato = l;
loadImg();
}
function setImageName(name){
document.getElementById("image_name").innerHTML = name;
}
//file upload
function logFile (event) {
let str = event.target.result;
let json = JSON.parse(str);
console.log('string', str);
console.log('json', json);
data = json;
}
function uploadFile(event){
event.preventDefault();
let reader = new FileReader();
reader.onload = logFile;
// Read the file
reader.readAsText(file.files[0]);
}
let form = document.querySelector('#upload');
let file = document.querySelector('#file');
form.addEventListener('submit', uploadFile);
//image processing and changing
function loadImg(){
let filename = 'images/' + lato + num + '.png';
console.log(filename);
let img = document.querySelector('img');
img.src = filename;
img.style.height = '200px';
img.style.width = '200px';
setImageName(filename);
if (data[filename] != undefined){
setImageStatus(true);
} else {
setImageStatus(false);
}
}
function isLetter(letter){
let filename = 'images/' + lato + num + '.png';
if (num !== 0)
data[filename] = letter;
num++;
let n = document.querySelector('#image_number');
n.value = num;
loadImg();
}
function changeNumber(){
//get the content of image_number
let n = document.querySelector('#image_number');
num = n.value;
loadImg();
}
function saveOnServer(){
//make a post request to the server at the page save.php
let url = 'save.php';
fetch(url, {
method: 'POST',
body: JSON.stringify(data)
}).then(response => response.text())
.then(data => {
console.log('Success:', data);
})
}
</script>
</body>
</html>