From 6e0d48ec571628a2e0dd1047b3760e50a0351573 Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 27 Feb 2022 05:51:25 +0100 Subject: [PATCH] Refactor popup logic --- pages/popup/popup.css | 1 + pages/popup/popup.js | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pages/popup/popup.css b/pages/popup/popup.css index f7c89db4..a23c92eb 100644 --- a/pages/popup/popup.css +++ b/pages/popup/popup.css @@ -392,6 +392,7 @@ input:checked + .slider:hover { color: #a5a5a5; font-style: italic; font-weight: 400; + padding-left: 5px; } #popup-incomplete-translation { diff --git a/pages/popup/popup.js b/pages/popup/popup.js index 2e6a02b2..f3935834 100644 --- a/pages/popup/popup.js +++ b/pages/popup/popup.js @@ -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'.