-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchallenge.js
40 lines (38 loc) · 1.41 KB
/
challenge.js
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
$(".generate-button").on("click", function(event){
$(".potential-error").first().css("display", "none")
$(".link-button").css("display", "none")
wca_id = $(".wca-id-input").first().val()
guesses = parseInt($(".guesses-no-input").first().val())
// check number
if(isNaN(guesses)){
$(".potential-error").first().text("no of guesses needs to be a number")
$(".potential-error").first().css("display", "inline")
return
}
// check wca id
$.ajax({
type: 'GET',
url: "https://www.worldcubeassociation.org/api/v0/persons/" + wca_id,
dataType:'json',
error: function(){
$(".potential-error").first().text("cant validate wca id")
$(".potential-error").first().css("display", "inline")
},
success: function(result){
final_object =
{
wca: wca_id,
guesses: guesses
}
challenge_code = btoa(JSON.stringify(final_object))
challenge_link = URI(window.location.href).filename("index.html").query({challenge: challenge_code}).toString()
console.log(challenge_link)
$(".link-button").css("display", "inline")
$(".link-button").on("click", function(event){
navigator.clipboard.writeText(challenge_link);
alert("link copied")
})
}
}
)
})