From 14cd12c2ef81d5eb2c67ad55b3c847a9eaf38822 Mon Sep 17 00:00:00 2001 From: Minteck ⭐ Date: Fri, 15 Oct 2021 18:28:58 +0000 Subject: Add 'FtechWebring.client.js' --- FtechWebring.client.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 FtechWebring.client.js (limited to 'FtechWebring.client.js') diff --git a/FtechWebring.client.js b/FtechWebring.client.js new file mode 100644 index 0000000..162227e --- /dev/null +++ b/FtechWebring.client.js @@ -0,0 +1,79 @@ +/** + * + * 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; + if (typeof location.hostname === "string") { // Checking if the required variable is defined + index = 0; + for (site of sites) { + if (site["name"] === location.hostname) { + 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 + } + + document.write("Ftech webringThis is"+sites[thisSite]["name"]+", owned by "+sites[thisSite]["owner"]+". This website is part of the Ftech webring."); + + if (previous !== null) document.write("[Prev]\n"); + if (previous === null) document.write("[You're on the first site]\n"); + if (next !== null) document.write("[Next]\n"); + if (next === null) document.write("[You're on the last site]\n"); + if (random !== null) document.write("[Random]\n"); + + document.write(""+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"]+"."); + } 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."); + } + } 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."); + } +} 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."); +} +} + +// We fetch the API +window.fetch("https://jae.fi/webring/members").then((a) => { + a.text().then((b) => { + _ftww_processData(b); + }) +}) \ No newline at end of file -- cgit