Skip to content

Commit 1101986

Browse files
committed
update script assets
1 parent 4211ee5 commit 1101986

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

assets/js/script.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// --- Check if this is a static page first ---
2+
if (window.staticPageMode === true) {
3+
console.log("Static page mode detected - API calls will be intercepted");
4+
}
5+
16
// --- Constants ---
27
const GITHUB_PAT = ""; // IMPORTANT: Replace with your Personal Access Token ONLY in your PRIVATE fork. Keep this fork private. NEVER commit a PAT to a public repo.
38

assets/js/static-repo.js

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
// This script is loaded on statically-generated repository pages
2-
// It prevents the automatic API fetch that would normally happen
2+
// It completely prevents API calls to GitHub for static pages
33

4-
document.addEventListener('DOMContentLoaded', function() {
5-
// Override the fetchRepoTree function to prevent API calls on static pages
4+
// Execute immediately to block API calls before any other scripts run
5+
(function() {
6+
// Create a flag to mark this as a static page
67
window.preventRepoFetch = true;
78

8-
// Add a meta indicator that this is a pre-generated page (for debugging)
9-
const meta = document.createElement('meta');
10-
meta.name = 'static-page';
11-
meta.content = 'true';
12-
document.head.appendChild(meta);
13-
});
9+
// Override the fetch function to intercept GitHub API calls
10+
const originalFetch = window.fetch;
11+
12+
window.fetch = function(url, options) {
13+
// If URL is a string and contains api.github.com, block the request
14+
if (typeof url === 'string' && url.includes('api.github.com')) {
15+
console.log("Static page: Blocking GitHub API request to:", url);
16+
17+
// Return a mock successful response to prevent errors
18+
return Promise.resolve({
19+
ok: true,
20+
status: 200,
21+
json: () => Promise.resolve({ mock: true, message: "Static page - API call intercepted" })
22+
});
23+
}
24+
25+
// Pass through all other fetch requests
26+
return originalFetch.apply(this, arguments);
27+
};
28+
29+
// Signal that this script has loaded by creating a meta tag
30+
document.addEventListener('DOMContentLoaded', function() {
31+
const meta = document.createElement('meta');
32+
meta.name = 'static-page';
33+
meta.content = 'true';
34+
document.head.appendChild(meta);
35+
36+
// Also ensure the tree is hidden since we won't be fetching
37+
setTimeout(function() {
38+
// Hide loading indicators
39+
const loadingElement = document.getElementById('loading');
40+
if (loadingElement) loadingElement.style.display = 'none';
41+
42+
// Hide error container
43+
const errorElement = document.getElementById('error');
44+
if (errorElement) errorElement.style.display = 'none';
45+
}, 100);
46+
});
47+
})();

0 commit comments

Comments
 (0)