Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
COM6009M
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bailey.barber-scar
COM6009M
Commits
60917418
Commit
60917418
authored
May 25, 2023
by
bailey.barber-scar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
03be3cb7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
784 additions
and
0 deletions
+784
-0
script.js
Front End/script.js
+784
-0
No files found.
Front End/script.js
0 → 100644
View file @
60917418
const
apiRequest
=
new
XMLHttpRequest
();
const
apiURL
=
"
http://ysjcs.net:5002/
"
;
window
.
onload
=
function
()
{
$
(
"
body
"
).
removeClass
(
"
preload
"
);
//Script used for the dynamic NavBar
const
theBody
=
document
.
querySelector
(
'
body
'
);
const
openNav
=
document
.
querySelector
(
'
.menu-bar button
'
);
const
closeNav
=
document
.
querySelector
(
'
.close-nav button
'
);
const
Navbar
=
document
.
querySelector
(
'
.navbar
'
);
function
bodyScroll
()
{
if
(
Navbar
.
classList
.
contains
(
'
show
'
))
{
theBody
.
classList
.
add
(
'
hide-scroll
'
);
}
else
if
(
theBody
.
classList
.
contains
(
'
hide-scroll
'
))
{
theBody
.
classList
.
remove
(
'
hide-scroll
'
);
}
}
function
showHide
()
{
Navbar
.
classList
.
toggle
(
'
show
'
);
bodyScroll
();
}
openNav
.
onclick
=
showHide
;
closeNav
.
onclick
=
showHide
;
authUser
(
localStorage
.
getItem
(
"
usertoken
"
));
accountPage_LoadUserDetails
();
}
function
openLoginForm
()
{
closeSignUpForm
();
document
.
getElementById
(
"
loginForm
"
).
style
.
display
=
"
block
"
;
}
function
closeLoginForm
()
{
document
.
getElementById
(
"
loginForm
"
).
style
.
display
=
"
none
"
;
}
function
openSignUpForm
()
{
closeLoginForm
();
document
.
getElementById
(
"
signupForm
"
).
style
.
display
=
"
block
"
;
}
function
closeSignUpForm
()
{
document
.
getElementById
(
"
signupForm
"
).
style
.
display
=
"
none
"
;
}
function
login
()
{
const
loginData
=
{
username
:
document
.
getElementById
(
"
loginUsername
"
).
value
,
password
:
document
.
getElementById
(
"
loginPassword
"
).
value
};
var
loginReply
=
document
.
getElementById
(
"
loginResponse
"
);
$
.
ajax
({
url
:
apiURL
+
"
login
"
,
type
:
"
POST
"
,
data
:
JSON
.
stringify
(
loginData
),
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
localStorage
.
setItem
(
"
usertoken
"
,
data
.
token
)
// Show success message
loginReply
.
style
.
backgroundColor
=
"
lightgreen
"
;
loginReply
.
style
.
color
=
"
white
"
;
$
(
"
#loginResponse
"
).
text
(
"
Successfully logged in!
"
);
loginReply
.
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
accountNavLink
"
).
style
.
display
=
"
block
"
;
setInterval
(
'
location.reload()
'
,
1000
);
return
;
}
},
error
:
function
(
jqXHR
,
textStatus
,
error
)
{
console
.
error
(
error
);
console
.
error
(
jqXHR
.
status
);
if
(
jqXHR
.
status
===
401
)
{
// Show failed message
loginReply
.
style
.
backgroundColor
=
"
red
"
;
loginReply
.
style
.
color
=
"
white
"
;
$
(
"
#loginResponse
"
).
text
(
"
Incorrect details.
"
);
loginReply
.
style
.
display
=
"
block
"
;
console
.
log
(
jqXHR
.
status
);
}
else
{
// Show failed message
loginReply
.
style
.
backgroundColor
=
"
orange
"
;
loginReply
.
style
.
color
=
"
gray
"
;
$
(
"
#loginResponse
"
).
text
(
"
Unable to reach server.
"
);
loginReply
.
style
.
display
=
"
block
"
;
}
}
})
}
function
registerUser
()
{
const
newUserData
=
{
username
:
document
.
getElementById
(
"
registerUsername
"
).
value
,
password
:
document
.
getElementById
(
"
registerPassword
"
).
value
};
var
registerReply
=
document
.
getElementById
(
"
registerResponse
"
);
// Check if password is at least 6 characters long
if
(
newUserData
.
password
.
length
<
6
)
{
// Show failed message
registerReply
.
style
.
backgroundColor
=
"
red
"
;
registerReply
.
style
.
color
=
"
white
"
;
$
(
"
#registerResponse
"
).
text
(
"
Password must be at least 6 characters long.
"
);
registerReply
.
style
.
display
=
"
block
"
;
return
;
}
// Check if passwords match
if
(
newUserData
.
password
!=
document
.
getElementById
(
"
registerPasswordConfirm
"
).
value
)
{
// Show failed message
registerReply
.
style
.
backgroundColor
=
"
red
"
;
registerReply
.
style
.
color
=
"
white
"
;
$
(
"
#registerResponse
"
).
text
(
"
Passwords do not match.
"
);
document
.
getElementById
(
"
registerPasswordConfirm
"
).
style
.
border
=
"
2px solid red
"
;
registerReply
.
style
.
display
=
"
block
"
;
return
;
}
$
.
ajax
({
url
:
apiURL
+
"
register
"
,
type
:
"
POST
"
,
data
:
JSON
.
stringify
(
newUserData
),
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
// Show failed message
registerReply
.
style
.
backgroundColor
=
"
lightgreen
"
;
registerReply
.
style
.
color
=
"
white
"
;
$
(
"
#registerResponse
"
).
text
(
"
Account successfully created!
"
);
registerReply
.
style
.
display
=
"
block
"
;
return
;
}
},
error
:
function
(
jqXHR
,
textStatus
,
error
)
{
console
.
error
(
error
);
console
.
error
(
jqXHR
.
status
);
if
(
jqXHR
.
status
===
401
)
{
// Show failed message
registerReply
.
style
.
backgroundColor
=
"
red
"
;
registerReply
.
style
.
color
=
"
white
"
;
$
(
"
#registerResponse
"
).
text
(
"
This username is already taken.
"
);
registerReply
.
style
.
display
=
"
block
"
;
console
.
log
(
jqXHR
.
status
);
return
;
}
else
{
// Show failed message
registerReply
.
style
.
backgroundColor
=
"
orange
"
;
registerReply
.
style
.
color
=
"
gray
"
;
$
(
"
#registerResponse
"
).
text
(
"
Unable to reach server.
"
);
registerReply
.
style
.
display
=
"
block
"
;
return
;
}
}
})
}
function
authUser
(
userToken
)
{
$
.
ajax
({
url
:
apiURL
+
"
authUser/
"
+
userToken
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
// We have a login if the status is 200
if
(
jqXHR
.
status
===
200
)
{
// If the user is logged in, set our HTML to match
$
(
"
#btnLogin span.text
"
).
text
(
"
Logout
"
);
$
(
"
#btnLogin
"
).
attr
(
"
onclick
"
,
"
logout()
"
);
document
.
getElementById
(
"
accountNavLink
"
).
style
.
display
=
"
block
"
;
$
(
"
#homeWelcomeText
"
).
text
(
"
Welcome back,
"
+
data
.
data
.
user
.
username
);
$
(
"
#homeWelcomeText
"
).
css
(
"
font-weight
"
,
"
bold
"
);
}
else
{
}
},
complete
:
function
()
{
$
(
'
#loading
'
).
hide
();
// Hide the loading overlay
}
});
}
function
logout
()
{
localStorage
.
clear
();
window
.
location
.
href
=
"
index.html
"
;
}
$
(
document
).
ready
(
function
()
{
var
targetDiv
=
$
(
'
#homeInfo
'
);
if
(
targetDiv
.
length
>
0
)
{
loadHomeInfo
();
}
});
function
loadHomeInfo
()
{
currentUserToken
=
localStorage
.
getItem
(
"
usertoken
"
);
// Check if we have any game tags for the user
$
.
ajax
({
url
:
apiURL
+
"
getUserGameTags/
"
+
localStorage
.
getItem
(
"
usertoken
"
),
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
$
(
"
#homeUserGameTags
"
).
show
();
// If we get an OK response, fill in the data if we have anything
if
(
data
.
data
[
0
]
!=
null
)
{
gameTags
=
data
.
data
[
0
];
if
(
gameTags
.
battlenet
!=
null
)
{
$
(
"
#homeBattleNet
"
).
show
();
$
(
"
#homeBattleNetIdStatus
"
).
removeClass
();
$
(
"
#homeBattleNetIdStatus
"
).
addClass
(
"
homeUserGameTagConnected
"
);
$
(
"
#homeBattleNetIdStatus
"
).
text
(
"
Connected
"
);
}
else
{
$
(
"
#homeBattleNet
"
).
show
();
$
(
"
#homeBattleNetIdStatus
"
).
removeClass
();
$
(
"
#homeBattleNetIdStatus
"
).
addClass
(
"
homeUserGameTagNotConnected
"
);
$
(
"
#homeBattleNetIdStatus
"
).
text
(
"
Not Connected
"
);
}
if
(
gameTags
.
riotid
!=
null
)
{
$
(
"
#homeRiotId
"
).
show
();
$
(
"
#homeRiotIdStatus
"
).
removeClass
();
$
(
"
#homeRiotIdStatus
"
).
addClass
(
"
homeUserGameTagConnected
"
);
$
(
"
#homeRiotIdStatus
"
).
text
(
"
Connected
"
);
}
else
{
$
(
"
#homeRiotId
"
).
show
();
$
(
"
#homeRiotIdStatus
"
).
removeClass
();
$
(
"
#homeRiotIdStatus
"
).
addClass
(
"
homeUserGameTagNotConnected
"
);
$
(
"
#homeRiotIdStatus
"
).
text
(
"
Not Connected
"
);
}
}
else
{
$
(
"
#homeRiotId
"
).
show
();
$
(
"
#homeRiotIdStatus
"
).
removeClass
();
$
(
"
#homeRiotIdStatus
"
).
addClass
(
"
homeUserGameTagNotConnected
"
);
$
(
"
#homeRiotIdStatus
"
).
text
(
"
Not Connected
"
);
$
(
"
#homeBattleNet
"
).
show
();
$
(
"
#homeBattleNetIdStatus
"
).
removeClass
();
$
(
"
#homeBattleNetIdStatus
"
).
addClass
(
"
homeUserGameTagNotConnected
"
);
$
(
"
#homeBattleNetIdStatus
"
).
text
(
"
Not Connected
"
);
}
}
else
{
// Show failed message
console
.
warn
(
"
Unable to get game tags. Status:
"
+
jqXHR
.
status
);
return
;
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
error
(
"
AJAX request failed:
"
,
textStatus
,
errorThrown
);
// Handle the error here as needed
$
(
"
#homeUserGameTags
"
).
hide
();
}
});
}
function
showPassword
()
{
var
passwordInput
=
document
.
getElementById
(
"
userdetails_password
"
);
var
showButton
=
document
.
querySelector
(
"
.show-pass-button
"
);
if
(
passwordInput
.
type
===
"
password
"
)
{
passwordInput
.
type
=
"
text
"
;
showButton
.
innerHTML
=
'
<i class="fa fa-eye"></i>
'
;
// Change icon to hide symbol
showButton
.
style
.
backgroundColor
=
"
lightgreen
"
;
}
else
{
passwordInput
.
type
=
"
password
"
;
showButton
.
innerHTML
=
'
<i class="fa fa-eye-slash"></i>
'
;
// Change icon to show symbol
showButton
.
style
.
backgroundColor
=
"
#F08080
"
;
}
}
function
copyPassword
()
{
var
passwordInput
=
document
.
getElementById
(
"
userdetails_password
"
);
var
copyButton
=
document
.
querySelector
(
"
.copy-pass-button
"
);
// Copy the password to clipboard
passwordInput
.
select
();
document
.
execCommand
(
"
copy
"
);
// Provide visual feedback to the user
copyButton
.
innerHTML
=
"
Copied!
"
;
setTimeout
(
function
()
{
copyButton
.
innerHTML
=
'
<i class="fa fa-clone"></i>
'
;
},
1500
);
}
function
accountPage_LoadUserDetails
()
{
currentUserToken
=
localStorage
.
getItem
(
"
usertoken
"
);
//Get the user data
$
.
ajax
({
url
:
apiURL
+
"
getUserData/
"
+
currentUserToken
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
,
error
)
{
// We have a login if the status is 200
console
.
log
(
jqXHR
.
status
);
if
(
jqXHR
.
status
===
200
)
{
// If we get data, lets set the user details up
$
(
"
#userdetails_username
"
).
val
(
data
.
data
.
user
.
username
);
$
(
"
#userdetails_titleUser
"
).
text
(
data
.
data
.
user
.
username
);
$
(
"
#userdetails_password
"
).
val
(
data
.
data
.
user
.
password
);
// Check if we have any game tags for the user
$
.
ajax
({
url
:
apiURL
+
"
getUserGameTags/
"
+
currentUserToken
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
//If we get a OK response, fill in the data if we have anything
if
(
data
.
data
[
0
]
!=
null
)
{
$
(
"
#battleNetInput
"
).
val
(
data
.
data
[
0
].
battlenet
);
$
(
"
#riotIdInput
"
).
val
(
data
.
data
[
0
].
riotid
);
}
}
else
{
// Show failed message
console
.
warn
(
"
Unable to get game tags:
"
+
error
);
return
;
}
}
})
if
(
data
.
data
.
user
.
isAdmin
==
0
)
{
// Change the text
$
(
"
#userdetails_role
"
).
text
(
"
USER
"
);
// Change the class name
$
(
"
#userdetails_role
"
).
removeClass
().
addClass
(
"
role-user
"
);
}
else
if
(
data
.
data
.
user
.
isAdmin
==
1
)
{
// Change the text
$
(
"
#userdetails_role
"
).
text
(
"
ADMIN
"
);
// Change the class name
$
(
"
#userdetails_role
"
).
removeClass
().
addClass
(
"
role-admin
"
);
}
}
else
{
console
.
log
(
"
User not logged in
"
);
}
},
complete
:
function
()
{
$
(
'
#loading
'
).
hide
();
// Hide the loading overlay
}
});
}
function
updateGamesTags
()
{
var
battlenetValue
=
$
(
"
#battleNetInput
"
).
val
();
var
riotidValue
=
$
(
"
#riotIdInput
"
).
val
();
var
currentUserToken
=
localStorage
.
getItem
(
"
usertoken
"
);
// Prepare the payload with battlenet and riotid values
var
payload
=
{
"
battlenet
"
:
battlenetValue
,
"
riotid
"
:
riotidValue
};
$
.
ajax
({
url
:
apiURL
+
"
getUserGameTags/
"
+
currentUserToken
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
// If user game tags exist, perform an update
$
.
ajax
({
url
:
apiURL
+
"
updateUserGameTags/
"
+
currentUserToken
,
type
:
"
POST
"
,
data
:
JSON
.
stringify
(
payload
),
contentType
:
"
application/json
"
,
success
:
function
(
response
)
{
$
(
"
#saveGameTagsBtn
"
).
text
(
"
✔ Game Tags Updated
"
);
setTimeout
(
function
()
{
$
(
"
#saveGameTagsBtn
"
).
text
(
"
Save
"
);
},
2500
);
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
"
#saveGameTagsBtn
"
).
text
(
"
✘ An error occured
"
);
$
(
"
#saveGameTagsBtn
"
).
css
(
"
background-color
"
,
"
red
"
);
setTimeout
(
function
()
{
$
(
"
#saveGameTagsBtn
"
).
text
(
"
Save
"
);
$
(
"
#saveGameTagsBtn
"
).
css
(
"
background-color
"
,
"
lightgreen
"
);
},
2500
);
}
});
}
else
{
// If user game tags don't exist, perform an insert
$
.
ajax
({
url
:
apiURL
+
"
insertUserGameTags/
"
+
currentUserToken
,
type
:
"
POST
"
,
data
:
JSON
.
stringify
(
payload
),
contentType
:
"
application/json
"
,
success
:
function
(
response
)
{
console
.
log
(
"
Game tags inserted successfully!
"
);
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
error
(
"
Error inserting game tags:
"
+
errorThrown
);
}
});
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
error
(
"
Error getting user game tags:
"
+
errorThrown
);
$
(
"
#saveGameTagsBtn
"
).
text
(
"
✘ An error occured
"
);
$
(
"
#saveGameTagsBtn
"
).
css
(
"
background-color
"
,
"
red
"
);
setTimeout
(
function
()
{
$
(
"
#saveGameTagsBtn
"
).
text
(
"
Save
"
);
$
(
"
#saveGameTagsBtn
"
).
css
(
"
background-color
"
,
"
lightgreen
"
);
},
2500
);
}
});
setInterval
(
'
location.reload()
'
,
1000
);
}
$
(
document
).
ready
(
function
()
{
var
targetDiv
=
$
(
'
#userOverwatchStats
'
);
if
(
targetDiv
.
length
>
0
)
{
getUserOverwatchStats
();
}
});
function
getUserOverwatchStats
()
{
//https://overfast-api.tekrop.fr/players/{player_id}/summary
currentUserToken
=
localStorage
.
getItem
(
"
usertoken
"
);
// Check if we have any game tags for the user
$
.
ajax
({
url
:
apiURL
+
"
getUserGameTags/
"
+
currentUserToken
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
//If we get a OK response, fill in the data if we have anything
if
(
data
.
data
[
0
]
!=
null
)
{
userBattleId
=
JSON
.
stringify
(
data
.
data
[
0
].
battlenet
);
userBattleId
=
userBattleId
.
replace
(
/"/g
,
''
);
if
(
userBattleId
.
length
>
0
)
{
apiGetUserOverwatchStats
(
userBattleId
);
$
(
"
#userOverwatchStats
"
).
css
(
"
display
"
,
"
block
"
);
}
else
{
$
(
"
#userOverwatchStats
"
).
css
(
"
display
"
,
"
none
"
);
}
}
}
else
{
// IF WE FAIL TO GET IT THEY HAVE NOT SET A GAME TAG SO WE NEED TO REMOVE THE DIV
$
(
"
#userOverwatchStats
"
).
css
(
"
display
"
,
"
none
"
);
return
;
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
if
(
jqXHR
.
status
===
404
)
{
// Player not found
$
(
"
#userOverwatchStats
"
).
hide
();
}
else
{
// Handle other errors
console
.
error
(
"
Error:
"
,
textStatus
,
errorThrown
);
}
}
})
}
function
titleCase
(
string
)
{
var
sentence
=
string
.
toLowerCase
().
split
(
"
"
);
for
(
var
i
=
0
;
i
<
sentence
.
length
;
i
++
){
sentence
[
i
]
=
sentence
[
i
][
0
].
toUpperCase
()
+
sentence
[
i
].
slice
(
1
);
}
return
sentence
;
}
function
apiGetUserOverwatchStats
(
battlenetid
)
{
// Replace "#" with "-"
var
modifiedPlayerId
=
battlenetid
.
replace
(
"
#
"
,
"
-
"
);
//Fill in name, title, icon, comp ranks
$
.
ajax
({
url
:
"
https://overfast-api.tekrop.fr/players/
"
+
modifiedPlayerId
,
type
:
"
GET
"
,
dataType
:
"
json
"
,
success
:
function
(
data
)
{
//Fill in the data
$
(
"
#userOWName
"
).
text
(
battlenetid
)
$
(
"
#userOWTitle
"
).
text
(
data
.
summary
.
title
)
$
(
"
#userOWAvatar
"
).
attr
(
"
src
"
,
data
.
summary
.
avatar
)
//Check if the profile is private, if it is, we can't get competitve data
if
(
data
.
summary
.
privacy
!==
"
public
"
)
{
// Handle private profile
$
(
"
#userOWPrivateProfile
"
).
show
()
$
(
"
#userOWMostPlayedRankedHeroHours
"
).
text
(
"
Private Profile. No Data Available.
"
)
}
else
{
$
(
"
#userOWPrivateProfile
"
).
hide
()
// Access and update tank rank_icon
var
tankRankIcon
=
data
.
summary
.
competitive
.
pc
.
tank
.
rank_icon
;
$
(
"
#userOWRankTankIcon
"
).
attr
(
"
src
"
,
tankRankIcon
);
$
(
"
#userOWRankTankText
"
).
text
(
titleCase
(
data
.
summary
.
competitive
.
pc
.
tank
.
division
)
+
"
"
+
data
.
summary
.
competitive
.
pc
.
tank
.
tier
);
// Access and update DPS rank_icon
var
dpsRankIcon
=
data
.
summary
.
competitive
.
pc
.
damage
.
rank_icon
;
$
(
"
#userOWRankDPSIcon
"
).
attr
(
"
src
"
,
dpsRankIcon
);
$
(
"
#userOWRankDPSText
"
).
text
(
titleCase
(
data
.
summary
.
competitive
.
pc
.
damage
.
division
)
+
"
"
+
data
.
summary
.
competitive
.
pc
.
damage
.
tier
);
// Access and update support rank_icon
var
supportRankIcon
=
data
.
summary
.
competitive
.
pc
.
support
.
rank_icon
;
$
(
"
#userOWRankSupportIcon
"
).
attr
(
"
src
"
,
supportRankIcon
);
$
(
"
#userOWRankSupportText
"
).
text
(
titleCase
(
data
.
summary
.
competitive
.
pc
.
support
.
division
)
+
"
"
+
data
.
summary
.
competitive
.
pc
.
support
.
tier
);
//Access and update most played ranked hero
//Sort the most played heroes by play time
var
mostPlayedRankedHero
=
data
.
stats
.
pc
.
competitive
.
heroes_comparisons
.
time_played
.
values
[
0
];
mostPlayedHeroId
=
mostPlayedRankedHero
.
hero
.
replace
(
/"/g
,
''
);
//Get Hero Icon
$
.
ajax
({
url
:
"
https://overfast-api.tekrop.fr/heroes/
"
+
mostPlayedHeroId
,
type
:
"
GET
"
,
dataType
:
"
json
"
,
success
:
function
(
data
)
{
$
(
"
#userOWMostPlayedRankedHeroIcon
"
).
attr
(
"
src
"
,
data
.
portrait
)
}
})
$
(
"
#userOWMostPlayedRankedHeroName
"
).
text
(
titleCase
(
mostPlayedRankedHero
.
hero
))
$
(
"
#userOWMostPlayedRankedHeroHours
"
).
text
(
"
(
"
+
Math
.
floor
((
mostPlayedRankedHero
.
value
)
/
3600
)
+
"
hours)
"
)
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
// Player not found
console
.
log
(
"
Player not found
"
);
$
(
"
#userOWName
"
).
text
(
"
Player
"
+
battlenetid
+
"
not found.
"
)
$
(
"
#owRankedStatsTitle
"
).
hide
();
$
(
"
#owRankedStats
"
).
hide
();
$
(
"
#owMostPlayedHero
"
).
hide
();
// Handle other errors
console
.
log
(
"
Error:
"
,
textStatus
,
errorThrown
);
}
});
}
$
(
document
).
ready
(
function
()
{
var
targetDiv
=
$
(
'
#userValorantStats
'
);
if
(
targetDiv
.
length
>
0
)
{
getUserValorantStats
();
}
});
function
getUserValorantStats
()
{
currentUserToken
=
localStorage
.
getItem
(
"
usertoken
"
);
//Check if the user has any RiotID
$
.
ajax
({
url
:
apiURL
+
"
getUserGameTags/
"
+
currentUserToken
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
===
200
)
{
//If we get a OK response, fill in the data if we have anything
if
(
data
.
data
[
0
]
!=
null
)
{
userRiotId
=
JSON
.
stringify
(
data
.
data
[
0
].
riotid
);
userRiotId
=
userRiotId
.
replace
(
/"/g
,
''
);
if
(
userRiotId
.
length
>
2
)
{
apiGetUserValorantStats
(
userRiotId
);
$
(
"
#userValorantStats
"
).
css
(
"
display
"
,
"
block
"
);
}
else
{
$
(
"
#userValorantStats
"
).
css
(
"
display
"
,
"
none
"
);
}
}
}
else
{
// IF WE FAIL TO GET IT THEY HAVE NOT SET A GAME TAG SO WE NEED TO REMOVE THE DIV
$
(
"
#userValorantStats
"
).
css
(
"
display
"
,
"
none
"
);
return
;
}
}
})
}
function
apiGetUserValorantStats
(
riotId
)
{
//We need to seperate the tag from the username
riotId
=
riotId
.
split
(
"
#
"
);
riotIdName
=
riotId
[
0
];
riotIdTag
=
riotId
[
1
];
//Get our basic user info
$
.
ajax
({
url
:
"
https://api.henrikdev.xyz/valorant/v1/account/
"
+
riotIdName
+
"
/
"
+
riotIdTag
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
//We get a valid account
if
(
jqXHR
.
status
===
200
)
{
//Fill in basic user info
$
(
"
#userValCard
"
).
attr
(
"
src
"
,
data
.
data
.
card
.
small
);
$
(
"
#userValName
"
).
text
(
data
.
data
.
name
);
$
(
"
#userValTag
"
).
text
(
"
#
"
+
data
.
data
.
tag
);
$
(
"
#userValLevel
"
).
text
(
"
Level
"
+
data
.
data
.
account_level
)
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
// Handle other errors
console
.
log
(
"
Error:
"
,
textStatus
,
errorThrown
);
$
(
"
#userValName
"
).
hide
();
$
(
"
#userValTag
"
).
text
(
"
User
"
+
riotId
+
"
not found.
"
);
$
(
"
#userValLevel
"
).
hide
();
$
(
"
#userValRankedStats
"
).
hide
();
$
(
"
#userValLastMatchStatsTitle
"
).
hide
();
$
(
"
#userValMapTitle
"
).
hide
();
$
(
"
#userValLastMapName
"
).
hide
();
$
(
"
#userValStats
"
).
hide
();
$
(
"
#userValLastPlayedHero
"
).
hide
();
}
});
//Get ranked data
//Get our ranked data
$
.
ajax
({
url
:
"
https://api.henrikdev.xyz/valorant/v1/mmr-history/eu/
"
+
riotIdName
+
"
/
"
+
riotIdTag
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
//We get a valid account
if
(
jqXHR
.
status
===
200
)
{
//Fill in basic user info
$
(
"
#userValRankIcon
"
).
attr
(
"
src
"
,
data
.
data
[
0
].
images
.
small
);
$
(
"
#userValRank
"
).
text
(
data
.
data
[
0
].
currenttierpatched
);
if
(
data
.
data
[
0
].
mmr_change_to_last_game
>
0
)
{
$
(
"
#userValMMRChange
"
).
css
(
"
color
"
,
"
lightgreen
"
)
}
else
if
(
data
.
data
[
0
].
mmr_change_to_last_game
<
0
)
{
$
(
"
#userValMMRChange
"
).
css
(
"
color
"
,
"
red
"
)
}
else
{
$
(
"
#userValMMRChange
"
).
css
(
"
color
"
,
"
lightgray
"
)
}
$
(
"
#userValMMRChange
"
).
text
(
"
(
"
+
data
.
data
[
0
].
mmr_change_to_last_game
+
"
)
"
);
lastMatchId
=
data
.
data
[
0
].
match_id
;
//Get data from last match
$
.
ajax
({
url
:
"
https://api.henrikdev.xyz/valorant/v2/match/
"
+
lastMatchId
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
//We get a valid account
if
(
jqXHR
.
status
===
200
)
{
//Fill in the match data
$
(
"
#userValLastMapName
"
).
text
(
data
.
data
.
metadata
.
map
);
//playerData
playerData
=
data
.
data
.
players
.
all_players
;
filteredPlayer
=
playerData
.
filter
(
function
(
player
)
{
return
player
.
name
==
riotIdName
})
$
(
"
#userValStatKD
"
).
text
((
filteredPlayer
[
0
].
stats
.
kills
/
filteredPlayer
[
0
].
stats
.
deaths
).
toFixed
(
2
))
$
(
"
#userValStatHeadshots
"
).
text
(
filteredPlayer
[
0
].
stats
.
headshots
)
$
(
"
#userValStatLength
"
).
text
(
filteredPlayer
[
0
].
session_playtime
.
minutes
+
"
m
"
)
$
(
"
#userValLastPlayedHeroName
"
).
text
(
filteredPlayer
[
0
].
character
)
$
(
"
#userValLastPlayedHeroImg
"
).
attr
(
"
src
"
,
filteredPlayer
[
0
].
assets
.
agent
.
small
)
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
if
(
jqXHR
.
status
===
404
)
{
// Player not found
console
.
log
(
"
Player not found
"
);
}
else
{
// Handle other errors
console
.
log
(
"
Error:
"
,
textStatus
,
errorThrown
);
}
}
});
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
if
(
jqXHR
.
status
===
404
)
{
// Player not found
console
.
log
(
"
Player not found
"
);
}
else
{
// Handle other errors
console
.
log
(
"
Error:
"
,
textStatus
,
errorThrown
);
}
}
});
}
$
(
document
).
ready
(
function
()
{
var
targetDiv
=
$
(
'
#playerList
'
);
if
(
targetDiv
.
length
>
0
)
{
getAllPlayers
();
}
});
function
getAllPlayers
()
{
//Get data from last match
const
playerListElement
=
document
.
getElementById
(
"
playerList
"
);
$
.
ajax
({
url
:
apiURL
+
"
/getAllPlayers
"
,
type
:
"
GET
"
,
contentType
:
"
application/json
"
,
dataType
:
"
json
"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
//We get a valid account
if
(
jqXHR
.
status
===
200
)
{
if
(
data
.
length
>
0
)
{
let
html
=
""
;
data
.
forEach
(
entry
=>
{
const
{
username
,
battlenet
,
riotid
,
admin
}
=
entry
;
let
playerTagsHTML
=
""
;
if
(
battlenet
!==
null
&&
battlenet
!==
""
)
{
playerTagsHTML
+=
`<span class="playerBattleNet"><img src="https://static.wikia.nocookie.net/logopedia/images/f/f6/Battle.net_2021_Icon.svg">
${
battlenet
}
</span>`
;
}
if
(
riotid
!==
null
&&
riotid
!==
""
)
{
playerTagsHTML
+=
`<span class="playerRiotID"><img src="https://www.svgrepo.com/show/424912/valorant-logo-play-2.svg">
${
riotid
}
</span>`
;
}
else
{
playerTagsHTML
+=
`<span class="playerNoTags">No Game Tags</span>`
;
}
const
playerHTML
=
`
<div class="player">
<p><span class="player-name">
${
username
}
</span> <span class="playerTags">
${
playerTagsHTML
}
</span></p>
</div>
`
;
html
+=
playerHTML
;
});
playerListElement
.
innerHTML
=
html
;
}
else
{
noPlayersHTML
=
`<span class="noPlayersFound">No players found.</span>`
playerListElement
.
innerHTML
=
noPlayersHTML
;
}
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
if
(
jqXHR
.
status
===
404
)
{
// Player not found
noPlayersHTML
=
`<span class="noPlayersFound">No players found.</span>`
playerListElement
.
innerHTML
=
noPlayersHTML
;
console
.
log
(
"
Players not found
"
);
}
else
{
// Unable to communicate to server
noServerConnectionHTML
=
`<span class="noServerConnection">Cannot retrieve data. No connection to server.</span>`
playerListElement
.
innerHTML
=
noServerConnectionHTML
;
console
.
log
(
"
Error:
"
,
textStatus
,
errorThrown
);
}
}
});
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment