Friday, January 13, 2017

3shrink: adventures in one click shrinking

While I'm pleased with the core functionality of 3shrink, it definitely needed a faster interface. That is, a way to effortlessly encode and decode 3shrink URLs, as well as bits of text. For now I've only solved half the problem, the shrinking side of things. The solution was straightforward: create a couple of bookmarklets. Here they are in action.

With these bookmarklets in place, I'm only one click away from a 3shrink code.

The implementation of the bookmarklets is nearly trivial. Here's the PHP snippet that powers them both:

 * A PHP file for generating a URL shrinking bookmarklet
$code = <<<EOF
  window.location = 
    'http://{$_SERVER['SERVER_NAME']}/shrink?i=' + encodeURIComponent($src)
$code = esc_attr($code);
<a href="javascript:<?= $code ?>">3shrink <?= $label ?></a>

And here's the calling code that renders the bookmarklets in the footer:

<div class="footer">
  <a href="/">Home</a> | <a href="">Built By Ben</a> |
  [<?= snippet('bookmarklet',
       ['label' => "URL", 'src' => 'window.location']) ?>]
  [<?= snippet('bookmarklet', 
       ['label' => "TXT", 'src' => "prompt('Text to Shrink')"]) ?>]

Installing the bookmarklets is as simple as browsing to your preferred instance of 3shrink, say and dragging the appropriate links from the footer into your bookmark toolbar.

You'll want to note that the bookmarklet's a domain specific. That is, the bookmarklets in the footer of the site register URLs with a different context than

With the shrinking side of things streamlined, the next area to focus on is how to quickly expand 3shrink codes. Stay tuned for that solution.

No comments:

Post a Comment