37 lines
2.0 KiB
JavaScript
37 lines
2.0 KiB
JavaScript
|
|
// Define userAgents directly in the script
|
|
const userAgents = [
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35",
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35",
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35",
|
|
"Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/113.0",
|
|
"Mozilla/5.0 (Android 12; Mobile; rv:109.0) Gecko/113.0 Firefox/113.0",
|
|
"mozilla/5.0 (macintosh; intel mac os x 10.15; rv:109.0) gecko/20100101 firefox/113.0",
|
|
];
|
|
|
|
function getRandomUserAgent() {
|
|
return userAgents[Math.floor(Math.random() * userAgents.length)];
|
|
}
|
|
|
|
function makeRequest() {
|
|
var username = document.getElementById('username').value;
|
|
var randomUserAgent = getRandomUserAgent();
|
|
|
|
var url = `https://api.chess.com/pub/player/hippodrunkimus/games/2023/03?callback=jsonpCallback&user_agent=${encodeURIComponent(randomUserAgent)}`;
|
|
|
|
var script = document.createElement('script');
|
|
script.src = url;
|
|
|
|
window.jsonpCallback = function(data) {
|
|
archive_list = data;
|
|
console.log(archive_list);
|
|
document.head.removeChild(script);
|
|
};
|
|
|
|
document.head.appendChild(script);
|
|
}
|
|
|
|
// https://api.chess.com/pub/player/hippodrunkimus/games/2023/03 (can't use .pgn)
|
|
//https://api.chess.com/pub/player/${username}/games/archives?callback=jsonpCallback&user_agent=${encodeURIComponent(randomUserAgent)}`
|
|
//Good. Now, the archive_list contains an archives property and each element in the archives array corresponds to a URL. I need make asynchronous requests with those URLs in the same manner as the initial request, namely using random user agents and implementing jsonp again. The response from each of these URL requests will be an object of the form { "games" : [{"pgn": "chess game 1 in pgn notation"}, {"pgn":"chess game 2 in pgn notation"}, ...]
|