Created
March 15, 2021 17:30
-
-
Save NoCtrlZ1110/a6c7286a7a6aacae73ffc996b07de3f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: function makeHttpObject() { | |
try { | |
return new XMLHttpRequest(); | |
} catch (error) {} | |
try { | |
return new ActiveXObject('Msxml2.XMLHTTP'); | |
} catch (error) {} | |
try { | |
return new ActiveXObject('Microsoft.XMLHTTP'); | |
} catch (error) {} | |
throw new Error('Could not create HTTP request object!'); | |
} | |
var arr = [ | |
{ name: 'Nguyễn Văn Huy', id: 41002308 }, | |
{ name: 'Trần Tấn Phát', id: 57964931 }, | |
{ name: 'Lưu Hải Đăng', id: 46990864 }, | |
]; | |
var getPoint = new Promise(function (resolve, reject) { | |
let count = 0; | |
let result = []; | |
arr.forEach((element, i, array) => { | |
var request = makeHttpObject(); | |
request.open( | |
'GET', | |
`https://app.memrise.com/api/user/get/?user_id=${element.id}&with_leaderboard=true` | |
); | |
request.send(null); | |
request.onreadystatechange = function () { | |
if (request.readyState == 4) { | |
count++; | |
var data = JSON.parse(request.responseText); | |
data = data.user; | |
result.push({ | |
name: element.name, | |
point: data.leaderboard.points_week, | |
}); | |
if (count == array.length) resolve(result); | |
} | |
}; | |
}); | |
}); | |
getPoint.then((result) => { | |
result.sort((a, b) => { | |
return b.point - a.point; | |
}); | |
message = `\n205 MEMRISE RANKING!\n---\n`; | |
result.forEach((element, i) => { | |
message += `#${i + 1} ${element.name}: [${element.point}]\n`; | |
}); | |
alert(message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment