From 5b77366f61ea4ad2147142c0873d7b16283e447d Mon Sep 17 00:00:00 2001 From: Valvin Date: Thu, 21 Sep 2017 12:52:38 +0200 Subject: [PATCH] separate appcache js script detection --- gege.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 gege.js diff --git a/gege.js b/gege.js new file mode 100644 index 0000000..5337e52 --- /dev/null +++ b/gege.js @@ -0,0 +1,52 @@ + +checkCacheFunction = function() { + var webappCache = window.applicationCache; + + function loaded() + { + //var h1El = document.querySelector("h1"); + var connectionStatus = ((navigator.onLine) ? 'online' : 'offline'); + //h1El.textContent = h1El.textContent + " - currently: " + connectionStatus; + + switch(webappCache.status) + { + case 0: + console.log("Cache status: Uncached"); + break; + case 1: + console.log("Cache status: Idle"); + break; + case 2: + console.log("Cache status: Checking"); + break; + case 3: + console.log("Cache status: Downloading"); + break; + case 4: + console.log("Cache status: Updateready"); + break; + case 5: + console.log("Cache status: Obsolete"); + break; + } + + } + + function updateCache() + { + webappCache.swapCache(); + console.log("Cache has been updated due to a change found in the manifest"); + } + + function errorCache() + { + console.log("You're either offline or something has gone horribly wrong."); + } + + window.addEventListener("load", loaded, false); + webappCache.addEventListener("updateready", updateCache, false); + webappCache.addEventListener("error", errorCache, false); + +} + +checkCacheFunction();