1
0
This commit is contained in:
dtb 2021-10-14 23:45:12 -04:00
parent d795a325c0
commit 5fd82dff48

View File

@ -2,25 +2,33 @@
/* With thanks to Ками on Discord. */
/*********** CURRENTLY DOESN'T WORK ***********/
/* To use:
* - add two P elements with the IDs "quote" and "quoteauthor" respectively
* - call window.initializequotes() on page load.
* - use window.genQuote() to get a new quote. */
* - add two P 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. */
/* Will set window.quotes to the list of quotes and window.quote to 0 (to
* indicate a quote hasn't yet been generated). */
window.initializequotes = function(){
window.quote_initialize = function(){
/* 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.genQuote = function(){
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_old = window.quote; /* The quote currently in use. */
quoteIndex = Math.floor(Math.random() * window.quotes.length);
@ -29,7 +37,7 @@ window.genQuote = function(){
window.quotes.push(window.quote_old);
if(quote_text = document.getElementById(QUOTE_VALUE_ID))
quote_text.textContent = '"' + window.quote[0] + '"';
quote_text.textContent = 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];