<commit_before>'use strict';

/*jslint
    browser: true
*/

(function() {
    var divs = document.getElementsByTagName('div'),
        i,
        selects = document.getElementsByTagName('select'),
        options,
        ths;

    function fancify(div) {
        var table = div.getElementsByTagName('table')[0],
            ths,
            firstCellWidth,
            i;

        if (table.clientWidth <= div.clientWidth) {
            return;
        }
        ths = table.getElementsByTagName('th');
        for (i = ths.length - 1; i >= 0; i -= 1) {
            if (ths[i].offsetWidth) {
                firstCellWidth = ths[i].offsetWidth;
                break;
            }
        }

        firstCellWidth += 'px';
        for (i = ths.length - 1; i >= 0; i -= 1) {
            ths[i].style.width = firstCellWidth;
            ths[i].style.marginLeft = '-' + firstCellWidth;
        }
        div.style.marginLeft = firstCellWidth;
        div.className += ' fancy';
    }

    for (i = divs.length - 1; i >= 0; i -= 1) {
        if (divs[i].className === 'timetable-wrapper') {
            fancify(divs[i]);
        }
    }

    // correct date picker after using browser back button
    if (selects.length) {
        options = selects[0].getElementsByTagName('option');
        for (i = options.length - 1; i >= 0; i -= 1) {
            if (options[i].defaultSelected) {
                if (!options[i].selected) {
                    selects[0].value = options[i].value;
                }
                break;
            }
        }
    }

    // highlight the row of the referring stop
    function maybeHighlight(tr) {
        var as = tr.getElementsByTagName('a');
        if (as.length && as[0].href === document.referrer) {
            tr.className += ' referrer';
        }
    }

    if (document.referrer.indexOf('/stops/') > -1) {
        ths = document.getElementsByTagName('th');
        for (i = ths.length - 1; i >= 0; i -= 1) {
            maybeHighlight(ths[i].parentNode);
        }
    }
}());<commit_msg>Track Megabus link clicks<commit_after>'use strict';

/*jslint
    browser: true
*/
/*global
    ga
*/

(function() {
    var divs = document.getElementsByTagName('div'),
        i,
        selects = document.getElementsByTagName('select'),
        options,
        ths;

    function fancify(div) {
        var table = div.getElementsByTagName('table')[0],
            ths,
            firstCellWidth,
            i;

        if (table.clientWidth <= div.clientWidth) {
            return;
        }
        ths = table.getElementsByTagName('th');
        for (i = ths.length - 1; i >= 0; i -= 1) {
            if (ths[i].offsetWidth) {
                firstCellWidth = ths[i].offsetWidth;
                break;
            }
        }

        firstCellWidth += 'px';
        for (i = ths.length - 1; i >= 0; i -= 1) {
            ths[i].style.width = firstCellWidth;
            ths[i].style.marginLeft = '-' + firstCellWidth;
        }
        div.style.marginLeft = firstCellWidth;
        div.className += ' fancy';
    }

    for (i = divs.length - 1; i >= 0; i -= 1) {
        if (divs[i].className === 'timetable-wrapper') {
            fancify(divs[i]);
        }
    }

    // correct date picker after using browser back button
    if (selects.length) {
        options = selects[0].getElementsByTagName('option');
        for (i = options.length - 1; i >= 0; i -= 1) {
            if (options[i].defaultSelected) {
                if (!options[i].selected) {
                    selects[0].value = options[i].value;
                }
                break;
            }
        }
    }

    // highlight the row of the referring stop
    function maybeHighlight(tr) {
        var as = tr.getElementsByTagName('a');
        if (as.length && as[0].href === document.referrer) {
            tr.className += ' referrer';
        }
    }

    if (document.referrer.indexOf('/stops/') > -1) {
        ths = document.getElementsByTagName('th');
        for (i = ths.length - 1; i >= 0; i -= 1) {
            maybeHighlight(ths[i].parentNode);
        }
    }

    function handleMegabusLinkClick() {
        ga('send', 'event', {
            eventCategory: 'Outbound Link',
            eventAction: 'click',
            eventLabel: 'megabus',
            transport: 'beacon'
        });
    }

    var as = document.getElementsByTagName('a');
    for (i = as.length - 1; i >= 0; i -= 1) {
        if (as[i].href.indexOf('uk.megabus.com') > -1) {
            as[i].onclick = handleMegabusLinkClick;
            break;
        }
    }
}());
{'fraction_non_alphanumeric': 0.14562895138434706, 'fraction_numerical': 0.009592326139088728, 'mean_word_length': 1.574635241301908, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3806475', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1401, 'n_words': 295}