From 492fefb170c42efbc689ef95752eaedc413e75a0 Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Tue, 4 Aug 2020 07:02:57 +0200 Subject: [PATCH] update ua's from repo --- extension/data/popup/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extension/data/popup/index.js b/extension/data/popup/index.js index bbdc7a7..7b06318 100644 --- a/extension/data/popup/index.js +++ b/extension/data/popup/index.js @@ -33,6 +33,16 @@ function sort(arr) { 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) { const browser = document.getElementById('browser').value; const os = document.getElementById('os').value; @@ -43,7 +53,7 @@ function update(ua) { tbody.textContent = ''; 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 => { console.error(e); return [];