-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
77 lines (63 loc) · 2.79 KB
/
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
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
function updateFlagOptions() {
const mainCategory = document.getElementById("mainCategory").value;
const flagDropdown = document.getElementById("flagOptions");
flagDropdown.innerHTML = '';
const options = flagCategories[mainCategory];
options.forEach(option => {
const opt = document.createElement("option");
opt.value = option.value;
opt.textContent = option.name;
flagDropdown.appendChild(opt);
});
}
window.onload = function() {
updateFlagOptions();
};
function checkFlags() {
const selectedCategory = document.getElementById('flagOptions').value;
const selectedFlags = flags[selectedCategory];
const inputFlag = parseInt(document.getElementById('flagInput').value);
if (isNaN(inputFlag)) {
alert('Please enter a valid number!');
return;
}
const inputValueDisplay = document.getElementById('inputValueDisplay');
inputValueDisplay.textContent = `Flags included for bitmask value: ${inputFlag}`;
const flagsIncluded = selectedFlags.filter(flag => (inputFlag & flag.bit) !== 0);
const flagList = document.getElementById('flagList');
flagList.innerHTML = '';
const combinedList = document.getElementById('combinedList');
combinedList.innerHTML = '';
if (flagsIncluded.length > 0) {
flagsIncluded.forEach(flag => {
const listItem = document.createElement('li');
listItem.textContent = `${flag.bit} - ${flag.name}`;
flagList.appendChild(listItem);
});
document.getElementById('inputValueDisplay').scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// Create the list of flags in the (flag1 | flag2 | flag3 | flag4) format
const flagNames = flagsIncluded.map(flag => flag.bit);
const addFlag = `|${flagNames.join('|')}`;
const removeFlag = `&~(${flagNames.join('|')})`
// Display the formatted flags
const flagHeader = document.createElement('h4');
flagHeader.textContent = 'Add/Remove the listed flags';
combinedList.appendChild(flagHeader);
const flagStringElement = document.createElement('li');
flagStringElement.textContent = `\`${selectedCategory}\`=\`${selectedCategory}\`${addFlag}`;
combinedList.appendChild(flagStringElement);
const removeFlagString = document.createElement('li');
removeFlagString.textContent = `\`${selectedCategory}\`=\`${selectedCategory}\`${removeFlag}`;
combinedList.appendChild(removeFlagString);
} else if (flagsIncluded.length == 0) {
alert('Value must be greater than 0!');
return;
} else {
const listItem = document.createElement('li');
listItem.textContent = 'No flags found';
flagList.appendChild(listItem);
}
}