<commit_before>const debugging = (window == top);
window.onload = function() {
    displaySchedule();
    displayDrafts();
    displayEmailAddress();

    // Set dates to today
    var curTime = moment().format('HH:mm');
    var curDate = moment().format('YYYY-MM-DD');
    document.querySelector('#date').value = curDate;
    document.querySelector('#time').value = curTime;

    // Adds date picker for browsers without date support
    loadPicker();

    setTimeout(function(){
        document.getElementById('myHTML').style.height = '100%';
        document.querySelector('#myHTML > body').style.height = '100%';
    }, 1000)
    /* NOTE 1: This is very hacky but what is happening is #myHTML must have height set to over 100% otherwise you can't scroll on mobile (if needed)
    This may be caused by this all being in an iframe and a lot of the height of the document rendering later.
    This basically sets the height back to 100% like normal
        */
};

function getEmailAddress(callback){
    if (debugging){
        let address = "<EMAIL>";
        callback(address);
    } else {
        google.script.run.withSuccessHandler(callback).getCurrentUser();
    }
}
function displayEmailAddress(){
    getEmailAddress(function(address){
        document.querySelector('#userEmail').innerText = address;
    })
}
function getDrafts(callback){
    if (debugging){
        let draftSubjects = ["Subject 1", "Subject 2", "etc", "Medium Article Examples", "Resume Inspiration",
         "iPod Print", "https://iwantwhatitsworth.com/","Lo And Behold: Reveries Of The Connected World"];
        callback(draftSubjects);
    } else {
        google.script.run.withSuccessHandler(callback).getDraftSubjects();
    }
}
function displayDrafts() {
    getDrafts(function (drafts) {
        var options = '';
        for (var draft of drafts) {
            options += '<option value="' + draft + '">' + draft + '<\/option>';
        }
        document.querySelector('#subjects').innerHTML = options;
        showLoading(false);
    })
}
function getSchedule(callback) {
    showLoading(true);
    if (debugging) {
        let scheduledEmails = [
            { "subject": "Resume Inspiration", "date": "2018-08-01T20:11:00.000Z" },
            { "subject": "iPod Print", "date": "2018-07-31T21:14:00.000Z" },
            { "subject": "SQL Stuffs", "date": "2018-08-01T20:11:00.000Z" }
        ];
        callback(scheduledEmails)
    } else {
        google.script.run.withSuccessHandler(callback).getScheduledEmails();
    }
}
function displaySchedule() {
    getSchedule(
        function (s) {
            var template = document.querySelector('#productrow');
            var newContents = document.createDocumentFragment();

            for (let message of s) {
                var formattedDate = moment(message.date).format('MMMM Do YYYY, hh:mm a');
                var clone = document.importNode(template.content, true);
                var td = clone.querySelectorAll("td");
                td[0].textContent = message.subject;
                td[1].textContent = formattedDate;
                td[2].addEventListener('click', function () { removeScheduledMessage(message.subject); });
                newContents.appendChild(clone);
            };

            //Deletes old table-items
            document.querySelectorAll('.table-item').forEach(function (e) { e.remove() });
            document.querySelector("tbody").appendChild(newContents);
            showLoading(false);
        }
        //function(s){console.log("hi")}
    )
}
function addScheduledMessage() {
    var date = document.querySelector('#date').value;
    var time = parseTime(document.querySelector('#time').value);
    var subject = document.querySelector('#subjects').value;
    var sendDate = new Date(date + " " + time);

    if (dateIsInFuture(sendDate)){
        sendDate = JSON.stringify(sendDate);
        showError(false);
        if (debugging){
            console.log("Submitting the following to Google: " + subject + sendDate)
        } else{
            google.script.run.addEmailToSchedule(subject, sendDate);
        }
        displaySchedule();
    } else {
        showError(true);
    }
}<commit_msg>add option to schedule new emails in dummy mode<commit_after>const debugging = (window == top);
window.onload = function() {
    displaySchedule();
    displayDrafts();
    displayEmailAddress();

    // Set dates to today
    var curTime = moment().format('HH:mm');
    var curDate = moment().format('YYYY-MM-DD');
    document.querySelector('#date').value = curDate;
    document.querySelector('#time').value = curTime;

    // Adds date picker for browsers without date support
    loadPicker();

    setTimeout(function(){
        document.getElementById('myHTML').style.height = '100%';
        document.querySelector('#myHTML > body').style.height = '100%';
    }, 1000)
    /* NOTE 1: This is very hacky but what is happening is #myHTML must have height set to over 100% otherwise you can't scroll on mobile (if needed)
    This may be caused by this all being in an iframe and a lot of the height of the document rendering later.
    This basically sets the height back to 100% like normal
        */
};

function getEmailAddress(callback){
    if (debugging){
        let address = "<EMAIL>";
        callback(address);
    } else {
        google.script.run.withSuccessHandler(callback).getCurrentUser();
    }
}
function displayEmailAddress(){
    getEmailAddress(function(address){
        document.querySelector('#userEmail').innerText = address;
    })
}
function getDrafts(callback){
    if (debugging){
        let draftSubjects = ["Subject 1", "Subject 2", "etc", "Medium Article Examples", "Resume Inspiration",
         "iPod Print", "https://iwantwhatitsworth.com/","Lo And Behold: Reveries Of The Connected World"];
        callback(draftSubjects);
    } else {
        google.script.run.withSuccessHandler(callback).getDraftSubjects();
    }
}
function displayDrafts() {
    getDrafts(function (drafts) {
        var options = '';
        for (var draft of drafts) {
            options += '<option value="' + draft + '">' + draft + '<\/option>';
        }
        document.querySelector('#subjects').innerHTML = options;
        showLoading(false);
    })
}
function getSchedule(callback) {
    showLoading(true);
    if (debugging) {
        if (typeof(scheduledEmails) == "undefined"){
            scheduledEmails = [
                { "subject": "Resume Inspiration", "date": "2018-08-01T20:11:00.000Z" },
                { "subject": "iPod Print", "date": "2018-07-31T21:14:00.000Z" },
                { "subject": "SQL Stuffs", "date": "2018-08-01T20:11:00.000Z" }
            ];
        }
        callback(scheduledEmails)
    } else {
        google.script.run.withSuccessHandler(callback).getScheduledEmails();
    }
}
function displaySchedule() {
    getSchedule(
        function (s) {
            var template = document.querySelector('#productrow');
            var newContents = document.createDocumentFragment();

            for (let message of s) {
                var formattedDate = moment(new Date(message.date)).format('MMM Do YYYY, hh:mm a');
                var clone = document.importNode(template.content, true);
                var td = clone.querySelectorAll("td");
                td[0].textContent = message.subject;
                td[1].textContent = formattedDate;
                td[2].addEventListener('click', function () { removeScheduledMessage(message.subject); });
                newContents.appendChild(clone);
            };

            //Deletes old table-items
            document.querySelectorAll('.table-item').forEach(function (e) { e.remove() });
            document.querySelector("tbody").appendChild(newContents);
            showLoading(false);
        }
        //function(s){console.log("hi")}
    )
}
function addScheduledMessage() {
    let date = document.querySelector('#date').value;
    let time = parseTime(document.querySelector('#time').value);
    let subject = document.querySelector('#subjects').value;
    let sendDate = new Date(date + " " + time);

    if (dateIsInFuture(sendDate)){
        sendDate = sendDate.toJSON();
        showError(false);
        if (debugging){
            console.log("Submitting the following to Google: " + subject + sendDate);
            let newEmail = { "subject": subject, "date": sendDate };
            let index = scheduledEmails.findIndex(e => {return e.subject == subject});
            index > -1 ? scheduledEmails[index] = newEmail : scheduledEmails.push(newEmail);
        } else{
            google.script.run.addEmailToSchedule(subject, sendDate);
        }
        displaySchedule();
    } else {
        showError(true);
    }
}
{'fraction_non_alphanumeric': 0.13490705895769187, 'fraction_numerical': 0.016763599042080055, 'mean_word_length': 2.667921371810958, 'pattern_counts': {'":': 14, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '477210', 'n_tokens_mistral': 2499, 'n_tokens_neox': 2383, 'n_words': 568}