const JSON_WEBRING = "https://git.gablaxy.xyz/api/v1/repos/gablaxy/webring/raw/webring.json?ref=main"; const template = document.createElement("template"); template.innerHTML = `
`; class Webring extends HTMLElement { connectedCallback() { this.attachShadow({ mode: "open" }); this.shadowRoot.appendChild(template.content.cloneNode(true)); const currentSite = this.getAttribute("site"); fetch(JSON_WEBRING) .then((response) => response.json()) .then((sites) => { const normalize = (url) => url.replace(/\/$/, ""); const matchedSiteIndex = sites.findIndex( (site) => normalize(site.url) === normalize(currentSite) ); if (matchedSiteIndex === -1) { this.shadowRoot.querySelector("#webring-inner").insertAdjacentHTML("afterbegin", `

grossomodoX

T'es pas dans le gang bozo

`); return; } let previousSiteIndex = matchedSiteIndex - 1; if (previousSiteIndex < 0) previousSiteIndex = sites.length - 1; let nextSiteIndex = matchedSiteIndex + 1; if (nextSiteIndex >= sites.length) nextSiteIndex = 0; const content = `

grossomodoX

< avant / ${sites[matchedSiteIndex].name} / après > `; this.shadowRoot .querySelector("#webring-inner") .insertAdjacentHTML("afterbegin", content); }) .catch((error) => { console.error(error); const content = `

grossomodoX

T'es pas dans le gang bozo

`; this.shadowRoot .querySelector("#webring-inner") .insertAdjacentHTML("afterbegin", content); }); } } window.customElements.define("webring-iutechno", Webring);