import css from "../css/app.css" import "flatpickr/dist/flatpickr.min.css" import "./polyfills/closest" import 'abortcontroller-polyfill/dist/polyfill-patch-fetch' import "phoenix_html" import 'alpinejs' const triggers = document.querySelectorAll('[data-dropdown-trigger]') for (const trigger of triggers) { trigger.addEventListener('click', function(e) { e.stopPropagation() e.currentTarget.nextElementSibling.classList.remove('hidden') }) } if (triggers.length > 0) { document.addEventListener('click', function(e) { const dropdown = e.target.closest('[data-dropdown]') if (dropdown && e.target.tagName === 'A') { dropdown.classList.add('hidden') } }) document.addEventListener('click', function(e) { const clickedInDropdown = e.target.closest('[data-dropdown]') if (!clickedInDropdown) { for (const dropdown of document.querySelectorAll('[data-dropdown]')) { dropdown.classList.add('hidden') } } }) } const registerForm = document.getElementById('register-form') if (registerForm) { registerForm.addEventListener('submit', function(e) { e.preventDefault(); setTimeout(submitForm, 1000); var formSubmitted = false; function submitForm() { if (!formSubmitted) { formSubmitted = true; registerForm.submit(); } } 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) const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72 if ((!lastChecked || hasNewUpdateSinceLastClicked) && notOlderThanThreeDays) { el.innerHTML = ` ` const link = el.getElementsByTagName('a')[0] link.addEventListener('click', function() { localStorage.lastChangelogClick = Date.now() setTimeout(() => { link.remove() }, 100) }) } } const embedButton = document.getElementById('generate-embed') if (embedButton) { embedButton.addEventListener('click', function(e) { const baseUrl = document.getElementById('base-url').value const embedCode = document.getElementById('embed-code') const theme = document.getElementById('theme').value.toLowerCase() const background = document.getElementById('background').value try { const embedLink = new URL(document.getElementById('embed-link').value) embedLink.searchParams.set('embed', 'true') embedLink.searchParams.set('theme', theme) if (background) { embedLink.searchParams.set('background', background) } embedCode.value = `
Stats powered by Plausible Analytics
` } catch (e) { embedCode.value = 'ERROR: Please enter a valid URL in the shared link field' } }) }