Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHyplex9511 committed Jun 14, 2024
1 parent 225c141 commit a4191ca
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,62 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Files for school</title>
<title>GitHub Repo File Fetcher</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#content {
margin-top: 20px;
white-space: pre-wrap;
background-color: #f4f4f4;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
</style>
</head>
<body>

<h1>Fetch File from GitHub Repository</h1>
<form id="fetchForm">
<label for="path">File Path:</label>
<input type="text" id="path" name="path" placeholder="e.g., README.md" required>
<button type="submit">Fetch File</button>
</form>
<div id="content"></div>

<script>
document.getElementById('fetchForm').addEventListener('submit', function(event) {
event.preventDefault();
const path = document.getElementById('path').value;
fetchGitHubFile(path);
});

async function fetchGitHubFile(path) {
const owner = 'MrHyplex9511';
const repo = 'Project_Files';
const accessToken = 'SHA256:cQ3xd45HiMg52eyE+7OgfChauhb7AO/HWUhDq3qJZME=';

const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
const headers = {
'Authorization': `token ${accessToken}`,
'Accept': 'application/vnd.github.v3+json'
};

try {
const response = await fetch(url, { headers });
if (response.ok) {
const data = await response.json();
const content = atob(data.content);
document.getElementById('content').textContent = content;
} else {
document.getElementById('content').textContent = `Error: ${response.status} ${response.statusText}`;
}
} catch (error) {
document.getElementById('content').textContent = `Error: ${error.message}`;
}
}
</script>
</body>
</html>
</html>

0 comments on commit a4191ca

Please sign in to comment.