1
0

working on quotes again

This commit is contained in:
dtb 2022-02-20 13:04:11 -05:00
parent dc41d19150
commit 3c927453a2
2 changed files with 22 additions and 29 deletions

View File

@ -11,6 +11,7 @@
<META CONTENT="https://ia601509.us.archive.org/31/items/trinitydotmoe88x31/trinitydotmoe88x31.bmp" NAME="og:image" />
<META CONTENT="noindex" NAME="googlebot" /> <!-- FUCK GOOGLE -->
<META CONTENT="interest-cohort=()" HTTP-EQUIV="Permissions-Policy" /> <!-- FUCK GOOGLE -->
<SCRIPT SRC="/js/quotes.js" TYPE="module"></SCRIPT>
<STYLE></STYLE>
<TITLE>trinity dot moe</TITLE> <!-- Also considered: 1945-07-16T05:26-06:00 -->
</HEAD>
@ -337,6 +338,11 @@ WIDTH="88px" <BR />
<HR ALIGN="left" SIZE="1" WIDTH="25%" />
<P ID="quote_value">QUOTE</P>
<P ID="quote_author">QUOTE AUTHOR</P>
<HR ALIGN="left" SIZE="1" WIDTH="25%" />
<P>
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.

View File

@ -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
* - <SCRIPT SRC="quotes.js" TYPE="module"></SCRIPT>
* - 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];
};