Website/global/global.js

288 lines
11 KiB
JavaScript
Raw Normal View History

2024-09-15 11:24:26 +02:00
/**
*
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
*
* Copyright (C) 2024 Gabriel Weingardt
*
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend The above is the entire license notice
* for the JavaScript code in this page.
*
*/
2024-09-21 20:41:23 +02:00
/*
* I am very sorry to the person, who actually takes a look at this javascript
2024-09-22 00:23:56 +02:00
* Clean code sometimes isn't my greatest strength ;)
2024-09-21 20:41:23 +02:00
*/
/* Global navigation buttons */
/* (L)ink, (P)ath or (SEP)erator, Display Name, Target Link */
2024-09-15 11:24:26 +02:00
navContent = [
2024-09-21 20:41:23 +02:00
["P", "Home", ""],
["P", "Contact", "contact/"],
["P", "Projects", "projects/"],
["P", "Posts", "posts/"],
["SEP"],
2024-09-21 20:41:23 +02:00
["L", "Git", "https://git.weingardt.dev/explore/repos"],
["SEP"],
2024-09-21 20:41:23 +02:00
["P", "Website Info", "info/"]
2024-09-15 11:24:26 +02:00
];
2024-09-21 20:41:23 +02:00
/* Global buttons located in the footer of the page */
/* Alt Text, Target Link, Image Source */
2024-09-15 11:24:26 +02:00
funButtons = [
2024-09-23 20:36:29 +02:00
["CC BY-SA 4.0", "https://creativecommons.org/licenses/by-sa/4.0/", "global/buttons/cc-by-sa.png"],
["Right to repair", "", "global/buttons/right2repair.gif"],
["Made with VSCodium", "https://vscodium.com/", "global/buttons/vscodium.png"],
["Made on Gnu/Linux", "https://www.gnu.org/home.en.html", "global/buttons/gnu-linux.gif"],
["Windows 10, NO", "", "global/buttons/win10no.gif"],
// ["No NFT's", "", "global/buttons/nftbutton.gif"],
["Anything but Chrome", "https://librewolf.net/", "global/buttons/nochrome.png"],
["UBlock Origin Now!", "https://ublockorigin.com/", "global/buttons/ublock.png"],
["Get a Website - Landchad", "https://landchad.net/", "global/buttons/landchad.gif"],
["Internet Privacy Now!", "https://anonymousplanet.org/", "global/buttons/internetprivacy.gif"],
["Encrypt Your Shit", "https://gitlab.com/cryptsetup/cryptsetup", "global/buttons/encryptyourshit.gif"],
["No Web 3!", "", "global/buttons/noweb3.gif"],
2024-09-15 11:24:26 +02:00
];
2024-09-22 00:23:56 +02:00
/* Available Themes located in the footer */
2024-09-15 11:24:26 +02:00
var styles = ["Tomorrow", "Forgotten", "Yotsuba"];
dirDepth = ""
2024-09-23 20:36:29 +02:00
2024-09-21 20:41:23 +02:00
/* Update CSS Colorscheme function for themes */
2024-09-15 11:24:26 +02:00
function updateStyle(type){
var doc = document.documentElement;
2024-09-21 20:41:23 +02:00
/* If type = undefined, default to "tomorrow" */
2024-09-15 11:24:26 +02:00
if (type == undefined){ type = "Tomorrow"; }
if (type == "Yotsuba"){
doc.style.setProperty("--main-bg-color", "#fed6af");
doc.style.setProperty("--main-bg-end-color", "#ffffee");
doc.style.setProperty("--main-color", "#ffffff");
doc.style.setProperty("--main-fg-color", "#800000");
doc.style.setProperty("--main-title-fg-color", "#800000");
doc.style.setProperty("--font-family", "Arial, Helvetica, sans-serif");
doc.style.setProperty("--font-size", "13px");
document.querySelector("body").style.backgroundImage = "url(" + dirDepth + "global/fade.png)";
2024-09-15 11:24:26 +02:00
} else if (type == "Tomorrow"){
doc.style.setProperty("--main-bg-color", "#1d1f21");
doc.style.setProperty("--main-bg-end-color", "#1d1f21");
doc.style.setProperty("--main-color", "#282a2e");
doc.style.setProperty("--main-fg-color", "#ffffff");
doc.style.setProperty("--main-title-fg-color", "#ffffff");
doc.style.setProperty("--font-family", "Arial, Helvetica, sans-serif");
doc.style.setProperty("--font-size", "13px");
document.querySelector("body").style.backgroundImage = "none";
} else if (type == "Forgotten"){
doc.style.setProperty("--main-bg-color", "#282828");
doc.style.setProperty("--main-bg-end-color", "#458588");
doc.style.setProperty("--main-color", "#a89984");
doc.style.setProperty("--main-fg-color", "#282828");
doc.style.setProperty("--main-title-fg-color", "#7c7c7c");
doc.style.setProperty("--font-family", "FreePixel");
doc.style.setProperty("--font-size", "13px");
2024-09-15 11:24:26 +02:00
document.querySelector("body").style.backgroundImage = "none";
} else if (type == "Neocities"){
doc.style.setProperty("--main-bg-color", "#282828");
doc.style.setProperty("--main-bg-end-color", "#458588");
doc.style.setProperty("--main-color", "#a89984");
doc.style.setProperty("--main-fg-color", "#282828");
doc.style.setProperty("--main-title-fg-color", "#7c7c7c");
doc.style.setProperty("--font-family", "FreePixel");
doc.style.setProperty("--font-size", "15px");
2024-09-15 11:24:26 +02:00
document.querySelector("body").style.backgroundImage = "none";
}
}
2024-09-23 20:36:29 +02:00
function LoadWebsite(){
2024-09-15 11:24:26 +02:00
dirDepth = document.getElementById("toplevel").getAttribute("data-");
2024-09-23 20:36:29 +02:00
document.getElementById("toplevel").textContent = "";
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
const WEBSIDENAME = document.URL;
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var footing = document.getElementById("footnote");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
/* Footer Section */
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
/* Image Buttons */
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var title = document.createElement("h2");
title.setAttribute("class", "titlebar");
title.textContent = "Page Info";
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
footing.appendChild(title);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
if (document.getElementById("please-no-buttons") == null){
var button_container = document.createElement("div");
button_container.setAttribute("class", "button-container");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
for (let i = 0; i < funButtons.length; i++) {
link = document.createElement("a");
if (funButtons[Number(i)][1] != ""){
link.setAttribute("href", funButtons[Number(i)][1]);
}
link.setAttribute("target", "_blank");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
img = document.createElement("img");
img.setAttribute("src", dirDepth + funButtons[Number(i)][2]);
img.setAttribute("alt", funButtons[Number(i)][0]);
img.setAttribute("class", "license-img");
link.appendChild(img);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
button_container.appendChild(link);
}
footing.appendChild(button_container);
2024-09-15 11:24:26 +02:00
}
2024-09-23 20:36:29 +02:00
/* Global "Page last updated" text, reading the modified date of the page */
2024-09-21 20:41:23 +02:00
2024-09-23 20:36:29 +02:00
/* Have to flip Months w. Days for European style Date MM.DD.YYYY to DD.MM.YYYY */
var docDate = ((("" + document.lastModified).replaceAll(",", " at ")).replaceAll("/", ".")).split(".");
docSave = docDate[0];
docDate[0] = docDate[1];
docDate[1] = docSave;
docDate = "Page last updated: " + ((docDate.toString().replaceAll(",", ".")).replaceAll(" ", " at "));
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var last_updated = document.createElement("p");
last_updated.setAttribute("class", "text-center");
last_updated.textContent = docDate;
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
footing.appendChild(last_updated);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
// Footer
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
const LICENCE_LINK = "https://creativecommons.org/licenses/by-sa/4.0/";
const LICENCE_NAME = "CC BY-SA 4.0";
2024-09-21 20:41:23 +02:00
2024-09-23 20:36:29 +02:00
var footer = document.getElementById("footer");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var span = document.createElement("p");
span.setAttribute("class", "nobr");
span.setAttribute("class", "text-center");
span.textContent = "Website licensed under\u00A0";
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var span_license = document.createElement("a");
span_license.setAttribute("href", LICENCE_LINK);
span_license.setAttribute("class", "nobr");
span.setAttribute("class", "text-center");
span_license.textContent = LICENCE_NAME;
span.appendChild(span_license);
2024-09-21 20:41:23 +02:00
2024-09-23 20:36:29 +02:00
footing.appendChild(span);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
// Webside name
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var webside_name = document.createElement("a");
webside_name.setAttribute("class", "text-center");
webside_name.setAttribute("href", WEBSIDENAME);
webside_name.textContent = WEBSIDENAME;
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
footing.appendChild(webside_name);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var button_span = document.createElement("span");
button_span.setAttribute("class", "prefSpan")
button_span.textContent = "Style: "
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var button_select = document.createElement("select");
button_select.id = "styleselector";
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
for (let i = 0; i < styles.length; i++) {
var button_item = document.createElement("option");
button_item.textContent = styles[Number(i)];
button_item.value = styles[Number(i)];
if (styles[Number(i)] === localStorage.getItem("style")) { button_item.selected = "selected"; }
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
button_select.appendChild(button_item);
}
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
button_span.appendChild(button_select);
footing.appendChild(button_span);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
if(dirDepth === ""){
document.getElementById("agestamp").textContent = new Date(new Date().getTime() - new Date("March, 30, 2006").getTime()).getFullYear() - 1970;
}
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
/* Navbar Section */
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
if (document.getElementById("navbar") != null){
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var selectedNav = document.getElementById("selected-nav").getAttribute("data-");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
var nav = document.getElementById("navbar");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
for (let i = 0; i < navContent.length; i++) {
if (navContent[Number(i)][0] === "SEP"){
tmpAdd = document.createElement("hr");
tmpAdd.classList.add("navSep");
document.getElementById("navbar").appendChild(tmpAdd);
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
} else {
href = navContent[Number(i)][2];
sel = navContent[Number(i)][1].toLowerCase().includes(selectedNav.toLowerCase());
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
if (navContent[Number(i)][0] === "P"){
href = dirDepth + href;
}
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
tmpAdd = document.createElement("a");
tmpAdd.textContent = navContent[Number(i)][1];
tmpAdd.setAttribute("href", href);
tmpAdd.classList.add("nav");
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
if (sel) {
tmpAdd.classList.add("selected-nav");
}
2024-09-15 11:24:26 +02:00
2024-09-23 20:36:29 +02:00
document.getElementById("navbar").appendChild(tmpAdd);
}
}
}
var stylebutton = document.getElementById("styleselector");
stylebutton.addEventListener("change", (event) => {
localStorage.setItem("style", event.target.value);
updateStyle(event.target.value);
});
if (localStorage.getItem("style") == "Yotsuba"){
updateStyle(localStorage.getItem("style"));
}
2024-09-15 11:24:26 +02:00
}
2024-09-23 20:36:29 +02:00
document.addEventListener("DOMContentLoaded", LoadWebsite);
2024-09-15 11:24:26 +02:00
2024-09-22 23:23:07 +02:00
updateStyle(localStorage.getItem("style"));
2024-09-23 20:36:29 +02:00