<commit_before>/*
Audio file is Notification Up II by FoolBoyMedia (http://www.freesound.org/people/FoolBoyMedia/sounds/234563/)
Used with permission.
License: CC BY-NC 3.0 http://creativecommons.org/licenses/by-nc/3.0/
*/

(function (env) {
    "use strict";
    env.ddg_spice_timer = function(api_result) {
        Spice.add({
            id: "timer",
            name: "Timer",
            signal: "high",
            data: {},
            meta: {
                sourceName: "Timer",
                itemType: "timer"
            },
            templates: {
                detail: Spice.timer.timer,
                wrap_detail: 'base_detail'
            },
            //wait for the spice to load before displaying things
            //this makes sure the divs display at the right time so the layout doesn't break
            onShow: function(){
                $('#timer_buttons').css('display', 'inline-block');
                $('#timer_input').css('display', 'inline-block');
            }
        });

        //add zeros to the end of the number
        function padZeros(n, len){
            var s = n.toString();
            while (s.length < len){
                s = '0' + s;
            }
            return s;
        }

        function parseQueryForTime(){
            var q = DDG.get_query().replace('timer', '').replace('online', ''),
                regex = new RegExp(/(\d+) ?(min|sec|h)/),
                time = 0;

            while (true){
                var match = regex.exec(q);
                if (match){
                    var val = parseInt(match[1]),
                        unit = match[2];
                    if (unit === 'h') time += val*60*60;
                    else if (unit === 'min') time += val*60;
                    else if (unit === 'sec') time += val;
                    q = q.replace(match[0], '');
                } else {
                    break;
                }
            }
            return time;
        }

        var time_left, last_update, update_int,
            started = false,
            $minute_input = $('#minute_input'),
            $second_input = $('#second_input'),
            $timer = $('#timer'),
            $timer_input = $('#timer_input'),
            $timer_display = $('#timer_display'),
            $reset_btn = $('#reset_btn'),
            $startstop_btn = $('#startstop_btn'),
            $done_modal = $('#done_modal'),
            soundUrl = DDG.get_asset_path('timer', 'alarm.mp3'),
            enteredTime = parseQueryForTime(),
            oldTitle = document.title;

        //enter the time from the query into the boxes
        if (enteredTime) {
            if (Math.floor(enteredTime / 60) > 0) {
                $minute_input.val(Math.floor(enteredTime / 60));
            }
            $second_input.val(padZeros(enteredTime % 60, 2));<commit_msg>Timer: don't reshow the time input<commit_after>/*
Audio file is Notification Up II by FoolBoyMedia (http://www.freesound.org/people/FoolBoyMedia/sounds/234563/)
Used with permission.
License: CC BY-NC 3.0 http://creativecommons.org/licenses/by-nc/3.0/
*/

(function (env) {
    "use strict";

    var started = false;

    env.ddg_spice_timer = function(api_result) {
        Spice.add({
            id: "timer",
            name: "Timer",
            signal: "high",
            data: {},
            meta: {
                sourceName: "Timer",
                itemType: "timer"
            },
            templates: {
                detail: Spice.timer.timer,
                wrap_detail: 'base_detail'
            },
            //wait for the spice to load before displaying things
            //this makes sure the divs display at the right time so the layout doesn't break
            onShow: function(){
                if (!started){
                    $('#timer_input').css('display', 'inline-block');
                }
                $('#timer_buttons').css('display', 'inline-block');
            }
        });

        //add zeros to the end of the number
        function padZeros(n, len){
            var s = n.toString();
            while (s.length < len){
                s = '0' + s;
            }
            return s;
        }

        function parseQueryForTime(){
            var q = DDG.get_query().replace('timer', '').replace('online', ''),
                regex = new RegExp(/(\d+) ?(min|sec|h)/),
                time = 0;

            while (true){
                var match = regex.exec(q);
                if (match){
                    var val = parseInt(match[1]),
                        unit = match[2];
                    if (unit === 'h') time += val*60*60;
                    else if (unit === 'min') time += val*60;
                    else if (unit === 'sec') time += val;
                    q = q.replace(match[0], '');
                } else {
                    break;
                }
            }
            return time;
        }

        var time_left, last_update, update_int,
            $minute_input = $('#minute_input'),
            $second_input = $('#second_input'),
            $timer = $('#timer'),
            $timer_input = $('#timer_input'),
            $timer_display = $('#timer_display'),
            $reset_btn = $('#reset_btn'),
            $startstop_btn = $('#startstop_btn'),
            $done_modal = $('#done_modal'),
            soundUrl = DDG.get_asset_path('timer', 'alarm.mp3'),
            enteredTime = parseQueryForTime(),
            oldTitle = document.title;

        //enter the time from the query into the boxes
        if (enteredTime) {
            if (Math.floor(enteredTime / 60) > 0) {
                $minute_input.val(Math.floor(enteredTime / 60));
            }
            $second_input.val(padZeros(enteredTime % 60, 2));
{'fraction_non_alphanumeric': 0.1375432525951557, 'fraction_numerical': 0.010380622837370242, 'mean_word_length': 1.3987551867219916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7119443', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1542, 'n_words': 387}