This commit is contained in:
Ray Lothian 2019-08-01 06:41:28 +01:00
parent 03501a14ff
commit 3e947f5f80
3 changed files with 22 additions and 12 deletions

View file

@ -80,6 +80,7 @@ select {
} }
#list { #list {
overflow: auto; overflow: auto;
scroll-behavior: smooth;
height: 300px; height: 300px;
margin-bottom: 10px; margin-bottom: 10px;
color: #000; color: #000;

View file

@ -2,7 +2,7 @@
document.body.dataset.android = navigator.userAgent.indexOf('Android') !== -1; document.body.dataset.android = navigator.userAgent.indexOf('Android') !== -1;
var map = {}; const map = {};
function sort(arr) { function sort(arr) {
function sort(a = '', b = '') { function sort(a = '', b = '') {
@ -33,7 +33,7 @@ function sort(arr) {
return list; return list;
} }
function update() { function update(ua) {
const browser = document.getElementById('browser').value; const browser = document.getElementById('browser').value;
const os = document.getElementById('os').value; const os = document.getElementById('os').value;
@ -49,6 +49,7 @@ function update() {
}).then(list => { }).then(list => {
if (list) { if (list) {
const fragment = document.createDocumentFragment(); const fragment = document.createDocumentFragment();
let radio;
for (const o of sort(list)) { for (const o of sort(list)) {
const clone = document.importNode(t.content, true); const clone = document.importNode(t.content, true);
const second = clone.querySelector('td:nth-child(2)'); const second = clone.querySelector('td:nth-child(2)');
@ -57,9 +58,19 @@ function update() {
third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' '); third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' ');
const forth = clone.querySelector('td:nth-child(4)'); const forth = clone.querySelector('td:nth-child(4)');
forth.title = forth.textContent = o.ua; 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); tbody.appendChild(fragment);
if (radio) {
radio.checked = true;
radio.scrollIntoView({
block: 'center',
inline: 'nearest'
});
}
document.getElementById('custom').placeholder = `Filter among ${list.length} "User-Agent" strings`; document.getElementById('custom').placeholder = `Filter among ${list.length} "User-Agent" strings`;
[...document.getElementById('os').querySelectorAll('option')].forEach(option => { [...document.getElementById('os').querySelectorAll('option')].forEach(option => {
option.disabled = map.matching[browser.toLowerCase()].indexOf(option.value.toLowerCase()) === -1; option.disabled = map.matching[browser.toLowerCase()].indexOf(option.value.toLowerCase()) === -1;
@ -106,7 +117,13 @@ document.addEventListener('DOMContentLoaded', () => fetch('./map.json').then(r =
document.querySelector('#os optgroup:last-of-type').appendChild(f2); document.querySelector('#os optgroup:last-of-type').appendChild(f2);
document.getElementById('os').value = localStorage.getItem('os') || 'Windows'; document.getElementById('os').value = localStorage.getItem('os') || 'Windows';
update(); chrome.storage.local.get({
ua: ''
}, prefs => {
const ua = prefs.ua || navigator.userAgent;
update(ua);
document.getElementById('ua').value = ua;
});
})); }));
document.getElementById('list').addEventListener('click', ({target}) => { document.getElementById('list').addEventListener('click', ({target}) => {
@ -128,9 +145,6 @@ document.getElementById('custom').addEventListener('keyup', ({target}) => {
.forEach(tr => tr.dataset.matched = tr.textContent.toLowerCase().indexOf(value.toLowerCase()) !== -1); .forEach(tr => tr.dataset.matched = tr.textContent.toLowerCase().indexOf(value.toLowerCase()) !== -1);
}); });
chrome.storage.local.get({
ua: ''
}, prefs => document.getElementById('ua').value = prefs.ua || navigator.userAgent);
chrome.storage.onChanged.addListener(prefs => { chrome.storage.onChanged.addListener(prefs => {
if (prefs.ua) { if (prefs.ua) {
document.getElementById('ua').value = prefs.ua.newValue || navigator.userAgent; document.getElementById('ua').value = prefs.ua.newValue || navigator.userAgent;

View file

@ -54,10 +54,5 @@
"match_about_blank": true, "match_about_blank": true,
"matches": ["*://*/*"], "matches": ["*://*/*"],
"js": ["data/inject.js"] "js": ["data/inject.js"]
}], }]
"applications": {
"gecko": {
"id": "{a6c4a591-f1b2-4f03-b3ff-767e5bedf4e7}"
}
}
} }