diff --git a/homepage/index.html b/homepage/index.html index 2563bba..a3fc1db 100644 --- a/homepage/index.html +++ b/homepage/index.html @@ -11,6 +11,7 @@ +
QUOTE
+ + +This site is written in vim and tested in the latest Firefox. No rights reserved, all rights exercised, rights turned to lefts, left in this corner of the web. diff --git a/homepage/js/quotes.js b/homepage/js/quotes.js index 49f3208..3f68ae5 100644 --- a/homepage/js/quotes.js +++ b/homepage/js/quotes.js @@ -1,44 +1,31 @@ -/* quotes.js; Deven Blake 2021; Public Domain */ +/* quotes.js; Deven Blake 2021-2022; Public Domain */ /* With thanks to Ками on Discord. */ -/*********** CURRENTLY DOESN'T WORK ***********/ /* To use: - * - add two P elements with the IDs QUOTE_AUTHOR_ID (see code) and + * - + * - add two elements with the IDs QUOTE_AUTHOR_ID (see code) and * QUOTE_VALUE_ID (see code) respectively - * - call window.quote_initialize() on page load. - * - use window.quote_pick() to get a new quote. */ + * - use window.quote_new() to get a new quote. */ -/* Will set window.quotes to the list of quotes and window.quote to 0 (to - * indicate a quote hasn't yet been generated). */ -window.quote_initialize = function(){ +import quotes from './quotes.json'; +window.quotes = quotes; +window.QUOTES_L_QUOTE_MARK = '"'; +window.QUOTES_R_QUOTE_MARK = '"'; +window.QUOTES_QUOTE_AUTHOR_ID = "quote_author"; +window.QUOTES_QUOTE_AUTHOR_PREFIX = "~ "; +window.QUOTES_QUOTE_VALUE_ID = "quote_value"; - /* What needs to be done here is it needs to fetch the `quotes` object - * from /js/quotes.json and load it into `window.quotes`. The issue is - * I haven't figured out how to load JSON into JS yet without external - * libraries. */ - - window.quote = 0; -}; /* Will not give you the same quote twice in a row! */ -window.quote_pick = function(){ - /* Customizeable constants */ - var L_QUOTE_MARK = '"'; - var R_QUOTE_MARK = '"'; - var QUOTE_AUTHOR_ID = "quote_author"; - var QUOTE_AUTHOR_PREFIX = "~ " - var QUOTE_VALUE_ID = "quote_value"; - /* Could be `const`, but not supported in IE6-10: - * https://caniuse.com/const */ - +window.quote_new = function(){ window.quote_old = window.quote; /* The quote currently in use. */ quoteIndex = Math.floor(Math.random() * window.quotes.length); window.quote = window.quotes.splice(quoteIndex, 1)[0]; if(window.quote_old) window.quotes.push(window.quote_old); - if(quote_text = document.getElementById(QUOTE_VALUE_ID)) - quote_text.textContent = L_QUOTE_MARK + window.quote[0] + R_QUOTE_MARK; + if(quote_text = document.getElementById(window.QUOTES_QUOTE_VALUE_ID)) + quote_text.textContent = window.QUOTES_L_QUOTE_MARK + window.quote[0] + R_QUOTE_MARK; - if(quote_author = document.getElementById(QUOTE_AUTHOR_ID)) - quoteAuthorText.textContent = QUOTE_AUTHOR_PREFIX + window.quote[1]; + if(quote_author = document.getElementById(window.QUOTES_QUOTE_AUTHOR_ID)) + quoteAuthorText.textContent = window.QUOTES_QUOTE_AUTHOR_PREFIX + window.quote[1]; };