/**
*
* This is a client-side implementation of Jae's Ftech webring.
* It depends on DOM elements, attempt to use it in headless
* environments such as NodeJS will result in a failure.
*
*/
// Custom write function since document.write will get removed in Chrome
document.write = (content) => {
document.body.innerHTML = document.body.innerHTML + content;
}
// CSS to make the magic happen
document.write("");
// Code that will be run after we get the data
function _ftww_processData(raw) {
try {
sites = JSON.parse(raw)["members"];
// We find the index corresponding to this website
thisSite = null;
hparts = location.href.split("/");
href = hparts[0] + "/" + hparts[1] + "/" + hparts[2];
if (typeof href === "string") { // Checking if the required variable is defined
index = 0;
for (site of sites) {
if (site["url"] === href) {
thisSite = index;
}
index++;
}
if (thisSite !== null) { // We check if it has found the site in the list
next = null;
previous = null;
random = sites[Math.floor(Math.random() * sites.length)]["url"]; // This simply selects a random item from the $sites array
if (sites[thisSite - 1]) { // We check if there's a previous site in the list
previous = sites[thisSite - 1]["url"];
} else {
previous = sites[sites.length - 1]["url"]; // If this is the first site, roll out to the last one
}
if (sites[thisSite + 1]) { // We check if there's a next site in the list
next = sites[thisSite + 1]["url"];
} else {
next = sites[0]["url"]; // If this is the last site, roll out to the first one
}
dom = "Ftech webringThis is "+sites[thisSite]["name"]+", owned by "+sites[thisSite]["owner"]+". This website is part of the Ftech webring.";
if (previous !== null) dom = dom + "[Prev]\n";
if (previous === null) dom = dom + "[You're on the first site]\n";
if (next !== null) dom = dom + "[Next]\n";
if (next === null) dom = dom + "[You're on the last site]\n";
if (random !== null) dom = dom + "[Random]\n";
dom = dom + ""+sites[thisSite]["owner"]+" is warning you that other websites on the webring have their own policies that may or may not be the same as the policies from "+sites[thisSite]["name"]+".";
document.write(dom);
} else {
// We display an error message
document.write("The content that was supposed to appear here cannot be loaded due to an internal error. Please contact the website administrator.");
console.error(new Error("Unable to detect site"));
}
} else {
// We display an error message
document.write("The content that was supposed to appear here cannot be loaded due to an internal error. Please contact the website administrator.");
console.error(new Error("No hostname"));
}
} catch (e) {
// We display an error message
document.write("The content that was supposed to appear here cannot be loaded due to an internal error. Please contact the website administrator.");
console.error(e);
}
}
// We fetch the API
window.fetch("https://jae.fi/webring/members").then((a) => {
a.text().then((b) => {
_ftww_processData(b);
})
})