<commit_before>// whatthekeycode.com
//  define some global variables

$(document).ready(function () {


	  // $.ajaxSetup({ cache: true });
	  // $.getScript('http://connect.facebook.net/en_US/sdk.js', function(){
	  //   FB.init({
	  //     appId: '1484948608415623',
	  //     version: 'v2.0' // or v2.0, v2.1, v2.0
	  //   });     
	  //   $('#loginbutton,#feedbutton').removeAttr('disabled');
	  //   FB.getLoginStatus(updateStatusCallback);
	  // });

	var LOG = false, saving=false;
	var autoplay;
	document.getElementById("autoplay_check").checked = false;
	document.getElementById("englishflag").checked = true;

	$('#textbox').val('');

	var platform = navigator.platform;
	
	//  make height and width dynamic and always updated on resize
	$( window ).resize(function() {
		var viewport = {
		    width  : $(window).width(),
		    height : $(window).height()
		};

		if (LOG) console.log("height: " + viewport.height);
		if (LOG) console.log("width: " + viewport.width);
	});
			


	if (LOG) console.log(platform);

	function detectmob() { 
	 if( navigator.userAgent.match(/Android/i)
	 || navigator.userAgent.match(/webOS/i)
	 || navigator.userAgent.match(/iPhone/i)
	 || navigator.userAgent.match(/iPad/i)
	 || navigator.userAgent.match(/iPod/i)
	 || navigator.userAgent.match(/BlackBerry/i)
	 || navigator.userAgent.match(/Windows Phone/i)
	 ){
	    return true;
	  }
	 else {
	    return false;
	  }
	}

	// detect if device is mobile
	 var isMobile =  detectmob();

	 $(document).mousemove(function (e) {
		var mouseX = e.pageX; // e.pageX - gives you the X position.
		var mouseY = e.pageY; // e.pageY - gives you the Y position.
	});

	 // add element to on-screen canvas (hidden)
	 function getBase64Image(img) {
	    canvas = document.getElementById("my-canvas");
	    canvas.width = img.width;
	    canvas.height = img.height;
	    ctx = canvas.getContext("2d");
	    ctx.drawImage(img, 0, 0);
	    dataURL = canvas.toDataURL("image/png");
	    return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
	}

	function hideForSaving(){
 		$('#download').css('visibility','hidden');
 		$('#again').css('visibility','hidden');
 		$('#vocab').css('visibility','hidden');
 		$('#content').css('margin-top', '10%');
	}

	function prepareForDownload(){
		saving = !saving;
		document.getElementById('savingstate').innerHTML=flashDict[saving];
	}

	  function saveToFile(blob){
	  	var dateTimeInMs = new Date();
	  	var imageName = 'alphabet_ninja_';
	  	var extension = '.png"';
	  	var imageFileName = imageName.concat(dateTimeInMs).concat(extension);
	  	var pathName = '"../blobs/';
	  	var fullPathName = pathName.concat(imageFileName);
	  	console.log(fullPathName);

    	var data = new FormData();
		data.append("data" , blob);
		var xhr = new XMLHttpRequest();
		xhr.open( 'post', imageFileName, true );
		xhr.send(data);
    }

    function PostImageToFacebook( authToken, filename, mimeType, imageData, message )
{
    // this is the multipart/form-data boundary we'll use
    var boundary = '----ThisIsTheBoundary1234567890';
    
    // let's encode our image file, which is contained in the var
    var formData = '--' + boundary + '\r\n'
    formData += 'Content-Disposition: form-data; name="source"; filename="' + filename + '"\r\n';
    formData += 'Content-Type: ' + mimeType + '\r\n\r\n';
    for ( var i = 0; i < imageData.length; ++i )
    {
        formData += String.fromCharCode( imageData[ i ] & 0xff );
    }
    formData += '\r\n';
    formData += '--' + boundary + '\r\n';
    formData += 'Content-Disposition: form-data; name="message"\r\n\r\n';
    formData += message + '\r\n'
    formData += '--' + boundary + '--\r\n';
    
    var xhr = new XMLHttpRequest();
    xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + authToken, true );
    xhr.onload = xhr.onerror = function() {
        console.log( xhr.responseText );
    };
    xhr.setRequestHeader( "Content-Type", "multipart/form-data; boundary=" + boundary );
    xhr.sendAsBinary( formData );
}

    function postToFb(canvas){

    	if ( XMLHttpRequest.prototype.sendAsBinary === undefined ) {
    XMLHttpRequest.prototype.sendAsBinary = function(string) {
        var bytes = Array.prototype.map.call(string, function(c) {
            return c.charCodeAt(0) & 0xff;
        });
        this.send(new Uint8Array(bytes).buffer);
    };
}

    	var c = canvas.toDataURL('image/png');
        var encodedPng = c.substring(c.indexOf(',')+1,c.length);
        var decodedPng = atob(encodedPng);

        PostImageToFacebook(response.authResponse.accessToken, 'AlphabetNinja.png', 'image/png', decodedPng, '');
    }


	 function download() {

	 		hideForSaving();
	 		myElement = document.body;
    	    html2canvas(myElement).then(function(c) {
				// document.body.appendChild(canvas);

				// add element to on-screen invisible canvas
				imgData = getBase64Image(c);
				var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
				postToFb(canvas);
				// save hidden element to file
				// canvas.toBlob(function(blob) {

				//     // saveAs(blob, "alphabet-ninja.png");
				//     saveToFile(blob);

				// });
			});
	          		
    }
<commit_msg>playing with fb like button<commit_after>// whatthekeycode.<EMAIL>
//  define some global variables

$(document).ready(function () {


	  // $.ajaxSetup({ cache: true });
	  // $.getScript('http://connect.facebook.net/en_US/sdk.js', function(){
	  //   FB.init({
	  //     appId: '1484948608415623',
	  //     version: 'v2.0' // or v2.0, v2.1, v2.0
	  //   });     
	  //   $('#loginbutton,#feedbutton').removeAttr('disabled');
	  //   FB.getLoginStatus(updateStatusCallback);
	  // });

	var LOG = false, saving=false;
	var autoplay;
	document.getElementById("autoplay_check").checked = false;
	document.getElementById("englishflag").checked = true;

	$('#textbox').val('');

	var platform = navigator.platform;
	
	//  make height and width dynamic and always updated on resize
	$( window ).resize(function() {
		var viewport = {
		    width  : $(window).width(),
		    height : $(window).height()
		};

		if (LOG) console.log("height: " + viewport.height);
		if (LOG) console.log("width: " + viewport.width);
	});
			


	if (LOG) console.log(platform);

	function detectmob() { 
	 if( navigator.userAgent.match(/Android/i)
	 || navigator.userAgent.match(/webOS/i)
	 || navigator.userAgent.match(/iPhone/i)
	 || navigator.userAgent.match(/iPad/i)
	 || navigator.userAgent.match(/iPod/i)
	 || navigator.userAgent.match(/BlackBerry/i)
	 || navigator.userAgent.match(/Windows Phone/i)
	 ){
	    return true;
	  }
	 else {
	    return false;
	  }
	}

	// detect if device is mobile
	 var isMobile =  detectmob();

	 $(document).mousemove(function (e) {
		var mouseX = e.pageX; // e.pageX - gives you the X position.
		var mouseY = e.pageY; // e.pageY - gives you the Y position.
	});

	 // add element to on-screen canvas (hidden)
	 function getBase64Image(img) {
	    canvas = document.getElementById("my-canvas");
	    canvas.width = img.width;
	    canvas.height = img.height;
	    ctx = canvas.getContext("2d");
	    ctx.drawImage(img, 0, 0);
	    dataURL = canvas.toDataURL("image/png");
	    return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
	}

	function hideForSaving(){
 		$('#download').css('visibility','hidden');
 		$('#again').css('visibility','hidden');
 		$('#vocab').css('visibility','hidden');
 		$('#content').css('margin-top', '10%');
	}

	function prepareForDownload(){
		saving = !saving;
		document.getElementById('savingstate').innerHTML=flashDict[saving];
	}

	  function saveToServer(blob){
	  	var dateTimeInMs = new Date();
	  	var imageName = 'alphabet_ninja_';
	  	var extension = '.png"';
	  	var imageFileName = imageName.concat(dateTimeInMs).concat(extension);
	  	var pathName = '"../blobs/';
	  	var fullPathName = pathName.concat(imageFileName);
	  	console.log(fullPathName);

    	var data = new FormData();
		data.append("data" , blob);
		var xhr = new XMLHttpRequest();
		xhr.open( 'post', imageFileName, true );
		xhr.send(data);
    }

    function PostImageToFacebook( authToken, filename, mimeType, imageData, message )
{
    // this is the multipart/form-data boundary we'll use
    var boundary = '----ThisIsTheBoundary1234567890';
    
    // let's encode our image file, which is contained in the var
    var formData = '--' + boundary + '\r\n'
    formData += 'Content-Disposition: form-data; name="source"; filename="' + filename + '"\r\n';
    formData += 'Content-Type: ' + mimeType + '\r\n\r\n';
    for ( var i = 0; i < imageData.length; ++i )
    {
        formData += String.fromCharCode( imageData[ i ] & 0xff );
    }
    formData += '\r\n';
    formData += '--' + boundary + '\r\n';
    formData += 'Content-Disposition: form-data; name="message"\r\n\r\n';
    formData += message + '\r\n'
    formData += '--' + boundary + '--\r\n';
    
    var xhr = new XMLHttpRequest();
    xhr.open( 'POST', 'https://graph.facebook.com/me/photos?access_token=' + authToken, true );
    xhr.onload = xhr.onerror = function() {
        console.log( xhr.responseText );
    };
    xhr.setRequestHeader( "Content-Type", "multipart/form-data; boundary=" + boundary );
    xhr.sendAsBinary( formData );
}

    function postToFb(canvas){

    	if ( XMLHttpRequest.prototype.sendAsBinary === undefined ) {
    XMLHttpRequest.prototype.sendAsBinary = function(string) {
        var bytes = Array.prototype.map.call(string, function(c) {
            return c.charCodeAt(0) & 0xff;
        });
        this.send(new Uint8Array(bytes).buffer);
    };
}

    	var c = canvas.toDataURL('image/png');
        var encodedPng = c.substring(c.indexOf(',')+1,c.length);
        var decodedPng = atob(encodedPng);

        PostImageToFacebook(response.authResponse.accessToken, 'AlphabetNinja.png', 'image/png', decodedPng, '');
    }


	 function download() {

	 		hideForSaving();
	 		myElement = document.body;
    	    html2canvas(myElement).then(function(c) {
				// document.body.appendChild(canvas);

				// add element to on-screen invisible canvas
				imgData = getBase64Image(c);
				var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
				
				// postToFb(canvas);

				// save hidden element to file
				canvas.toBlob(function(blob) {

				    saveAs(blob, "alphabet-ninja.png");
				    //saveToServer(blob);

				});
			});
	          		
    }

{'fraction_non_alphanumeric': 0.17085330776605945, 'fraction_numerical': 0.010162991371045062, 'mean_word_length': 3.025858741798533, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1261395', 'n_tokens_mistral': 3752, 'n_tokens_neox': 3400, 'n_words': 668}