jsonp attempts
This commit is contained in:
18
jsonp/arch_dl.html
Normal file
18
jsonp/arch_dl.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chess.com API Request</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<label for="username">Enter Chess.com Username:</label>
|
||||
<input type="text" id="username" placeholder="Enter username">
|
||||
|
||||
<button onclick="makeRequest()">Fetch Games</button>
|
||||
|
||||
<script src="./main.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
35
jsonp/main.js
Normal file
35
jsonp/main.js
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
// 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)}`
|
39
jsonp/test.html
Normal file
39
jsonp/test.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>File Download App</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<button id="downloadButton">Download File</button>
|
||||
|
||||
<script>
|
||||
// Function to trigger the download
|
||||
function downloadFile() {
|
||||
// Create a Blob containing the file data
|
||||
var fileData = "Hello, this is the content of the file!"; // this will end up being the concatenated .pgn results returned by the async function
|
||||
var blob = new Blob([fileData], { type: "text/plain" });
|
||||
|
||||
// Create an anchor element and set its attributes
|
||||
var a = document.createElement("a");
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.download = "example.txt";
|
||||
|
||||
// Append the anchor element to the body
|
||||
document.body.appendChild(a);
|
||||
|
||||
// Programmatically click the anchor to trigger the download
|
||||
a.click();
|
||||
|
||||
// Remove the anchor from the body
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
|
||||
// Attach the downloadFile function to the button click event
|
||||
document.getElementById("downloadButton").addEventListener("click", downloadFile);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
13
jsonp/userAgents.js
Normal file
13
jsonp/userAgents.js
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
// userAgents.js
|
||||
|
||||
export 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",
|
||||
// Add more user agents as needed
|
||||
];
|
||||
|
Reference in New Issue
Block a user