-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (60 loc) · 2.2 KB
/
script.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
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
const socials_url = 'https://socials-cdn.proguy.me/socials.json';
const socials = document.querySelector(".buttons");
const header = document.querySelector(".header");
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
async function getSocials() {
let r = await fetch(socials_url);
let data = await r.json();
return data;
}
function initializeSocials(data) {
let svgData;
let iconElement, svgElement, pathElement;
let buttonElement, contentElement;
data.socials.forEach(element => {
// svg/icon stuff
svgData = element.svg;
svgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
// svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
svgElement.setAttribute('viewBox', element.svg.viewBox);
svgData.path.forEach(svgPath => {
pathElement = document.createElementNS('http://www.w3.org/2000/svg', 'path');
pathElement.setAttribute('d', svgPath);
svgElement.appendChild(pathElement);
});
iconElement = document.createElement('span');
iconElement.classList.add('icon');
iconElement.appendChild(svgElement);
// button stuff
buttonElement = document.createElement('button');
buttonElement.addEventListener('click', () => {
openInNewTab(element.url);
});
contentElement = document.createElement('span');
contentElement.classList.add('content');
contentElement.innerText = element.name;
buttonElement.appendChild(iconElement);
buttonElement.appendChild(contentElement);
socials.appendChild(buttonElement);
});
}
function modifyHeaders(data) {
console.log(1);
const hData = data.header;
let pfp = header.querySelector(".pfp");
let heading = header.querySelector(".heading");
let email = header.querySelector(".details #email");
pfp.src = hData.pfp;
heading.innerText = hData.heading;
email.href = `mailto:${hData.email}`;
email.innerText = hData.email;
document.title = hData.heading;
}
async function initialize() {
let data = await getSocials();
initializeSocials(data);
modifyHeaders(data);
}
initialize();