Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 84cc812

Browse files
committed
JS3test
1 parent a8b2cfe commit 84cc812

File tree

5 files changed

+73
-33
lines changed

5 files changed

+73
-33
lines changed

Week1/hw/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7+
<meta name="theme-color" content="#000000">
8+
<meta name="apple-mobile-web-app-capable" content="yes">
9+
<meta name="mobile-web-app-capable" content="yes">
10+
<meta name="format-detection" content="telephone=no">
11+
<link rel="apple-touch-icon" href="./hyf.png">
12+
<link rel="shortcut icon" type="image/png" href="./hyf.png" />
13+
<title>HYF-GITHUB</title>
14+
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
15+
<link rel="stylesheet" href="./style.css">
16+
</head>
17+
18+
<body>
19+
<div id="root"></div>
20+
<script src="./index.js"></script>
21+
</body>
22+
23+
</html>

Week1/hw/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
{
4+
function fetchJSON(url, cb) {
5+
const xhr = new XMLHttpRequest();
6+
xhr.open('GET', url);
7+
xhr.responseType = 'json';
8+
xhr.onload = () => {
9+
if (xhr.status < 400) {
10+
cb(null, xhr.response);
11+
} else {
12+
cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`));
13+
}
14+
};
15+
xhr.onerror = () => cb(new Error('Network request failed'));
16+
xhr.send();
17+
}
18+
19+
function createAndAppend(name, parent, options = {}) {
20+
const elem = document.createElement(name);
21+
parent.appendChild(elem);
22+
Object.keys(options).forEach((key) => {
23+
const value = options[key];
24+
if (key === 'text') {
25+
elem.innerText = value;
26+
} else {
27+
elem.setAttribute(key, value);
28+
}
29+
});
30+
return elem;
31+
}
32+
33+
function main(url) {
34+
fetchJSON(url, (err, data) => {
35+
const root = document.getElementById('root');
36+
if (err) {
37+
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
38+
} else {
39+
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
40+
}
41+
});
42+
}
43+
44+
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
45+
46+
window.onload = () => main(HYF_REPOS_URL);
47+
}

Week1/hw/script.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

Week1/hw/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.alert-error {
2+
color: red;
3+
}

Week1/hw/test.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)