better
This commit is contained in:
parent
d795a325c0
commit
5fd82dff48
@ -2,25 +2,33 @@
|
|||||||
/* With thanks to Ками on Discord. */
|
/* With thanks to Ками on Discord. */
|
||||||
/*********** CURRENTLY DOESN'T WORK ***********/
|
/*********** CURRENTLY DOESN'T WORK ***********/
|
||||||
/* To use:
|
/* To use:
|
||||||
* - add two P elements with the IDs "quote" and "quoteauthor" respectively
|
* - add two P elements with the IDs QUOTE_AUTHOR_ID (see code) and
|
||||||
* - call window.initializequotes() on page load.
|
* QUOTE_VALUE_ID (see code) respectively
|
||||||
* - use window.genQuote() to get a new quote. */
|
* - 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
|
/* Will set window.quotes to the list of quotes and window.quote to 0 (to
|
||||||
* indicate a quote hasn't yet been generated). */
|
* 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
|
/* 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
|
* 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
|
* I haven't figured out how to load JSON into JS yet without external
|
||||||
* libraries. */
|
* libraries. */
|
||||||
|
|
||||||
window.quote = 0;
|
window.quote = 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
/* 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(){
|
window.quote_pick = function(){
|
||||||
|
/* Customizeable constants */
|
||||||
|
var L_QUOTE_MARK = '"';
|
||||||
|
var R_QUOTE_MARK = '"';
|
||||||
var QUOTE_AUTHOR_ID = "quote_author";
|
var QUOTE_AUTHOR_ID = "quote_author";
|
||||||
var QUOTE_AUTHOR_PREFIX = "~ "
|
var QUOTE_AUTHOR_PREFIX = "~ "
|
||||||
var QUOTE_VALUE_ID = "quote_value";
|
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. */
|
window.quote_old = window.quote; /* The quote currently in use. */
|
||||||
quoteIndex = Math.floor(Math.random() * window.quotes.length);
|
quoteIndex = Math.floor(Math.random() * window.quotes.length);
|
||||||
@ -29,7 +37,7 @@ window.genQuote = function(){
|
|||||||
window.quotes.push(window.quote_old);
|
window.quotes.push(window.quote_old);
|
||||||
|
|
||||||
if(quote_text = document.getElementById(QUOTE_VALUE_ID))
|
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))
|
if(quote_author = document.getElementById(QUOTE_AUTHOR_ID))
|
||||||
quoteAuthorText.textContent = QUOTE_AUTHOR_PREFIX + window.quote[1];
|
quoteAuthorText.textContent = QUOTE_AUTHOR_PREFIX + window.quote[1];
|
||||||
|
Loading…
Reference in New Issue
Block a user