From 4a86d34f5a5477f317b74f9e85ad21491ab671c1 Mon Sep 17 00:00:00 2001 From: migatu Date: Tue, 7 Jul 2026 18:59:03 +0200 Subject: [PATCH] Geolokalizacja: jawny komunikat gdy brak secure context (http://) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Przyczyna "nie pyta o zgodę": navigator.geolocation działa tylko w secure context (https:// lub localhost). Na http:// przeglądarka po cichu odmawia — bez promptu; kod nie miał callbacku błędu, więc nic nie było widać. - wspólny static/now.js (deduplikacja skryptu z chart.html i interpret.html) - jawna detekcja window.isSecureContext + czytelny komunikat w #geoNote ("wymaga HTTPS lub localhost — wpisz lat/lon ręcznie") - callback błędu (odmowa/timeout) też widoczny; status "Pobieram lokalizację…" i potwierdzenie po sukcesie Zweryfikowano: /static/now.js serwowany (200), obie strony referencjonują skrypt i mają #geoNote. Co-Authored-By: Claude Opus 4.8 --- services/presentation/app/static/now.js | 43 +++++++++++++++++++ .../presentation/app/templates/chart.html | 20 +-------- .../presentation/app/templates/interpret.html | 19 +------- 3 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 services/presentation/app/static/now.js diff --git a/services/presentation/app/static/now.js b/services/presentation/app/static/now.js new file mode 100644 index 0000000..b46d86d --- /dev/null +++ b/services/presentation/app/static/now.js @@ -0,0 +1,43 @@ +// „Tu i teraz": uzupełnia datę/godzinę/strefę z przeglądarki oraz — jeśli to +// możliwe — lokalizację (lat/lon). +// +// UWAGA: geolokalizacja przeglądarki działa tylko w "secure context" +// (https:// lub localhost). Na http:// przeglądarka NIE pyta o zgodę, +// tylko po cichu odmawia — dlatego pokazujemy jawny komunikat w #geoNote. +document.addEventListener('DOMContentLoaded', function () { + const btn = document.getElementById('nowBtn'); + if (!btn) return; + + const note = document.getElementById('geoNote'); + const say = msg => { if (note) note.textContent = msg; }; + + btn.addEventListener('click', function () { + const d = new Date(); + const pad = n => String(n).padStart(2, '0'); + document.querySelector('input[name=date]').value = + d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); + document.querySelector('input[name=time]').value = pad(d.getHours()) + ':' + pad(d.getMinutes()); + document.querySelector('input[name=tz_offset]').value = (-d.getTimezoneOffset() / 60); + + if (!('geolocation' in navigator)) { + say('Ta przeglądarka nie udostępnia geolokalizacji — wpisz lat/lon ręcznie.'); + return; + } + if (!window.isSecureContext) { + say('Lokalizacja z przeglądarki wymaga HTTPS lub localhost (otwarto przez http://) — wpisz lat/lon ręcznie.'); + return; + } + say('Pobieram lokalizację…'); + navigator.geolocation.getCurrentPosition( + function (pos) { + document.querySelector('input[name=lat]').value = pos.coords.latitude.toFixed(4); + document.querySelector('input[name=lon]').value = pos.coords.longitude.toFixed(4); + say('Lokalizacja pobrana ✓'); + }, + function (err) { + say('Nie udało się pobrać lokalizacji: ' + (err && err.message ? err.message : 'odmowa dostępu')); + }, + { timeout: 8000 } + ); + }); +}); diff --git a/services/presentation/app/templates/chart.html b/services/presentation/app/templates/chart.html index 01a49d9..050bd97 100644 --- a/services/presentation/app/templates/chart.html +++ b/services/presentation/app/templates/chart.html @@ -36,6 +36,7 @@
+
@@ -110,22 +111,5 @@ {% endif %} {% endif %} - + {% endblock %} diff --git a/services/presentation/app/templates/interpret.html b/services/presentation/app/templates/interpret.html index 6fa24e9..b428ad8 100644 --- a/services/presentation/app/templates/interpret.html +++ b/services/presentation/app/templates/interpret.html @@ -29,6 +29,7 @@
+
@@ -82,21 +83,5 @@ {% endfor %} {% endif %} - + {% endblock %}