Last active
March 13, 2021 07:56
-
-
Save NoCtrlZ1110/c9edbf969e7ed10ca1562c0f014b3c7d to your computer and use it in GitHub Desktop.
PHÒ'S MEMRISE RANKING!
This file contains 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: "Phan Văn Minh", id: 44634577 }, { name: "Nguyễn Thị Xuân", id: 40435014 }, { name: "Đặng Văn Manh", id: 44354858 }, { name: "Ngô Văn Hào", id: 40266280 }, { name: "Lê Thị Tâm", id: 40269547 },];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 = `\nPHÒ'S 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