-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop'. Enable offline mode and caching
- Loading branch information
Showing
7 changed files
with
233 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* (c) 2024 Piotr Kniaz | ||
This file is part of HBDPG-2. | ||
Repository: https://github.com/HBDPG-2/hbdpg-2.github.io | ||
Licensed under the MIT License. See LICENSE file in the project root for details. | ||
*/ | ||
|
||
const form1 = document.getElementById('passphrase1Form'); | ||
const form2 = document.getElementById('passphrase2Form'); | ||
const passphrase1Input = document.getElementById('passphrase1Input'); | ||
const passphrase2Input = document.getElementById('passphrase2Input'); | ||
const showPassphrase1Checkbox = document.getElementById('showPassphrase1Checkbox'); | ||
const showPassphrase2Checkbox = document.getElementById('showPassphrase2Checkbox'); | ||
const showPasswordCheckbox = document.getElementById('showPasswordCheckbox'); | ||
const showPassphrase1CheckboxLabel = document.getElementById('showPassphrase1CheckboxLabel'); | ||
const showPassphrase2CheckboxLabel = document.getElementById('showPassphrase2CheckboxLabel'); | ||
const showPasswordCheckboxLabel = document.getElementById('showPasswordCheckboxLabel'); | ||
const passwordLengthRadioLabels = document.querySelectorAll('.passwordLengthRadioLabels'); | ||
const passwordLengthChoice = document.getElementsByName('length'); | ||
const nextButton = document.getElementById('nextButton'); | ||
const confirmButton = document.getElementById('confirmButton'); | ||
const generateButton = document.getElementById('generateButton'); | ||
const copyButton = document.getElementById('copyButton'); | ||
const clearButton = document.getElementById('clearButton'); | ||
const generateNote = document.getElementById('generateNote'); | ||
const clearClipboardCheckbox = document.getElementById('clearClipboardCheckbox'); | ||
const clearClipboardCheckboxLabel = document.getElementById('clearClipboardCheckboxLabel'); | ||
const result = document.getElementById('result'); | ||
const timeCount = document.getElementById('timeCount'); | ||
const entropyCount = document.getElementById('entropyCount'); | ||
// Dialogs | ||
const closeAlertButton = document.getElementById('closeAlertButton'); | ||
const confirmDontClearClipboardDialogBox = document.getElementById('confirmDontClearClipboardDialogBox'); | ||
const dontClearClipboardCancelButton = document.getElementById('dontClearClipboardCancelButton'); | ||
const dontClearClipboardConfirmButton = document.getElementById('dontClearClipboardConfirmButton'); | ||
const updateNotification = document.getElementById('updateNotification'); | ||
const updateButton = document.getElementById('updateButton'); | ||
|
||
// Preload images | ||
(new Image()).src = 'images/loading.webp'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* (c) 2024 Piotr Kniaz | ||
This file is part of HBDPG-2. | ||
Repository: https://github.com/HBDPG-2/hbdpg-2.github.io | ||
Licensed under the MIT License. See LICENSE file in the project root for details. | ||
*/ | ||
|
||
const registerServiceWorker = async () => { | ||
if ('serviceWorker' in navigator) { | ||
try { | ||
const registration = await navigator.serviceWorker.register('./serviceworker.js', { scope: './' } ); | ||
|
||
if (registration.waiting) { | ||
showUpdateNotification(registration.waiting); | ||
} | ||
|
||
registration.addEventListener('updatefound', () => { | ||
const newWorker = registration.installing || registration.waiting; | ||
|
||
if (newWorker) { | ||
newWorker.addEventListener('statechange', () => { | ||
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) { | ||
showUpdateNotification(newWorker); | ||
} | ||
}); | ||
} | ||
}); | ||
} catch (error) { | ||
console.error(`Service Worker registration failed with ${error}`); | ||
} | ||
} | ||
}; | ||
|
||
registerServiceWorker(); | ||
|
||
function updateServiceWorker(worker) { | ||
worker.postMessage({ type: 'SKIP_WAITING' }); | ||
|
||
worker.addEventListener('statechange', () => { | ||
if (worker.state === 'activated') { | ||
reloadPage(false); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* (c) 2024 Piotr Kniaz | ||
This file is part of HBDPG-2. | ||
Repository: https://github.com/HBDPG-2/hbdpg-2.github.io | ||
Licensed under the MIT License. See LICENSE file in the project root for details. | ||
*/ | ||
|
||
const CACHE_VERSION = 'v20241212-0'; | ||
// const CACHE_VERSION = 'v1-debug'; | ||
|
||
const ASSETS = [ | ||
'/', | ||
'/index.html', | ||
'/manifest.webmanifest', | ||
'/favicon.ico', | ||
'/images/Logo-beta.webp', | ||
'/images/check.svg', | ||
'/images/loading.webp', | ||
'/styles/style.css', | ||
'/scripts/ui-items.js', | ||
'/scripts/ui.js', | ||
'/scripts/updater.js', | ||
'/scripts/core.js', | ||
'/scripts/argon2.js', | ||
'/scripts/argon2/argon2.js', | ||
'/scripts/argon2/argon2.wasm', | ||
'/scripts/argon2/argon2-simd.wasm' | ||
]; | ||
|
||
self.addEventListener('install', event => { | ||
event.waitUntil(caches.open(CACHE_VERSION).then(cache => cache.addAll(ASSETS))); | ||
}); | ||
|
||
self.addEventListener('activate', event => { | ||
event.waitUntil( | ||
caches.keys().then(cacheVersions => { | ||
return Promise.all( | ||
cacheVersions.map(cacheVersion => { | ||
if (cacheVersion !== CACHE_VERSION) { | ||
return caches.delete(cacheVersion); | ||
} | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
self.clients.claim(); | ||
}); | ||
|
||
self.addEventListener('message', event => { | ||
if (event.data && event.data.type === 'SKIP_WAITING') { | ||
self.skipWaiting(); | ||
} | ||
}); | ||
|
||
self.addEventListener('fetch', event => { | ||
event.respondWith( | ||
caches.match(event.request).then(response => { | ||
return response || fetch(event.request).catch(() => { | ||
return new Response('Network error occurred.', { | ||
status: 503, | ||
statusText: 'Service Unavailable', | ||
}); | ||
}); | ||
}) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters