js cleanup
This commit is contained in:
parent
fb2c35fd64
commit
520075085e
@ -1,29 +1,13 @@
|
|||||||
/*
|
/* quotes.js; Deven Blake 2021; Public Domain */
|
||||||
quotes.js
|
/* With thanks to Ками on Discord. */
|
||||||
PUBLIC DOMAIN. CODED BY DEVEN BLAKE WITH HELP FROM КАМИ 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
|
/* Will set window.quotes to the list of quotes and window.quote to 0 (to
|
||||||
* add two P elements with the IDs "quote" and "quoteauthor" respectively
|
* indicate a quote hasn't yet been generated). */
|
||||||
* call window.initializequotes() on page load.
|
window.initializequotes = function(){
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
window.initializequotes = function() {
|
|
||||||
window.quotes = [
|
window.quotes = [
|
||||||
[ "Yeah, that's just how it is. Just, nothing. So much nothing that it hurts.",
|
[ "Yeah, that's just how it is. Just, nothing. So much nothing that it hurts.",
|
||||||
"danger/u/ aefd79" ],
|
"danger/u/ aefd79" ],
|
||||||
@ -109,41 +93,21 @@ window.initializequotes = function() {
|
|||||||
window.quote = 0;
|
window.quote = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Will not give you the same quote twice in a row! */
|
||||||
You can pop this in window.onload() to generate the quote on page load
|
window.genQuote = function(){
|
||||||
OR make a button with onclick="window.genQuote();" to let the user get
|
var QUOTE_AUTHOR_ID = "quote_author";
|
||||||
moar quotes.
|
var QUOTE_AUTHOR_PREFIX = "~ "
|
||||||
|
var QUOTE_VALUE_ID = "quote_value";
|
||||||
|
|
||||||
Will not give you the same quote twice in a row!
|
window.quote_old = window.quote; /* The quote currently in use. */
|
||||||
*/
|
|
||||||
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!";
|
|
||||||
|
|
||||||
// The quote currently in use.
|
|
||||||
window.oldQuote = window.quote;
|
|
||||||
|
|
||||||
// Get the index of the next quote we'll use in window.quotes
|
|
||||||
quoteIndex = Math.floor(Math.random() * window.quotes.length);
|
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];
|
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(quote_text = document.getElementById(QUOTE_VALUE_ID))
|
||||||
if(window.oldQuote) window.quotes.push(window.oldQuote);
|
quote_text.textContent = '"' + window.quote[0] + '"';
|
||||||
|
|
||||||
// This is where we show the quote.
|
if(quote_author = document.getElementById(QUOTE_AUTHOR_ID))
|
||||||
quoteText = document.getElementById('quote');
|
quoteAuthorText.textContent = QUOTE_AUTHOR_PREFIX + window.quote[1];
|
||||||
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);
|
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Depends on cookies.js (NON-FREE) */
|
/* Depends on cookies.js */
|
||||||
/* sheets.js; Deven Blake 2021; Public Domain */
|
/* sheets.js; Deven Blake 2021; Public Domain */
|
||||||
|
|
||||||
/* sets the sheet to the sheet in the cookie, if the user saved their
|
/* sets the sheet to the sheet in the cookie, if the user saved their
|
||||||
|
Loading…
Reference in New Issue
Block a user