const DATA_FOR_WEBRING = `https://miau.sadgrl.online/yesterweb-ring/webring.json`;
const yesterwebTemplate = document.createElement("template");
yesterwebTemplate.innerHTML = `
`;
class WebRing extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(yesterwebTemplate.content.cloneNode(true));
// e.g. https://css-tricks.com
const thisSite = this.getAttribute("site");
fetch(DATA_FOR_WEBRING)
.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 - 1) nextSiteIndex = 0;
//console.log("sites[0].url is " + sites[0].url);
//console.log("matchedSite.url is " + matchedSite.url);
//console.log("matchedSite.name is " + matchedSite.name);
//console.log(sites[0].url);
const randomSiteIndex = this.getRandomInt(0, sites.length - 1);
const cp = `
??? //
<<
Yesterweb
>> //
...
`;
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);
// Get HTML head element
var head = document.getElementsByTagName('HEAD')[0];
// Create new link Element
var link = document.createElement('link');
// set the attributes for link element
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '/CSS/yesterweb.css';
// Append link element to HTML head
head.appendChild(link);