-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (70 loc) · 1.82 KB
/
index.js
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
let beforeTxt,
middleTxt,
afterTxt,
firstnbs = [],
secondnbs = [],
coords = [],
files = [];
//function to remove regex characters
String.prototype.noRegex = function () {
return this.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
$(function () {
$("#beforeTxt").change(function () {
beforeTxt = $(this).val();
});
$("#middleTxt").change(function () {
middleTxt = $(this).val();
});
$("#afterTxt").change(function () {
afterTxt = $(this).val();
});
$("#beforeTxt,#middleTxt,#afterTxt").change();
$("#filepicker").change(function (event) {
files = [...event.target.files];
if (files.length === 0 || middleTxt == "") return;
getNbs(files);
});
$("#filepickerAdd").change(function (event) {
files.extend([...event.target.files]);
if (files.length === 0 || middleTxt == "") return;
getNbs(files);
});
});
const getNbs = (files) => {
for (const file of files) {
const rgx = new RegExp(
`(?<=${beforeTxt.noRegex()})-?\\d+${middleTxt.noRegex()}-?\\d+(?=${afterTxt.noRegex()})`,
"u"
);
let nbs = file.name.match(rgx)[0].split(middleTxt);
firstnbs.push(nbs[0]);
secondnbs.push(nbs[1]);
coords.push(nbs[0] + "-" + nbs[1]);
}
createTable(
Math.min(...firstnbs),
Math.max(...firstnbs),
Math.min(...secondnbs),
Math.max(...secondnbs)
);
};
const createTable = (firstRow, lastRow, firstColumn, lastColumn) => {
let txt = "";
for (let i = firstRow; i <= lastRow; i++) {
txt += "<li class='row " + i + "'><ul class='inside'> ";
for (let j = firstColumn; j <= lastColumn; j++) {
txt += "<li class='case inColumn " + j;
if (coords.includes(i + "-" + j)) txt += " black";
txt += "'> </li>";
}
txt += "</ul></li>";
}
$("ul.container").html(txt);
};
Array.prototype.extend = function (arr) {
if (arr.constructor !== Array) return;
arr.forEach(function (v) {
this.push(v);
}, this);
};