1let staticCacheName = 'currency-converter'; 2 3//Register Service Worker 4if ('serviceWorker' in navigator) { 5 navigator.serviceWorker.register('sw.js').then( reg => console.log("service worker successfully registered!", reg) 6 ).catch( err => console.log('Error while trying to register service worker', err) 7 ); 8} 9 10//Use Cache Api 11 12 13 self.addEventListener('install', event => { 14 event.waitUntil( 15 caches.open(staticCacheName).then( cache => { 16 return cache.addAll([ 17 '/', 18 '/index.html', 19 '/main.css', 20 '/sw.js', 21 '/app.js', 22 '/favicon.ico', 23 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css', 24 'https://free.currencyconverterapi.com/api/v5/currencies' 25 ]); 26 }) 27 ); 28}); 29 30 31 32 33 34self.addEventListener('fetch', event => { 35 36 console.log(event.request.url); 37 38 event.respondWith( 39 40 caches.match(event.request).then( response => { 41 42 return response || fetch(event.request); 43 44 }) 45 46 ); 47 48}); 49 50 51//Indexdb Here 52const dbname = "Currency-Converterdb"; 53 54// Open the database 55var open = indexedDB.open(dbname, 1); 56 57// Create the schema 58open.onupgradeneeded = () => { 59 let db = open.result; 60 let store = db.createObjectStore("CurrencyConverter", { keyPath: "id" }); 61 let index = store.createIndex("CurrencyNameIndex", ["Currency.CurrencyName", "Currency.CurrencySymbol"]); 62}; 63 64open.onsuccess = () => { 65 // Start a new transaction 66 let db = open.result; 67 let tx = db.transaction("CurrencyConverter", "readwrite"); 68 let store = tx.objectStore("CurrencyConverter"); 69 let index = store.index("CurrencyNameIndex"); 70 71 // Add some data 72 store.put({ id: "ALL", Currency: { CurrencyName: "Albanian Lek", CurrencySymbol: "ALL" } }); 73 store.put({ id: "$", Currency: { CurrencyName: "East Caribbean Dollar", CurrencySymbol: "$" } }); 74 store.put({ id: "$", Currency: { CurrencyName: "EasT", CurrencySymbol: "$" } }); 75 store.put({ id: "EUR", Currency: { currencyName: "Euro", CurrencySymbol: "â¬" } }); 76 store.put({ id: "NGN", Currency: { CurrencyName: "Nigerian Naira", CurrencySymbol: "â¦" } }); 77 store.put({ id: "$", Currency: { CurrencyName: "United States Dollar", CurrencySymbol: "$" } }); 78 store.put({ id: "$", Currency: { CurrencyName: "Australian Dollar", CurrencySymbol: "$" } }); 79 store.put({ id: "CNY", Currency: { CurrencyName: "Chinese Yuan", CurrencySymbol: "Â¥" } }); 80 store.put({ id: "CRC", Currency: { CurrencyName: "Costa Rican Colon", CurrencySymbol: "â¡" } }); 81 store.put({ id: "SYP", Currency: { CurrencyName: "Syrian Pound", CurrencySymbol: "£" } }); 82 store.put({ id: "AWG", Currency: { CurrencyName: "Aruban Florin", CurrencySymbol: "Æ" } }); 83 store.put({ id: "INR", Currency: { CurrencyName: "Indian Rupee", CurrencySymbol: "â¹" } }); 84 85 // Close the db when the transaction is done 86 tx.oncomplete = () => { 87 db.close(); 88 } 89}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.