Timers and other features for Heroes of the Storm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

75 lines
3.1 KiB

  1. /*
  2. * Copyright © 2021 Adrien Agez <adrien.agez@pm.me>
  3. *
  4. * This file is part of Nexus Timers.
  5. *
  6. * Nexus Timers is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Nexus Timers is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with Nexus Timers. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. (function() {
  20. 'use strict';
  21. // Check to make sure service workers are supported in the current browser,
  22. // and that the current page is accessed from a secure origin. Using a
  23. // service worker from an insecure origin will trigger JS console errors.
  24. var isLocalhost = Boolean(window.location.hostname === 'localhost' ||
  25. // [::1] is the IPv6 localhost address.
  26. window.location.hostname === '[::1]' ||
  27. // 127.0.0.1/8 is considered localhost for IPv4.
  28. window.location.hostname.match(
  29. /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
  30. )
  31. );
  32. window.addEventListener('load', function() {
  33. if ('serviceWorker' in navigator &&
  34. (window.location.protocol === 'https:' || isLocalhost)) {
  35. navigator.serviceWorker.register('service-worker.js')
  36. .then(function(registration) {
  37. // updatefound is fired if service-worker.js changes.
  38. registration.onupdatefound = function() {
  39. // updatefound is also fired the very first time the SW is installed,
  40. // and there's no need to prompt for a reload at that point.
  41. // So check here to see if the page is already controlled,
  42. // i.e. whether there's an existing service worker.
  43. if (navigator.serviceWorker.controller) {
  44. // The updatefound event implies that registration.installing is set
  45. var installingWorker = registration.installing;
  46. installingWorker.onstatechange = function() {
  47. switch (installingWorker.state) {
  48. case 'installed':
  49. // At this point, the old content will have been purged and the
  50. // fresh content will have been added to the cache.
  51. // It's the perfect time to display a "New content is
  52. // available; please refresh." message in the page's interface.
  53. break;
  54. case 'redundant':
  55. throw new Error('The installing ' +
  56. 'service worker became redundant.');
  57. default:
  58. // Ignore
  59. }
  60. };
  61. }
  62. };
  63. }).catch(function(e) {
  64. console.error('Error during service worker registration:', e);
  65. });
  66. }
  67. });
  68. })();