-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (58 loc) · 2.16 KB
/
script.js
File metadata and controls
71 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
console.log("script.js loaded");
document.addEventListener('DOMContentLoaded', () => {
console.log("parent DOMContentLoaded");
const iframe = document.getElementById('realpage');
if (!iframe) {
console.error('iframe#realpage not found');
return;
}
fetch('projects.json')
.then(res => {
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
})
.then(data => {
//console.log('projects.json loaded', data);
setupIframe(iframe, data);
})
.catch(err => console.error('Failed to load projects.json:', err));
});
function setupIframe(iframe, projectsData) {
iframe.addEventListener('load', () => {
console.log("iframe window loaded");
const doc = iframe.contentDocument || iframe.contentWindow.document;
if (!doc) {
console.error('Cannot access iframe document');
return;
}
const container = doc.getElementById('projects');
if (!container) {
console.error('Cannot find #projects in iframe.');
return;
}
container.innerHTML = '';
Object.entries(projectsData).forEach(([title, [url, desc]]) => {
const card = doc.createElement('div');
card.classList.add('project');
card.classList.add('w3-animate-opacity');
card.innerHTML = `
<h4>${title}</h4>
<p>${desc}</p>
<a href="${url}" target="_blank">View on GitHub</a>
`;
container.appendChild(card);
});
/*const nproject = doc.createElement('div');
nproject.classList.add('project');
nproject.classList.add('new-project');
nproject.classList.add('w3-animate-opacity');
nproject.innerHTML = `
<a href="https://github.com/coyoteclan/devCoD/blob/main/projects.json" target="_blank">+</a>
`;
container.appendChild(nproject);*/
});
// if iframe is already loaded, trigger injection immediately
if (iframe.contentDocument?.readyState === 'complete') {
iframe.dispatchEvent(new Event('load'));
}
}