summaryrefslogtreecommitdiff
path: root/static/scripts/gb.js
blob: 67afe20555c6cb95573d2e16bd012deb54d3b059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Handle image refresh.
var newImage;
window.onload = function (){
	reimg = document.getElementById('game_img');
	setInterval(function (){
		reimg.src = 'https://gb.luevano.xyz/image?r=' + Math.random();
	}, 1000)
}

function input(button){

	if(typeof button == 'number'){
		$.ajax({
			url: 'https://gb.luevano.xyz/control?button=' + button + '&callback=https://gb.luevano.xyz',
			type: 'GET',
			complete: function(xhr){
				let statusCode = xhr.status;
				if(statusCode >= 400){
					console.log('Error code: ' + statusCode + '. On input: ' + button);
				}
			}
			});
	}
}

// jQuery/ajax for handling input.
$(document).ready(function (){

	$('#btn_right').click(function (){
		input(0);
	});

	$('#btn_left').click(function (){
		input(1);
	});

	$('#btn_up').click(function (){
		input(2);
	});

	$('#btn_down').click(function (){
		input(3);
	});

	$('#btn_a').click(function (){
		input(4);
	});

	$('#btn_b').click(function (){
		input(5);
	});

	$('#btn_select').click(function (){
		input(6);
	});

	$('#btn_start').click(function (){
		input(7);
	});

});