kagisearch / smallweb

Kagi Small Web
https://kagi.com/smallweb
MIT License
519 stars 255 forks source link

feat: Add JS to disable "Next Post" for 5 seconds #122

Closed CarwynNelson closed 1 year ago

CarwynNelson commented 1 year ago

This PR adds some basic JavaScript that will disable the "Next Post" for 5 seconds after page load.

This complements the CSS change in 837af0c6b8e2fc34242f1f70184f52b4eec300bd which disables the button visually for 2 seconds, but does not stop users from pushing it. I have increased the CSS value from that patch to 5 seconds to match the JS.

Naturally this patch will work just fine if the user disables JS, but the disabled button will be purely visual.

I have added the JS to the bottom of the index.html template instead of a separate file as there is no other JS on the page, so it seems a bit silly to force the browser to make another HTTP request just for a few lines of JS.

With JS Enabled

https://github.com/kagisearch/smallweb/assets/3310215/e940e044-910d-47f3-bca8-8562ed976cc9

With JS Disabled

https://github.com/kagisearch/smallweb/assets/3310215/9f5f26e2-e8ba-4bae-b439-a543ed286ab2

vprelovac commented 1 year ago

This is great thanks. I recently pushed the CSS only patch and want to keep it alive for couple of days. It seems to have the wanted effect already (slowing down the user) and want to see if it is enough for what we want. if not we will pull this in (slightly concerned about unnerving some people with it). Sorry to keep your thoughtful MRs hanging, just trying to figure out what it the best for the site.

vprelovac commented 1 year ago

Can you check if you can click on the button while disabled on the site now? There is no JS and I can't.

CarwynNelson commented 1 year ago

Can you check if you can click on the button while disabled on the site now? There is no JS and I can't.

I just checked the patch, that's a clever way of doing it.

I can't click on the "Next Post" button now, although I also can't click on any button in the header either. That might be a worthwhile compromise though, i'll leave that up to you.

Sorry to keep your thoughtful MRs hanging, just trying to figure out what it the best for the site.

No worries at all! Thanks for taking the time to review my PRs thoughtfully :)

vprelovac commented 1 year ago

Thanks, I discovered it by accident. Now we have timer based button disable, without any JS!