Refactor popup logic

This commit is contained in:
nobody 2022-02-27 05:51:25 +01:00
parent 7e64f82220
commit 6e0d48ec57
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
2 changed files with 25 additions and 16 deletions

View File

@ -392,6 +392,7 @@ input:checked + .slider:hover {
color: #a5a5a5;
font-style: italic;
font-weight: 400;
padding-left: 5px;
}
#popup-incomplete-translation {

View File

@ -423,24 +423,12 @@ popup._createInjectionElement = function (injection) {
injectionElement.appendChild(nameTextNode);
if (injection.versionRequested !== null) {
noteElement = document.createElement('span');
noteElement.setAttribute('class', 'side-note');
let versionNode;
if (injection.versionRequested === undefined || injection.versionDelivered === undefined) {
versionNode = '';
} else if (injection.versionRequested === injection.versionDelivered) {
versionNode = ` v${injection.versionRequested}`;
} else if (injection.versionRequested === 'beta') {
versionNode = ` ${injection.versionRequested}`;
} else if (injection.versionRequested !== 'latest') {
versionNode = ` (v${injection.versionRequested} » v${injection.versionDelivered})`;
} else if (injection.versionRequested === 'latest') {
versionNode = ` v${injection.versionDelivered}`;
} else {
versionNode = '';
}
noteElement = document.createElement('span');
noteElement.setAttribute('class', 'side-note');
versionNode = popup._createVersionNode(injection.versionRequested, injection.versionDelivered);
noteTextNode = document.createTextNode(versionNode);
noteElement.appendChild(noteTextNode);
injectionElement.appendChild(noteElement);
@ -449,6 +437,26 @@ popup._createInjectionElement = function (injection) {
return injectionElement;
};
popup._createVersionNode = function (versionRequested, versionDelivered) {
let version = '';
if (versionRequested === undefined || versionDelivered === undefined) {
version = '';
} else if (versionRequested === versionDelivered && versionDelivered !== 'latest') {
version = `v${versionRequested}`;
} else if (versionRequested === versionDelivered) {
version = `v${versionRequested}`;
} else if (versionRequested === 'beta') {
version = `(${versionRequested} » v${versionDelivered})`;
} else if (versionRequested !== 'latest') {
version = `(v${versionRequested} » v${versionDelivered})`;
} else if (versionRequested === 'latest') {
version = `v${versionDelivered}`;
}
return version;
};
popup._filterDuplicates = function (array, key) {
/**
* Function to remove duplicates from an array, depending on 'key'.