<commit_before>'use strict'

<!--           ezpz-plug-export           -->
<!--       export your plug.dj data       -->
<!-- no bullshit, just a 1-Click-Download -->

// configure which endpoints get backup'd, and which filenames will be used
var endpoints = {
    'users/me':              'profile.json',
    'friends':               'friends.json',
    'friends/invites':       'invites.json',
    'ignores':               'ignores.json',
    'rooms/favorites':       'favorites.json',
    'rooms/history':         'history.json',
    'rooms/me':              'rooms.json',
    'store/inventory':       'inventory.json',
    'users/me/history':      'history.json',
    'users/me/transactions': 'transactions.json'
}

// set up progress bar
$('#ezpz-progress').remove()
var $prog = $('<div id=ezpz-progress>')
    .css({
        position:   'absolute',
        height:     '100%',
        background: 'rgba(0, 156, 221, .5)',
        zIndex:     -1,
        transition: 'width 200ms ease-in-out, background 200ms linear'
    })
    .appendTo('#footer')

// error handler
var ლ_ಠ益ಠ_ლ = function (msg, err) {
    // show warning in the console
    console.warn(msg, err)

    // add an error message to the chat
    if (window.API && typeof API.chatLog == 'function')
        API.chatLog(msg + '   ' + (err && err.message || err || '')) // \xa0 is &nbsp

    // temporarily turn the progress bar red/bloodorange
    $prog.css({ background: 'rgba(221, 20, 0, 0.5)' })
    setTimeout(function () {
        // turn it back to blue, unless we're done exporting
        if (loaded != total)
            $prog.css({ background: 'rgba(0, 156, 221, .5)' })
    }, 500)
}

// helper function to load data and store it in the zip
var delay = total = loaded = 0
var λ = function λ(url, filename, folder) {
    return new Promise(function (fulfill, reject) {
        // first, wait a moment before proceeding (0.2 seconds for each resource)
        // my tests indicate the delay isn't even necessary, but better be safe than sorry
        setTimeout( function () {
            // load the requested URL from https://plug.dj/_/… or whatever domain we're on
            $.get('/_/' + url, null, null, 'text').then(function (data) {
                // data successfully loaded
                // add file to zip
                ;(folder || zip).file('' + filename, data)
                // log progress to console
                console.log('[' + ++loaded + '/' + total + '] loaded /_/' + url + ' (' + filename + ')')
                // update progress bar (make it wider)
                $prog.css({ width: 100 * loaded / total + '%' })
            },
            // failed to load, show warning
            function (_, err) {
                ლ_ಠ益ಠ_ლ('failed to load /_/' + url + ' (' + filename + ')', err)
            }).then(fulfill, fulfill) // we don't reject ever. KEEP IT MOVING! ಠ_ಠ<commit_msg>fixed improper variable declaration<commit_after>'use strict'

<!--           ezpz-plug-export           -->
<!--       export your plug.dj data       -->
<!-- no bullshit, just a 1-Click-Download -->

// configure which endpoints get backup'd, and which filenames will be used
var endpoints = {
    'users/me':              'profile.json',
    'friends':               'friends.json',
    'friends/invites':       'invites.json',
    'ignores':               'ignores.json',
    'rooms/favorites':       'favorites.json',
    'rooms/history':         'history.json',
    'rooms/me':              'rooms.json',
    'store/inventory':       'inventory.json',
    'users/me/history':      'history.json',
    'users/me/transactions': 'transactions.json'
}

// set up progress bar
$('#ezpz-progress').remove()
var $prog = $('<div id=ezpz-progress>')
    .css({
        position:   'absolute',
        height:     '100%',
        background: 'rgba(0, 156, 221, .5)',
        zIndex:     -1,
        transition: 'width 200ms ease-in-out, background 200ms linear'
    })
    .appendTo('#footer')

// error handler
var ლ_ಠ益ಠ_ლ = function (msg, err) {
    // show warning in the console
    console.warn(msg, err)

    // add an error message to the chat
    if (window.API && typeof API.chatLog == 'function')
        API.chatLog(msg + '   ' + (err && err.message || err || '')) // \xa0 is &nbsp

    // temporarily turn the progress bar red/bloodorange
    $prog.css({ background: 'rgba(221, 20, 0, 0.5)' })
    setTimeout(function () {
        // turn it back to blue, unless we're done exporting
        if (loaded != total)
            $prog.css({ background: 'rgba(0, 156, 221, .5)' })
    }, 500)
}

// helper function to load data and store it in the zip
var delay = 0, total = 0, loaded = 0
var λ = function λ(url, filename, folder) {
    return new Promise(function (fulfill, reject) {
        // first, wait a moment before proceeding (0.2 seconds for each resource)
        // my tests indicate the delay isn't even necessary, but better be safe than sorry
        setTimeout( function () {
            // load the requested URL from https://plug.dj/_/… or whatever domain we're on
            $.get('/_/' + url, null, null, 'text').then(function (data) {
                // data successfully loaded
                // add file to zip
                ;(folder || zip).file('' + filename, data)
                // log progress to console
                console.log('[' + ++loaded + '/' + total + '] loaded /_/' + url + ' (' + filename + ')')
                // update progress bar (make it wider)
                $prog.css({ width: 100 * loaded / total + '%' })
            },
            // failed to load, show warning
            function (_, err) {
                ლ_ಠ益ಠ_ლ('failed to load /_/' + url + ' (' + filename + ')', err)
            }).then(fulfill, fulfill) // we don't reject ever. KEEP IT MOVING! ಠ_ಠ
{'fraction_non_alphanumeric': 0.15072264280798348, 'fraction_numerical': 0.015829318651066758, 'mean_word_length': 1.921105527638191, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '1635157', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1709, 'n_words': 534}