{"size": 4375, "ext": "js", "max_stars_repo_path": "ColorfulRubik'sCube/js/popup.js", "max_stars_repo_name": "maithanhduyan/auto-translate", "max_stars_repo_stars_event_min_datetime": "2021-05-09T03:41:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-09T03:41:42.000Z", "max_issues_repo_path": "ColorfulRubik'sCube/js/popup.js", "max_issues_repo_name": "maithanhduyan/chrome-extension", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ColorfulRubik'sCube/js/popup.js", "max_forks_repo_name": "maithanhduyan/chrome-extension", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.0, "max_line_length": 102, "alphanum_fraction": 0.5846857143}
//jQuery(document).ready(function($) {
//});

//function Scrolldown() { 
//	window.location = '#gameColumnWidth';
//}

//window.onload = Scrolldown;


(function($) {
			
	var userIsReading = false;
	var waitForFinalEvent = (function () {
		var timers = {};
		return function (callback, ms, uniqueId) {
			if (!uniqueId) {
				uniqueId = "Don't call this twice without a uniqueId";
			}
			if (timers[uniqueId]) {
				clearTimeout (timers[uniqueId]);
			}
			timers[uniqueId] = setTimeout(callback, ms);
		};
	})();
	
	//$(window).on('scroll', function() {
	//	//stop repositioning screen if user is reading about ttt
	//	if(!userIsReading && $(this).scrollTop() >= ($(".scores").offset().top + 100)){
	//		userIsReading = true;
	//	}
	//});
	
	$(window).resize(function() {
		
		waitForFinalEvent(function(){
	//		var wh = window.innerHeight;
	//		var cw = $('.game-column-width').width();
		
	//		var s = wh*0.7;
	//		var h = wh;
	//		if(cw/0.7 <= wh){
				
	//			h = cw/0.7;
	//			s = cw;
	//		}
	//		s = s < cw ? s : cw;
	//		$('.game-container').css('height',h);
	//		$('.game-container').css('width',s);
	//		$('.game').css('height', s);
			
			//SVGs are huge upon first loading when using percents. So, set initial values then remove
			$(".scores svg").removeAttr("style");
			//document.querySelector('.movescounter')
			
			
	//		if(!userIsReading){
	//			Scrolldown();
	//		}
		}, 500, "ID1");
	});
	
})( jQuery );
//TODO
//look at playing and turn and look at query selectors that try to find items that are no longer there

var ui = {
		mute: document.querySelector('.mute'),
		scores: {
			scores: document.querySelector('.scores'),
			swap: document.querySelector('.swap'),
			player1: document.querySelector('.player1 .score'),
			player2: document.querySelector('.player2 .score'),
			ties: document.querySelector('.ties .score'),
			turn1: document.querySelector('.player1'),
			turn2: document.querySelector('.player2'),
			turnTies: document.querySelector('.ties')
		}
	},		
	audio = {},
	hasLocalStorage, muted, playing, turn = true

function loadAudio(name) {
	var xhr = new XMLHttpRequest();
	xhr.open('GET', '/assets/audio/' + name + '.mp3', true);
	xhr.responseType = 'arraybuffer';
	xhr.onload = function() {
		context.decodeAudioData(xhr.response, function(buffer) {
			audio[name] = buffer;
		}, function() {});
	};
	xhr.send();
}

function playAudio(name) {
	if (muted || !audio[name]) {
	   return;
	}
	if (context && context.resume) {
		context.resume();
	}
	var source = context.createBufferSource();
	source.buffer = audio[name];
	source.connect(context.destination);
	if (source.start) {
		source.start(0);
	} else {
		source.noteOn(0);
	}
}

function updateMuteIcon() {
	var muteSoundWaves = ui.mute.querySelectorAll('path');
	for (var i = muteSoundWaves.length; i--;) {
		muteSoundWaves[i].style.display = muted ? 'none' : '';
	}
}

function toggleMute() {
	muted = !muted;
	if (hasLocalStorage) {
		try {
			localStorage.setItem('muted', muted.toString());
		} catch (e) {}
	}
	updateMuteIcon();
} 

(function() {

    function init() {	
		
        try {
            hasLocalStorage = 'localStorage' in window && window['localStorage'] !== null;
        } catch (e) {
            hasLocalStorage = false;
        }
        window.AudioContext = window.AudioContext || window.webkitAudioContext;
        if (window.AudioContext) {
            context = new AudioContext();
            loadAudio('solve');
            loadAudio('move');
            if (hasLocalStorage) {
                try {
                   muted = localStorage.getItem('muted') === 'true';
               } catch (e) {
                   muted = false;
               }
            }
            updateMuteIcon();
            ui.mute.ontouchstart = ui.mute.onclick = function(event) {
				event.stopPropagation();//avoid triggering tap from causing solve to be called
                event.preventDefault();
                toggleMute();
            };


        } else {
            ui.mute.style.display = 'none';
        }
        
        ui.scores.scores.ontouchend = ui.scores.scores.onclick = function(event) {
            event.preventDefault();
            if(!isSolved){
				//selecting solve after it's been solve causes bad things. Just close and reopen to reset
				solveCube(300);
				wasClickedToSolve = true;
			}			
        };

    }
	init();
}());

