Skip to content

Commit

Permalink
Use pushState to change url on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
artemave committed Oct 29, 2023
1 parent 05fde65 commit 37b6b02
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 60 deletions.
26 changes: 0 additions & 26 deletions assets/link.svg

This file was deleted.

1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<input type="url" placeholder="github user/repo or url" />
</div>
<div id="crawlContainer"></div>
<img id="link" src="/assets/link.svg">
</div>
</body>
</html>
27 changes: 10 additions & 17 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetchCommitMessages from './fetchCommitMessages.js'
import { inputContainer, link, crawlContainer } from './domRefs.js'
import { inputContainer, crawlContainer } from './domRefs.js'
import performCrawl from './performCrawl.js'
import registerScrollSoundEffect from './registerScrollSoundEffect.js'

Expand All @@ -21,7 +21,7 @@ inputContainer.onkeydown = function (e) {
inputContainer.classList.add('zoomed')

audio.onended = () => {
audio.src = 'assets/theme.mp3'
audio.src = '/assets/theme.mp3'
}
loadThemePromise = new Promise((resolve) => {
audio.oncanplaythrough = resolve
Expand All @@ -31,6 +31,9 @@ inputContainer.onkeydown = function (e) {
if (repo.startsWith('https://github.com')) {
repo = repo.split('/').slice(-2).join('/')
}
window.history.pushState({}, '', `/${repo}`)
document.title = `Star Logs - ${repo}`

fetchCommitMessagesPromise = fetchCommitMessages(repo)

// hide keyboard on mobile
Expand All @@ -39,12 +42,16 @@ inputContainer.onkeydown = function (e) {
}
}

window.onpopstate = function () {
window.location.reload()
document.title = 'Star Logs'
}

inputContainer.ontransitionend = function() {
Promise.all([fetchCommitMessagesPromise, loadThemePromise]).then(([messages]) => {
performCrawl(messages)

audio.play()
link.style.display = 'initial'

}).catch(() => {
audio.src = 'assets/imperial_march.mp3'
Expand All @@ -61,18 +68,4 @@ inputContainer.ontransitionend = function() {
})
}

link.onclick = () => {
navigator.clipboard.writeText(window.location.href + repo)

const block = document.createElement('div')
block.classList.add('copied')
block.style.bottom = `-${crawlContainer.scrollTop - 70}px`
block.innerText = 'URL copied to clipboard!'
block.onanimationend = () => {
block.remove()
}

crawlContainer.appendChild(block);
}

registerScrollSoundEffect(audio)
16 changes: 0 additions & 16 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,6 @@ body {
}
}

#link {
z-index: 4;
position: absolute;
bottom: 5%;
right: 5%;
width: 36px;
display: none;
cursor: copy;
opacity: 0.5;
}

#link:hover {
opacity: 1;
transition: opacity .3s;
}

#play {
height: 20%;
top: 31%;
Expand Down

0 comments on commit 37b6b02

Please sign in to comment.