Timer Bookmarklet

What is this?

I often find myself setting timers using Google's "set timer" search keyword. So often infact, that I decided to make a bookmarklet to simplify this action.

If you're not familiar, this is what Google's timer looks like:

How can I get it?

Simply drag this bookmarklet to your Bookmarks toolbar:

Set a timer

Woah, woah, woah, what is this JavaScript doing?

You can see the uncompressed JavaScript for the bookmarklet below:

(function (w) {
    'use strict';

    var timer_input = w.prompt('For how long?');
    var timer_split = timer_input.split(' ');

    var timer = parseInt(timer_split[0]);
    var units = 'minutes';

    if (timer_split.length > 1) {
        units = timer_split[1];
    }

    var tpl = function(string, data) {
        for (var token in data) {
            var value = data[token];
            string = string.replace(
                new RegExp('{' + token + '}', 'g'),
                value
            );
        }
        return string;
    };

    var url = tpl(
        'https://google.com/search?q=set+timer+for+{timer}+{units}',
        {
            timer: timer,
            units: units
        }
    );

    w.open(url, '_blank');
}(window));

Have any issues? let me know on the GitHub repository!