diff --git a/assets/js/app.js b/assets/js/app.js index ea7e58f3c..4232f5968 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -52,3 +52,45 @@ if (registerForm) { plausible('Signup', {callback: submitForm}); }) } + +const changelogNotification = document.getElementById('changelog-notification') + +if (changelogNotification) { + showChangelogNotification(changelogNotification) + + fetch('https://plausible.io/changes.txt', {headers: {'Content-Type': 'text/plain'}}) + .then((res) => res.text()) + .then((res) => { + localStorage.lastChangelogUpdate = new Date(res).getTime() + showChangelogNotification(changelogNotification) + }) +} + +function showChangelogNotification(el) { + const lastUpdated = Number(localStorage.lastChangelogUpdate) + const lastChecked = Number(localStorage.lastChangelogClick) + + if (lastChecked) { + const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked + const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72 + if (hasNewUpdateSinceLastClicked && notOlderThanThreeDays) { + el.innerHTML = ` + + + + + + + + + ` + const link = el.getElementsByTagName('a')[0] + link.addEventListener('click', function() { + localStorage.lastChangelogClick = Date.now() + setTimeout(() => { link.remove() }, 100) + }) + } + } else { + localStorage.lastChangelogClick = Date.now() + } +} diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex index 1ac1acb7c..760b171a3 100644 --- a/lib/plausible_web/templates/layout/app.html.eex +++ b/lib/plausible_web/templates/layout/app.html.eex @@ -50,6 +50,9 @@ + <%= if @conn.assigns[:current_user].email in ["me@markosaric.com", "uku@plausible.io"] do %> +
  • + <% end %> <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_authentication) -> %>