update ua's from repo

This commit is contained in:
Ray Lothian 2020-08-04 07:02:57 +02:00
parent 80823ddf65
commit 492fefb170

View file

@ -33,6 +33,16 @@ function sort(arr) {
return list; return list;
} }
function get(path) {
return caches.open('agents').then(cache => {
const link = 'https://cdn.jsdelivr.net/gh/ray-lothian/UserAgent-Switcher/node/' + path;
cache.add(link);
return cache.match(link).then(resp => {
return resp || fetch(path);
});
});
}
function update(ua) { 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;
@ -43,7 +53,7 @@ function update(ua) {
tbody.textContent = ''; tbody.textContent = '';
parent.dataset.loading = true; parent.dataset.loading = true;
fetch('browsers/' + browser.toLowerCase() + '-' + os.toLowerCase().replace(/\//g, '-') + '.json') get('browsers/' + browser.toLowerCase() + '-' + os.toLowerCase().replace(/\//g, '-') + '.json')
.then(r => r.json()).catch(e => { .then(r => r.json()).catch(e => {
console.error(e); console.error(e);
return []; return [];