Commit 96f53e87 authored by Jae's avatar Jae
Browse files

Webring base

parent 92d4b9ba
const template = document.createElement("template");
template.innerHTML = `
<style>
.webring {
border: 15px solid #fff;
padding: 1rem;
display: grid;
grid-template-columns: 1fr 4fr 1fr;
grid-gap: 1rem;
text-align: center;
font: 100% system-ui, sans-serif;
}
.icon {
font-size: 100px;
}
.webring a {
color: #f5a500;
}
</style>
<div class="webring">
<div class="icon">></div>
<div id="copy">
</div>
<div class="icon"><</div>
</div>`;
const RING_MEMBERS = window.location.href + "webring/members"
class WebRing extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(template.content.cloneNode(true));
const thisSite = this.getAttribute("site");
fetch(RING_MEMBERS)
.then((response) => response.json())
.then((sites) => {
// Find the current site in the data
const matchedSiteIndex = sites.findIndex(
(site) => site.url === thisSite
);
const matchedSite = sites[matchedSiteIndex];
let prevSiteIndex = matchedSiteIndex - 1;
if (prevSiteIndex === -1) prevSiteIndex = sites.length - 1;
let nextSiteIndex = matchedSiteIndex + 1;
if (nextSiteIndex > sites.length) nextSiteIndex = 0;
const randomSiteIndex = this.getRandomInt(0, sites.length - 1);
const cp = `
<h1>Ftech webring</h1>
<p>
This is <a href="${matchedSite.url}">${matchedSite.name}</a>, owned by ${matchedSite.owner}
</p>
<p>
<a href="${sites[prevSiteIndex].url}">[Prev]</a>
<a href="${sites[nextSiteIndex].url}">[Next]</a>
<a href="${sites[randomSiteIndex].url}">[Random]</a>
</p>
`;
this.shadowRoot
.querySelector("#copy")
.insertAdjacentHTML("afterbegin", cp);
});
}
getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}
window.customElements.define("webring-css", WebRing);
\ No newline at end of file
......@@ -106,4 +106,10 @@ th {
text-align: left;
background-color: #212121;
color: #c7eeb5;
}
\ No newline at end of file
}
webring-css {
display: block;
max-width: 600px;
margin: 1rem auto;
}
......@@ -10,6 +10,8 @@
<a href="https://code.jae.fi/jae/go-jae.fi" >This website is Open-Source</a>; <a href="https://bm.jae.fi/web/tor.txt">Tor URLs</a> and <a href="https://bm.jae.fi/web/tor.txt.minisig">Minisign signature</a>.
</small>
</footer>
<script src="/assets/js/main.js"></script>
</body>
</html>
......
......@@ -27,6 +27,9 @@
<a class="info" rel="noreferrer" href="https://matrix.to/&#35;/&#35;home:jae.fi?via=jae.fi">My Matrix room</a>; in order to chat with me.
</li>
</ul>
<webring-css site="https://jae.fi">
Please activate JavaScript to enable the webring widget.
</webring-css>
</div>
{{ template "globals/footer.tmpl" .}}
{{ end }}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment