-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
148 lines (129 loc) · 4.56 KB
/
script.js
File metadata and controls
148 lines (129 loc) · 4.56 KB
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
// Resolution mapping object
const resolutionMap = {
'2': '1024x600',
'3': '768x1024',
'5': '1600x720',
'7': '1280x720',
'R': '1920x860',
'B': '1920x1200',
'D': '2000x1200'
};
// Validation functions
function validateModelName(modelName) {
// Model name should be 5 characters
return modelName.length === 5;
}
function validateCompany(company) {
// Company should be 3 characters
return company.length === 3;
}
function validateSpecs(specs) {
// Specs should be 8 characters (S + 7 digits)
return specs.length === 8;
}
function validateDate(date) {
// Date should be 8 characters (YYYYMMDD)
return date.length === 8;
}
function validateTime(time) {
// Time should be 6 characters (HHMMSS)
return time.length === 6;
}
function validateBuildId(buildId) {
// Build ID should be 4 characters
return buildId.length === 4;
}
function validateVersion(version) {
// Version should be 3 characters
return version.length === 3;
}
// Function to decode the firmware code
function decodeFirmware() {
const code = document.getElementById('firmwareCode').value.trim();
if (!code) {
alert('Por favor, insira um código de firmware');
return;
}
try {
// Validate the structure using regex
const firmwarePattern = /^[^_]+_[^_]+_[^_]+\.\d+\.\d+\.[A-Z0-9]+\.[A-Z0-9]+$/;
if (!firmwarePattern.test(code)) {
throw new Error('Formato inválido: o código deve seguir o padrão MODELO_EMPRESA_ESPECIFICACOES.DATA.HORA.BUILD.VERSAO');
}
// Split the code into main parts
const [modelPart, company, specs] = code.split('_');
const [specsPart, datePart, timePart, buildPart, versionPart] = specs.split('.');
// Extract model name
const modelName = modelPart;
// Parse the specifications
const gsmService = specsPart[1] === '1' ? 'Without GSM' : 'With GSM';
const screenOrientation = specsPart[2] === '1' ? 'Landscape' : 'Portrait';
const resolution = resolutionMap[specsPart[3]] || 'Unknown Resolution';
const unknownNumbers = specsPart.substring(4, 7);
// Parse the date
const year = datePart.substring(0, 4);
const month = datePart.substring(4, 6);
const day = datePart.substring(6, 8);
const formattedDate = `${year}-${month}-${day}`;
// Format time (HHMMSS)
const hours = timePart.substring(0, 2);
const minutes = timePart.substring(2, 4);
const seconds = timePart.substring(4, 6);
const formattedTime = `${hours}:${minutes}:${seconds}`;
// Create the decoded object
const decoded = {
modelName,
company,
specifications: {
gsmService,
screenOrientation,
resolution,
unknownNumbers
},
creationDate: formattedDate,
buildInfo: {
time: formattedTime,
buildId: buildPart,
version: versionPart
}
};
// Display the results
displayResults(decoded);
} catch (error) {
alert(error.message);
}
}
// Function to display the results
function displayResults(decoded) {
const resultDiv = document.getElementById('result');
const contentDiv = document.getElementById('decodedContent');
contentDiv.innerHTML = `
<div class="mb3">
<span class="b">Model Name:</span> ${decoded.modelName}
</div>
<div class="mb3">
<span class="b">Company:</span> ${decoded.company}
</div>
<div class="mb3">
<span class="b">Specifications:</span>
<ul class="pl4 mt2">
<li>GSM Service: ${decoded.specifications.gsmService}</li>
<li>Screen Orientation: ${decoded.specifications.screenOrientation}</li>
<li>Resolution: ${decoded.specifications.resolution}</li>
<li>Unknown Numbers: ${decoded.specifications.unknownNumbers}</li>
</ul>
</div>
<div class="mb3">
<span class="b">Creation Date:</span> ${decoded.creationDate}
</div>
<div class="mb3">
<span class="b">Build Information:</span>
<ul class="pl4 mt2">
<li>Build Time: ${decoded.buildInfo.time}</li>
<li>Build ID: ${decoded.buildInfo.buildId}</li>
<li>Version: ${decoded.buildInfo.version}</li>
</ul>
</div>
`;
resultDiv.style.display = 'block';
}