-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinks.html
More file actions
143 lines (140 loc) · 4.52 KB
/
links.html
File metadata and controls
143 lines (140 loc) · 4.52 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="Cache-Control" content="max-age=86400, must-revalidate" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Links</title>
<style>
body {
font-family: "Arial", sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f4f4f4;
}
#links {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
width: 95%;
max-width: 1920px;
}
.link-container {
flex: 0 0 12%; /* Adjusts the number of columns for 8 per row */
margin: 10px;
border-radius: 8px;
overflow: hidden;
position: relative;
height: 200px; /* Adjusted height for smaller width */
cursor: pointer;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.link-container:hover {
transform: scale(1.05);
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
}
.link-title,
.link-url {
position: absolute;
width: 100%;
padding: 5px;
text-align: center;
z-index: 10;
}
.link-title {
top: 0;
background: rgba(0, 0, 0, 0.7); /* Semi-transparent background */
color: #fff;
font-size: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.favicon {
width: 20px;
height: 20px;
margin-right: 5px;
}
.link-url {
bottom: 0;
background: rgba(
0,
100,
0,
0.7
); /* Green semi-transparent background */
color: #eef;
font-size: 12px;
}
.link-preview {
width: 100%;
height: 100%;
background-size: cover;
background-position: center;
}
</style>
</head>
<body>
<div id="links"></div>
<script>
function loadLinks() {
fetch("links.json")
.then((response) => response.json())
.then((data) => {
const container = document.getElementById("links");
data.links.forEach((link) => {
const linkDiv = document.createElement("div");
linkDiv.className = "link-container";
fetch(
`https://api.allorigins.win/get?url=${encodeURIComponent(
link.url
)}`
)
.then((response) => response.json())
.then((data) => {
const parser = new DOMParser();
const doc = parser.parseFromString(
data.contents,
"text/html"
);
const title = doc.querySelector("title").innerText;
const ogImage = doc.querySelector(
'meta[property="og:image"]'
);
const faviconLink = doc.querySelector(
'link[rel="icon"], link[rel="shortcut icon"]'
);
const favicon = faviconLink
? faviconLink.href
: "/favicon.ico";
const thumbnail = ogImage
? ogImage.content
: "placeholder.jpg"; // Use a placeholder if no og:image
linkDiv.innerHTML = `
<div class="link-title"><img src="${favicon}" class="favicon" onerror="this.style.display='none'">${title}</div>
<div class="link-preview" style="background-image: url('${thumbnail}');"></div>
<div class="link-url">${link.url}</div>
`;
container.appendChild(linkDiv);
})
.catch((error) => {
console.error("Error loading the link:", error);
linkDiv.innerHTML = `
<div class="link-title">Unavailable</div>
<div class="link-preview" style="background-image: url('placeholder.jpg');"></div>
<div class="link-url">No URL</div>
`;
container.appendChild(linkDiv);
});
});
})
.catch((error) => console.error("Error loading the JSON:", error));
}
window.onload = loadLinks;
</script>
</body>
</html>