Skip to content

Commit 70021e2

Browse files
author
Vic-Nas
committed
Add localStorage token support and caching
1 parent 4282050 commit 70021e2

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

script.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ function getRepoPath() {
1515
return parts[1] && parts[2] ? `${parts[1]}/${parts[2]}` : 'Vic-Nas/PythonSolutions';
1616
}
1717

18+
// Users can set their own token in browser console:
19+
// localStorage.setItem('github_token', 'ghp_your_token_here')
20+
const GITHUB_TOKEN = localStorage.getItem('github_token') || '';
21+
1822
// Fetch folder contents
1923
async function fetchFolderContents(path) {
2024
if (state.folderCache[path]) {
2125
return state.folderCache[path];
2226
}
2327

2428
try {
25-
const res = await fetch(`https://api.github.com/repos/${getRepoPath()}/contents/${path}`);
29+
const headers = {};
30+
if (GITHUB_TOKEN) {
31+
headers['Authorization'] = `token ${GITHUB_TOKEN}`;
32+
}
33+
34+
const res = await fetch(`https://api.github.com/repos/${getRepoPath()}/contents/${path}`, { headers });
2635
if (!res.ok) return null;
2736

2837
const items = await res.json();

0 commit comments

Comments
 (0)