<commit_before>/**
 * Returns a historical Gmail URL
 * based on the date passed in
 * yearsInThePast years back from the current date
 *
 * @param <Date> date
 * @param <Integer> yearsInThePast
 * @return <String> combinedURL
 */
function historicalSearchURL(date, yearsInThePast, accountIndex) {
	// creating a copy because idk how to javascript tbh
	var dateCopy = new Date(date);
	var year = dateCopy.getFullYear() - yearsInThePast;

	var afterComponent = 'after:' + historicalDate(dateCopy, yearsInThePast);

	dateCopy.setDate(dateCopy.getDate() + 1);
	var beforeComponent = 'before:' + historicalDate(dateCopy, yearsInThePast);

	var baseURL = 'https://mail.google.com/mail/u/'+ accountIndex + '/#search/';
	var combinedURL = baseURL + encodeURIComponent(afterComponent) + '+' + encodeURIComponent(beforeComponent);

	return combinedURL;
}

/**
 * Creates a formatted date string
 * YYYY/MM/DD
 * given a Date object and years in the past
 *
 * @param <Date> date
 * @param <Integer> yearsInThePast
 * @return <String>
 */
function historicalDate(date, yearsInThePast) {
	var year = date.getFullYear() - yearsInThePast;
	var month = date.getMonth() + 1;
	var day = date.getDate();
	return year + '/' + month + '/' + day;
}

/**
 * Returns a shade of blue that
 * is lighter based on
 * number of years in the past
 * returns an rgba string
 *
 * @param <Integer> yearsInThePast
 * @return <String>
 */
function historicalColor(yearsInThePast) {
	var baseBlue = 149;
	var increment = 15;

	var blue = baseBlue + increment * yearsInThePast;

	return 'rgba(34, 110, ' + blue +', 1)';
}

/**
 * tbh i copied this from stackoverflow
 * and have no idea what it does
 *
 * @param <String> name
 * @returns <String>
 */
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

/**
 * Turns an object to a query string
 * and appends it to the current path
 *
 * @param <Object> params
 */
function updateURL(params) {
	var str = [];
  	for(var p in params) {
    	if (params.hasOwnProperty(p)) {
    		str.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p]));
    	}
  	}
  	var queryString = str.join('&');
	window.history.pushState('', '', '/?' + queryString);
}

Template.bottle.helpers({
<commit_msg>updated URLs to work on mobile as well<commit_after>/**
 * Returns a historical Gmail URL
 * based on the date passed in
 * yearsInThePast years back from the current date
 *
 * @param <Date> date
 * @param <Integer> yearsInThePast
 * @return <String> combinedURL
 */
function historicalSearchURL(date, yearsInThePast, accountIndex) {
	// creating a copy because idk how to javascript tbh
	var dateCopy = new Date(date);
	var year = dateCopy.getFullYear() - yearsInThePast;

	var afterComponent = 'after:' + historicalDate(dateCopy, yearsInThePast);

	dateCopy.setDate(dateCopy.getDate() + 1);
	var beforeComponent = 'before:' + historicalDate(dateCopy, yearsInThePast);

	var url = baseURL(accountIndex) + encodeURIComponent(afterComponent) + '+' + encodeURIComponent(beforeComponent);

	return url;
}

/**
 * Creates a formatted date string
 * YYYY/MM/DD
 * given a Date object and years in the past
 *
 * @param <Date> date
 * @param <Integer> yearsInThePast
 * @return <String>
 */
function historicalDate(date, yearsInThePast) {
	var year = date.getFullYear() - yearsInThePast;
	var month = date.getMonth() + 1;
	var day = date.getDate();
	return year + '/' + month + '/' + day;
}

/**
 * Returns a shade of blue that
 * is lighter based on
 * number of years in the past
 * returns an rgba string
 *
 * @param <Integer> yearsInThePast
 * @return <String>
 */
function historicalColor(yearsInThePast) {
	var baseBlue = 149;
	var increment = 15;

	var blue = baseBlue + increment * yearsInThePast;

	return 'rgba(34, 110, ' + blue +', 1)';
}

/**
 * tbh i copied this from stackoverflow
 * and have no idea what it does
 *
 * @param <String> name
 * @returns <String>
 */
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

/**
 * Turns an object to a query string
 * and appends it to the current path
 *
 * @param <Object> params
 */
function updateURL(params) {
	var str = [];
  	for(var p in params) {
    	if (params.hasOwnProperty(p)) {
    		str.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p]));
    	}
  	}
  	var queryString = str.join('&');
	window.history.pushState('', '', '/?' + queryString);
}

/**
 * Returns true if the user-agent is
 * a mobile device
 *
 * @returns <Boolean>
 */
function isMobile() {
	if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 		return true;
	} else {
		return false;
	}
}

/**
 * Turns an object to a query string
 * and appends it to the current path
 *
 * @param <Integer> accountIndex
 * @returns <String> baseURL
 */
function baseURL(accountIndex) {
	var firstPart = '';
	var secondPart = '';
	if (isMobile()) {
		firstPart = 'https://mail.google.com/mail/mu/mp/';
		secondPart = '#tl/search/';
	} else {
		firstPart = 'https://mail.google.com/mail/u/';
		secondPart = '#search/';
	}

	var url =  firstPart + accountIndex + secondPart;
	return url;
}

Template.bottle.helpers({

{'fraction_non_alphanumeric': 0.15263628239499552, 'fraction_numerical': 0.005004468275245755, 'mean_word_length': 3.7747440273037545, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 3, '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': '732546', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1836, 'n_words': 519}