<commit_before>// Copyright 2013-2016 <NAME>. All rights reserved
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

define(
	[
		"jquery",
		"services/AlertService"
	],
	function($, AlertService) {
		"use strict";

		var service = {
			/**
			 * addSavedSearch will append a new saved search
			 */
			addSavedSearch: function(name, searchCriteria) {
				searchCriteria.name = name;
				var currentSavedSearches = service.retrieveSavedSearches();

				currentSavedSearches.push(searchCriteria);
				service.storeSavedSearches(currentSavedSearches);
			},

			deleteSavedSearch: function(index) {
				var currentSavedSearches = service.retrieveSavedSearches();

				if (index > -1 && index < currentSavedSearches.length) {
					currentSavedSearches.splice(index, 1);
					service.storeSavedSearches(currentSavedSearches);
				}
			},

			/**
			 * getSavedSearchByIndex returns a saved search based on its location
			 * in the array.
			 */
			getSavedSearchByIndex: function(index) {
				var searches = service.retrieveSavedSearches();

				if (index < 0 && index >= searches.length) {
					AlertService.error({ message: "There is no saved search by that ID" });
					return {
						name: "",
						searchMessage: ""
					};
				}

				return searches[index];
			},

			/**
			 * getServiceSettings will return the MailSlurper service tier address
			 * and port.
			 */
			getServiceSettings: function() {
				return $.ajax({
					method: "GET",
					url: "/servicesettings"
				});
			},

			/**
			 * getServiceURL returns a fully formatted service URL as a key named
			 * "serviceURL" in the context object.
			 */
			getServiceURL: function(context) {
				var serviceSettings = service.retrieveServiceSettings();
				return "//" + serviceSettings.serviceAddress + ":" + serviceSettings.servicePort;
			},

			/**
			 * getServiceURLNow returns a fully formatted service URL as a key named
			 * "serviceURL" directly instead of via a promise.
			 */
			getServiceURLNow: function() {
				var serviceSettings = service.retrieveServiceSettings();

				var serviceURL = "http://" + serviceSettings.serviceAddress + ":" + serviceSettings.servicePort;

				return serviceURL;
			},

			/**
			 * retrieveSavedSearches reads saved searches from local storage
			 */
			retrieveSavedSearches: function() {
				if (localStorage["savedSearches"]) {
					return JSON.parse(localStorage["savedSearches"]);
				} else {
					return [];
				}
			},

			/**
			 * retrieveServiceSettings reads the MailSlurper service settings
			 * from the user's local storage.
			 */
			retrieveServiceSettings: function() {
				return JSON.parse(localStorage["serviceSettings"]);
			},

			/**
			 * retrieveSettings reads user settings from local storage.
			 */
			retrieveSettings: function() {
				if (localStorage["settings"]) {
					return JSON.parse(localStorage["settings"]);<commit_msg>Removed hard coded http:// refs #28<commit_after>// Copyright 2013-2016 <NAME>. All rights reserved
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

define(
	[
		"jquery",
		"services/AlertService"
	],
	function($, AlertService) {
		"use strict";

		var service = {
			/**
			 * addSavedSearch will append a new saved search
			 */
			addSavedSearch: function(name, searchCriteria) {
				searchCriteria.name = name;
				var currentSavedSearches = service.retrieveSavedSearches();

				currentSavedSearches.push(searchCriteria);
				service.storeSavedSearches(currentSavedSearches);
			},

			deleteSavedSearch: function(index) {
				var currentSavedSearches = service.retrieveSavedSearches();

				if (index > -1 && index < currentSavedSearches.length) {
					currentSavedSearches.splice(index, 1);
					service.storeSavedSearches(currentSavedSearches);
				}
			},

			/**
			 * getSavedSearchByIndex returns a saved search based on its location
			 * in the array.
			 */
			getSavedSearchByIndex: function(index) {
				var searches = service.retrieveSavedSearches();

				if (index < 0 && index >= searches.length) {
					AlertService.error({ message: "There is no saved search by that ID" });
					return {
						name: "",
						searchMessage: ""
					};
				}

				return searches[index];
			},

			/**
			 * getServiceSettings will return the MailSlurper service tier address
			 * and port.
			 */
			getServiceSettings: function() {
				return $.ajax({
					method: "GET",
					url: "/servicesettings"
				});
			},

			/**
			 * getServiceURL returns a fully formatted service URL as a key named
			 * "serviceURL" in the context object.
			 */
			getServiceURL: function(context) {
				var serviceSettings = service.retrieveServiceSettings();
				return "//" + serviceSettings.serviceAddress + ":" + serviceSettings.servicePort;
			},

			/**
			 * getServiceURLNow returns a fully formatted service URL as a key named
			 * "serviceURL" directly instead of via a promise.
			 */
			getServiceURLNow: function() {
				var serviceSettings = service.retrieveServiceSettings();

				var serviceURL = "//" + serviceSettings.serviceAddress + ":" + serviceSettings.servicePort;

				return serviceURL;
			},

			/**
			 * retrieveSavedSearches reads saved searches from local storage
			 */
			retrieveSavedSearches: function() {
				if (localStorage["savedSearches"]) {
					return JSON.parse(localStorage["savedSearches"]);
				} else {
					return [];
				}
			},

			/**
			 * retrieveServiceSettings reads the MailSlurper service settings
			 * from the user's local storage.
			 */
			retrieveServiceSettings: function() {
				return JSON.parse(localStorage["serviceSettings"]);
			},

			/**
			 * retrieveSettings reads user settings from local storage.
			 */
			retrieveSettings: function() {
				if (localStorage["settings"]) {
					return JSON.parse(localStorage["settings"]);
{'fraction_non_alphanumeric': 0.11156532106966445, 'fraction_numerical': 0.004087889626980072, 'mean_word_length': 3.1352112676056336, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, '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': '3951047', 'n_tokens_mistral': 2167, 'n_tokens_neox': 1626, 'n_words': 437}