-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
43 lines (33 loc) · 1.1 KB
/
code.js
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
function getLink() {
return new Promise((resolve) => {
//API
setTimeout(() => {
const link = 'https://gamejolt.com/';
resolve(link);
}, 1200);
});
}
getLink()
.then((link) => {
console.group('import ' + link);
})
.catch((error) => {
console.error('OS: ' + error);
});
const currentDirectory = './'; // текущая директория
const extension = '.css'; // расширение файлов
fetch(currentDirectory)
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(data, 'text/html');
const links = htmlDoc.querySelectorAll('link[rel="stylesheet"][href=extension]');
links.forEach(link => {
const head = document.head || document.getElementsByTagName('head')[0];
const newLink = document.createElement('link');
newLink.rel = 'stylesheet';
newLink.href = currentDirectory + link.href;
console.log(newLink);
head.appendChild(newLink);
});
})