-
Notifications
You must be signed in to change notification settings - Fork 58
/
script.js
38 lines (28 loc) · 989 Bytes
/
script.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
$(function () {
$("#generate").click(function () {
$("#sn").val(generateSerial($("#model").val()));
});
$.getJSON("synology.json", function(json) {
$("#model").empty();
$("#model").append($('<option>').text("Select model"));
$.each(json, function(i, obj){
$("#model").append($('<option>').text(obj.model).attr('value', obj.permanent));
});
});
});
function generateMac() {
return "001132" + random(10, 16777215).toString(16).toUpperCase();
}
function generateSerial(permanent) {
if(permanent == "Select model")
return "Please select a model first!";
return (random(11,14) + "30" + permanent + "n0" + random(0,2) + padLeft(random(1,9999),4)).toUpperCase();
}
function padLeft(nr, n) {
return Array(n - String(nr).length + 1).join('0') + nr;
}
function random(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}