-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
146 lines (119 loc) · 4.57 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="en">
<head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta charset="UTF-8">
<body>
<div class="container">
<h1 class="display-4">Pusher's Christmas Angel</h1>
<div class="row">
<div class="col-4">
<h3>Hex Colour 🖍</h3>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text">#</div>
</div>
<input type="text" class="form-control" id="txtColour"
placeholder="ffcc00">
</div>
<button type="button" class="btn btn-light"
onclick="sendHexColour()">Send hex</button>
<hr/>
<h3>Simple Colour ✏️</h3>
<button type="button" class="btn btn-danger"
onclick="sendSimpleColour('red')">Red</button>
<button type="button" class="btn btn-warning"
onclick="sendSimpleColour('yellow')">Yellow</button>
<button type="button" class="btn btn-success"
onclick="sendSimpleColour('green')">Green</button>
<button type="button" class="btn btn-primary"
onclick="sendSimpleColour('blue')">Blue</button>
<button type="button" class="btn btn-light"
onclick="sendSimpleColour('white')">White</button>
<hr/>
<h3>Special Modes ✨</h3>
<button type="button" class="btn btn-light"
onclick="sendColour('pusher')">Pusher</button>
<button type="button" class="btn btn-light"
onclick="sendColour('pusher-beams')">Pusher Beams</button>
<button type="button" class="btn btn-light"
onclick="sendColour('pusher-channels')">Pusher Channels</button>
<button type="button" class="btn btn-light"
onclick="sendColour('pusher-chatkit')">Pusher Chatkit</button>
<hr/>
<h3>Recent Events 💌</h3>
<div id="containerMessages">
</div>
</div>
</div>
</div>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-48817663-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-48817663-5');
</script>
<script src="https://js.pusher.com/5.0/pusher.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://js.pusher.com/5.0/pusher.min.js"></script>
<script>
function connectToPusher() {
var pusher = new Pusher('5b1e6772b0fa4040f5a6', {
cluster: 'eu',
forceTLS: true
});
var channel = pusher.subscribe('angel');
channel.bind('new-colour', function(data) {
console.log(JSON.stringify(data));
let element = `<span class="badge badge-secondary"
style="background-color:${data.responseColour};">${data.responseColour}</span>`
document.getElementById('containerMessages').insertAdjacentHTML('beforeend', element);
});
}
connectToPusher()
let sendSimpleColour= colourWord => {
if (colourWord == "red") {
sendColour("#dc3545")
} else if (colourWord == "yellow") {
sendColour("#ffc107")
} else if (colourWord == "green") {
sendColour("#28a745")
} else if (colourWord == "blue") {
sendColour("#007bff")
} else if (colourWord == "white") {
sendColour("#ffffff")
}
}
let sendHexColour = () => {
let colour = document.getElementById("txtColour").value
if (colour.length != 6) {
alert("hex colour needs to be 6 characters, without the #")
} else {
sendColour("#" + colour)
}
}
let sendColour = colour => {
gtag('event', "send-color", {
'event_category': "colour",
'event_label': "colour",
'value': colour
});
fetch("api/colour", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ colour })
}).then(response => console.log(response))
return
}
</script>
</body>
</html>