js cleanup
This commit is contained in:
		
							parent
							
								
									fb2c35fd64
								
							
						
					
					
						commit
						520075085e
					
				@ -1,28 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
	quotes.js
 | 
			
		||||
	PUBLIC DOMAIN. CODED BY DEVEN BLAKE WITH HELP FROM КАМИ ON DISCORD.
 | 
			
		||||
/* quotes.js; Deven Blake 2021; Public Domain */
 | 
			
		||||
/* With thanks to Ками on Discord. */
 | 
			
		||||
/* 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. */
 | 
			
		||||
 | 
			
		||||
	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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
// comments exhaustive because i hate working in JS
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
	Will set window.quotes to the list of quotes and window.quote to 0 (to
 | 
			
		||||
	indicate a quote hasn't yet been generated).
 | 
			
		||||
 | 
			
		||||
	window.quotes is a list of quotes and each quote is itself a list with
 | 
			
		||||
	[ quote, author ]. Kinda sucks that it has to load like (what could be)
 | 
			
		||||
	a huge list every time the page loads but I (like most webdevs) am lazy
 | 
			
		||||
	and It Works How It Is.
 | 
			
		||||
 | 
			
		||||
	maybe these could be loaded in from a JSON somewhere? i don't wanna do
 | 
			
		||||
	it if it'll drag page loading time down. already need to defer quote
 | 
			
		||||
	generation because the JS is so slow
 | 
			
		||||
*/
 | 
			
		||||
/* 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.quotes = [
 | 
			
		||||
		[ "Yeah, that's just how it is. Just, nothing. So much nothing that it hurts.",
 | 
			
		||||
@ -109,41 +93,21 @@ window.initializequotes = function() {
 | 
			
		||||
	window.quote = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
	You can pop this in window.onload() to generate the quote on page load
 | 
			
		||||
	OR make a button with onclick="window.genQuote();" to let the user get
 | 
			
		||||
	moar quotes.
 | 
			
		||||
 | 
			
		||||
	Will not give you the same quote twice in a row!
 | 
			
		||||
*/
 | 
			
		||||
/* Will not give you the same quote twice in a row! */
 | 
			
		||||
window.genQuote = function(){
 | 
			
		||||
	// This text is to what the text of the button with ID="quoteButton"
 | 
			
		||||
	// changes when a quote is generated. Used to have it be
 | 
			
		||||
	// "Get a free quote today!" / "Get another free quote today!".
 | 
			
		||||
	ButtonActivated = "Get another free quote today!";
 | 
			
		||||
	var QUOTE_AUTHOR_ID = "quote_author";
 | 
			
		||||
	var QUOTE_AUTHOR_PREFIX = "~ "
 | 
			
		||||
	var QUOTE_VALUE_ID = "quote_value";
 | 
			
		||||
 | 
			
		||||
	// The quote currently in use.
 | 
			
		||||
	window.oldQuote = window.quote;
 | 
			
		||||
 | 
			
		||||
	// Get the index of the next quote we'll use in window.quotes
 | 
			
		||||
	window.quote_old = window.quote; /* The quote currently in use. */
 | 
			
		||||
	quoteIndex = Math.floor(Math.random() * window.quotes.length);
 | 
			
		||||
 | 
			
		||||
	// Change the current quote to a new quote that we take out of the
 | 
			
		||||
	// quotes array.
 | 
			
		||||
	window.quote = window.quotes.splice(quoteIndex, 1)[0];
 | 
			
		||||
	if(window.quote_old)
 | 
			
		||||
		window.quotes.push(window.quote_old);
 | 
			
		||||
 | 
			
		||||
	// If there was a quote in use, let's put it back in the quotes array.
 | 
			
		||||
	if(window.oldQuote) window.quotes.push(window.oldQuote);
 | 
			
		||||
	if(quote_text = document.getElementById(QUOTE_VALUE_ID))
 | 
			
		||||
		quote_text.textContent = '"' + window.quote[0] + '"';
 | 
			
		||||
 | 
			
		||||
	// This is where we show the quote.
 | 
			
		||||
	quoteText = document.getElementById('quote');
 | 
			
		||||
	if(quoteText) quoteText.textContent = '\"' + window.quote[0] + '\"';
 | 
			
		||||
 | 
			
		||||
	// This is where we show the quote author.
 | 
			
		||||
	quoteAuthorText = document.getElementById('quoteauthor');
 | 
			
		||||
	if(quoteAuthorText) quoteAuthorText.textContent = '~ ' + window.quote[1];
 | 
			
		||||
 | 
			
		||||
	// Change the button text to the ButtonActivated text.
 | 
			
		||||
	button =  document.getElementById('quoteButton');
 | 
			
		||||
	if(button) button.setAttribute('value', ButtonActivated);
 | 
			
		||||
	if(quote_author = document.getElementById(QUOTE_AUTHOR_ID))
 | 
			
		||||
		quoteAuthorText.textContent = QUOTE_AUTHOR_PREFIX + window.quote[1];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
/* Depends on cookies.js (NON-FREE) */
 | 
			
		||||
/* Depends on cookies.js */
 | 
			
		||||
/* sheets.js; Deven Blake 2021; Public Domain */
 | 
			
		||||
 | 
			
		||||
/* sets the sheet to the sheet in the cookie, if the user saved their
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user