Silly countdown with jQuery
--
I hate winter. Just tell me when it’s over, please. I don’t trust foreign and/or unproven sources for this knowledge, so I created something.
Here’s what I used:
- Apache2 and jQuery
- The Final Countdown plugin http://hilios.github.io/jQuery.countdown/
Allocate a folder, example /var/www/html/spring,
and download the plugin:
➜ ~ wget -q https://github.com/hilios/jQuery.countdown/releases/download/2.2.0/jquery.countdown-2.2.0.zip➜ ~ unzip jquery.countdown-2.2.0.zip && cd jquery.countdown-2.2.0➜ ~ cp jquery.countdown.js /var/www/html/spring
Make sure you have jQuery, too.
Create a file /var/www/html/spring/index.html
with the contents below:
Navigate to where you configured your web server to serve this, e.g., http://127.0.0.1/spring
. You should see the countdown exactly as shown in the first picture.
But wait, I don’t want to use a web browser…
Oh, of course you don’t. Scrape your site via the CLI. Yes, you could just use a one-liner to calculate the days remaining, but that doesn’t sound very fun to me.
If you’re on a Mac, and using Homebrew, grab PhantomJS from homebrew/cask.
➜ ~ brew tap homebrew/cask➜ ~ brew install — cask phantomjs
Also, install w3m for later.
➜ ~ brew install w3m
Create a local file ~/save_page.js
.
And create wrapper script to call it at ~/spring.sh
Finally, run it:
➜ ~ chmod +x ~/spring.sh➜ ~ bash ~/spring.sh
Done.
Hopefully, one day a countdown will be desperately needed, and you’ll be prepared.
Mistakes? Did I miss anything? Let me know.