<commit_before>// jquery!
window.$ = window.jQuery = require("jquery");


/////////
// APP //
/////////
var App = function(){
	this.users = null;
	this.selectedUserIdx = null;
	this.selectedUser = null;
	this.projects = null;
	this.selectedProjectIdx = null;
	this.selectedProject = null;
	this.selectedFile = null;
};

App.prototype.login = function(key, user, rememberMe){
	// TODO: prevent from re-submitting while AJAX is running
	// TODO: clear existing data in next stages (they might change users and invalidate existing project data)


	$.ajax({
		url: "https://itch.io/api/1/"+key+"/my-games"
	}).done(function(data){
		// error handling
		
		if(data.errors){
			// error when submitting API key
			
			alert(data.errors.toString());

			return;
		}

		if(data.games.length <= 0){
			// the user has nothing associated with their key
			
			alert("Error: couldn't find any projects associated with this key. gui-butler can only push builds to existing projects; you need to use itch.io to actually create them.");

			return;
		}



		// success!

		if(rememberMe){
			// save login details to local storage
			window.localStorage.setItem("key", key);
			window.localStorage.setItem("rememberMe", "1");
		}else{
			// clear login details from local storage
			window.localStorage.setItem("key", "");
			window.localStorage.setItem("rememberMe", "0");
		}



		// find all usernames associated with key by stripping URLs
		var users={};
		for(var i = 0; i < data.games.length; ++i){
			var username = data.games[i].url.split("https://")[1].split(".itch.io/")[0];
			if(!users[username]){
				users[username] = {
					username: username,
					projects:[]
				}
			}
			users[username].projects.push(data.games[i]);
		}

		// add users to internal list + dropdown
		this.users = [];
		var s="";
		var i = 0;
		for(var u in users){
			this.users.push(users[u]);
			s += "<option value=\"" + (i++) + "\">" + users[u].username + "</option>";
		}
		$("#userSelect").html(s);



		// update section display
		$("section#login").hide();
		$("section#logout").show();



		// auto-select the first user in the dropdown
		// (provides a bit of feedback + removes the need for a null entry)
		$("#userSelect").val("0").change();

		$("section#selectUser").show();
	}.bind(this)).fail(function(){
		// couldn't get a response
		alert("Error: itch.io failed to respond. Check your internet connection etc.");
	}.bind(this));
};

App.prototype.logout = function(){
	$("section#login").show();

	$("#selectedFile").html("no .zip selected&hellip;");

	$("section#logout").hide();
	$("section#selectProject").hide();
	$("section#selectBuild").hide();
	$("section#selectUser").hide();
	$("section#butler").hide();
};
App.prototype.selectUser = function(idx){
	this.selectedUserIdx = parseInt(idx,10);
	this.selectedUser = this.users[this.selectedUserIdx];

	// update link
	$("#userPreview").attr("href", "https://"+this.selectedUser.username+".itch.io");

	// add the users games to the dropdown
	this.projects = this.selectedUser.projects;
	s="";
	for(var i = 0; i < this.projects.length; ++i){
		var g = this.projects[i];
		s += "<option value=\"" + i + "\">" + g.title + "</option>";
	}
	$("#projectSelect").html(s);

	// auto-select the first game in the dropdown
	// (provides a bit of feedback + removes the need for a null entry)
	$("#projectSelect").val("0").change();

	$("#selectProject").show();
};
App.prototype.selectProject = function(idx){
	this.selectedProjectIdx = parseInt(idx,10);
	this.selectedProject = this.projects[this.selectedProjectIdx];

	// get rid of the old cover, then set then new one
	$("#projectCover").attr("src", "");
	$("#projectCover").attr("src", this.selectedProject.cover_url);

	// update text
	$("#projectTitle").text(this.selectedProject.title);
	$("#projectText").text(this.selectedProject.short_text);

	// update link
	$("#projectUrl").attr("href", this.selectedProject.url);

	$("#selectBuild").show();
};
App.prototype.selectFile = function(){
	// prompt user to select a .zip archive
	remote.dialog.showOpenDialog(
	{
		title: "Select build archive",
		filters: [{name: "Build Archive", extensions:["zip"]}],
		properties: ["openFile"]
	},
	function(filenames){
		if(filenames.length==1){
			this.selectedFile = filenames[0];
			$("#selectedFile").text(this.selectedFile);
			$("section#butler").show();
		}else{
			// canceled selection
			$("section#butler").hide();
		}
	}.bind(this));
};
App.prototype.getChannels = function(){
	var channels = "";

	// add preset channels
	if($("#channelWin")[0].checked){
		channels += "win-";
	}if($("#channelOsx")[0].checked){
		channels += "osx-";
	}if($("#channelLinux")[0].checked){
		channels += "linux-";
	}

	// add custom channels
	channels += $("#channelOther").val();
<commit_msg>animations<commit_after>// jquery!
window.$ = window.jQuery = require("jquery");


/////////
// APP //
/////////
var App = function(){
	this.users = null;
	this.selectedUserIdx = null;
	this.selectedUser = null;
	this.projects = null;
	this.selectedProjectIdx = null;
	this.selectedProject = null;
	this.selectedFile = null;
};

App.prototype.login = function(key, user, rememberMe){
	// TODO: prevent from re-submitting while AJAX is running
	// TODO: clear existing data in next stages (they might change users and invalidate existing project data)


	$.ajax({
		url: "https://itch.io/api/1/"+key+"/my-games"
	}).done(function(data){
		// error handling
		
		if(data.errors){
			// error when submitting API key
			
			alert(data.errors.toString());

			return;
		}

		if(data.games.length <= 0){
			// the user has nothing associated with their key
			
			alert("Error: couldn't find any projects associated with this key. gui-butler can only push builds to existing projects; you need to use itch.io to actually create them.");

			return;
		}



		// success!

		if(rememberMe){
			// save login details to local storage
			window.localStorage.setItem("key", key);
			window.localStorage.setItem("rememberMe", "1");
		}else{
			// clear login details from local storage
			window.localStorage.setItem("key", "");
			window.localStorage.setItem("rememberMe", "0");
		}



		// find all usernames associated with key by stripping URLs
		var users={};
		for(var i = 0; i < data.games.length; ++i){
			var username = data.games[i].url.split("https://")[1].split(".itch.io/")[0];
			if(!users[username]){
				users[username] = {
					username: username,
					projects:[]
				}
			}
			users[username].projects.push(data.games[i]);
		}

		// add users to internal list + dropdown
		this.users = [];
		var s="";
		var i = 0;
		for(var u in users){
			this.users.push(users[u]);
			s += "<option value=\"" + (i++) + "\">" + users[u].username + "</option>";
		}
		$("#userSelect").html(s);



		// update section display
		$("section#login").slideUp();
		$("section#logout").slideDown();



		// auto-select the first user in the dropdown
		// (provides a bit of feedback + removes the need for a null entry)
		$("#userSelect").val("0").change();

		$("section#selectUser").slideDown();
	}.bind(this)).fail(function(){
		// couldn't get a response
		alert("Error: itch.io failed to respond. Check your internet connection etc.");
	}.bind(this));
};

App.prototype.logout = function(){
	$("section#login").slideDown();

	$("#selectedFile").html("no .zip selected&hellip;");

	$("section#logout").slideUp();
	$("section#selectProject").slideUp();
	$("section#selectBuild").slideUp();
	$("section#selectUser").slideUp();
	$("section#butler").slideUp();
};
App.prototype.selectUser = function(idx){
	this.selectedUserIdx = parseInt(idx,10);
	this.selectedUser = this.users[this.selectedUserIdx];

	// update link
	$("#userPreview").attr("href", "https://"+this.selectedUser.username+".itch.io");

	// add the users games to the dropdown
	this.projects = this.selectedUser.projects;
	s="";
	for(var i = 0; i < this.projects.length; ++i){
		var g = this.projects[i];
		s += "<option value=\"" + i + "\">" + g.title + "</option>";
	}
	$("#projectSelect").html(s);

	// auto-select the first game in the dropdown
	// (provides a bit of feedback + removes the need for a null entry)
	$("#projectSelect").val("0").change();

	$("#selectProject").slideDown();
};
App.prototype.selectProject = function(idx){
	this.selectedProjectIdx = parseInt(idx,10);
	this.selectedProject = this.projects[this.selectedProjectIdx];

	// get rid of the old cover, then set then new one
	$("#projectCover").attr("src", "");
	$("#projectCover").attr("src", this.selectedProject.cover_url);

	// update text
	$("#projectTitle").text(this.selectedProject.title);
	$("#projectText").text(this.selectedProject.short_text);

	// update link
	$("#projectUrl").attr("href", this.selectedProject.url);

	$("#selectBuild").slideDown();
};
App.prototype.selectFile = function(){
	// prompt user to select a .zip archive
	remote.dialog.showOpenDialog(
	{
		title: "Select build archive",
		filters: [{name: "Build Archive", extensions:["zip"]}],
		properties: ["openFile"]
	},
	function(filenames){
		if(filenames.length==1){
			this.selectedFile = filenames[0];
			$("#selectedFile").text(this.selectedFile);
			$("section#butler").slideDown();
		}else{
			// canceled selection
			$("section#butler").slideUp();
		}
	}.bind(this));
};
App.prototype.getChannels = function(){
	var channels = "";

	// add preset channels
	if($("#channelWin")[0].checked){
		channels += "win-";
	}if($("#channelOsx")[0].checked){
		channels += "osx-";
	}if($("#channelLinux")[0].checked){
		channels += "linux-";
	}

	// add custom channels
	channels += $("#channelOther").val();

{'fraction_non_alphanumeric': 0.19499478623566216, 'fraction_numerical': 0.004171011470281543, 'mean_word_length': 3.9361811631497683, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 6, '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': '290518', 'n_tokens_mistral': 3363, 'n_tokens_neox': 3050, 'n_words': 732}