From 80823ddf659ba5037c264803a1b0e0f7d74e3cc3 Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Tue, 4 Aug 2020 06:47:39 +0200 Subject: [PATCH] ui --- extension/common.js | 18 ++++---- extension/data/popup/index.css | 5 +-- extension/data/popup/index.html | 3 +- extension/data/popup/index.js | 73 +++++++++++++++++---------------- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/extension/common.js b/extension/common.js index 4bae2b9..72dfce2 100644 --- a/extension/common.js +++ b/extension/common.js @@ -416,28 +416,26 @@ chrome.contextMenus.onClicked.addListener(info => chrome.storage.local.set({ /* FAQs & Feedback */ { - const {onInstalled, setUninstallURL, getManifest} = chrome.runtime; - const {name, version} = getManifest(); - const page = getManifest().homepage_url; + const {management, runtime: {onInstalled, setUninstallURL, getManifest}, storage, tabs} = chrome; if (navigator.webdriver !== true) { + const page = getManifest().homepage_url; + const {name, version} = getManifest(); onInstalled.addListener(({reason, previousVersion}) => { - chrome.storage.local.get({ + management.getSelf(({installType}) => installType === 'normal' && storage.local.get({ 'faqs': true, 'last-update': 0 }, prefs => { if (reason === 'install' || (prefs.faqs && reason === 'update')) { const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45; if (doUpdate && previousVersion !== version) { - chrome.tabs.create({ - url: page + '?version=' + version + - (previousVersion ? '&p=' + previousVersion : '') + - '&type=' + reason, + tabs.create({ + url: page + '?version=' + version + (previousVersion ? '&p=' + previousVersion : '') + '&type=' + reason, active: reason === 'install' }); - chrome.storage.local.set({'last-update': Date.now()}); + storage.local.set({'last-update': Date.now()}); } } - }); + })); }); setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version); } diff --git a/extension/data/popup/index.css b/extension/data/popup/index.css index fb59866..8549949 100644 --- a/extension/data/popup/index.css +++ b/extension/data/popup/index.css @@ -93,8 +93,7 @@ select { } #list { overflow: auto; - height: 268px; - margin-bottom: 16px; + height: 240px; color: #000; background-position: top 120px center; background-repeat: no-repeat; @@ -177,7 +176,7 @@ select { #agent { white-space: nowrap; display: grid; - grid-template-columns: repeat(7, 1fr); + grid-template-columns: repeat(4, 1fr); grid-gap: 1px; } diff --git a/extension/data/popup/index.html b/extension/data/popup/index.html index 8bed3c0..0cfe9ab 100644 --- a/extension/data/popup/index.html +++ b/extension/data/popup/index.html @@ -121,12 +121,13 @@
-
+
+
diff --git a/extension/data/popup/index.js b/extension/data/popup/index.js index 59d6889..bbdc7a7 100644 --- a/extension/data/popup/index.js +++ b/extension/data/popup/index.js @@ -43,45 +43,46 @@ function update(ua) { tbody.textContent = ''; parent.dataset.loading = true; - fetch('browsers/' + browser.toLowerCase() + '-' + os.toLowerCase().replace(/\//g, '-') + '.json').then(r => r.json()).catch(e => { - console.error(e); - return []; - }).then(list => { - if (list) { - const fragment = document.createDocumentFragment(); - let radio; - for (const o of sort(list)) { - const clone = document.importNode(t.content, true); - const second = clone.querySelector('td:nth-child(2)'); - second.title = second.textContent = o.browser.name + ' ' + (o.browser.version || ' '); - const third = clone.querySelector('td:nth-child(3)'); - third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' '); - const forth = clone.querySelector('td:nth-child(4)'); - forth.title = forth.textContent = o.ua; - if (o.ua === ua) { - radio = clone.querySelector('input[type=radio]'); + fetch('browsers/' + browser.toLowerCase() + '-' + os.toLowerCase().replace(/\//g, '-') + '.json') + .then(r => r.json()).catch(e => { + console.error(e); + return []; + }).then(list => { + if (list) { + const fragment = document.createDocumentFragment(); + let radio; + for (const o of sort(list)) { + const clone = document.importNode(t.content, true); + const second = clone.querySelector('td:nth-child(2)'); + second.title = second.textContent = o.browser.name + ' ' + (o.browser.version || ' '); + const third = clone.querySelector('td:nth-child(3)'); + third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' '); + const forth = clone.querySelector('td:nth-child(4)'); + forth.title = forth.textContent = o.ua; + if (o.ua === ua) { + radio = clone.querySelector('input[type=radio]'); + } + fragment.appendChild(clone); } - fragment.appendChild(clone); - } - tbody.appendChild(fragment); - if (radio) { - radio.checked = true; - radio.scrollIntoView({ - block: 'center', - inline: 'nearest' + tbody.appendChild(fragment); + if (radio) { + radio.checked = true; + radio.scrollIntoView({ + block: 'center', + inline: 'nearest' + }); + } + document.getElementById('custom').placeholder = `Filter among ${list.length}`; + [...document.getElementById('os').querySelectorAll('option')].forEach(option => { + option.disabled = (map.matching[browser.toLowerCase()] || []).indexOf(option.value.toLowerCase()) === -1; }); } - document.getElementById('custom').placeholder = `Filter among ${list.length}`; - [...document.getElementById('os').querySelectorAll('option')].forEach(option => { - option.disabled = (map.matching[browser.toLowerCase()] || []).indexOf(option.value.toLowerCase()) === -1; - }); - } - else { - throw Error('OS is not found'); - } - }).finally(() => { - parent.dataset.loading = false; - }); + else { + throw Error('OS is not found'); + } + }).finally(() => { + parent.dataset.loading = false; + }); } document.getElementById('browser').addEventListener('change', e => chrome.storage.local.set({