1
0

move js, tidy quotes.js

This commit is contained in:
dtb
2021-08-04 11:30:41 -04:00
parent efe43b6a25
commit 31f240b580
16 changed files with 53 additions and 117 deletions

26
homepage/js/cookies.js Normal file
View File

@@ -0,0 +1,26 @@
/*
these code snippets copied from
https://www.w3schools.com/js/js_cookies.asp
used under fair use; for copyright see https://www.w3schools.com/about/about_copyright.asp
window.setCookie() sets a cookie, window.getCookie() gets a cookie.
*/
window.setCookie = function(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
};
window.getCookie = function(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while(c.charAt(0) == ' ') c = c.substring(1);
if(c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
};

149
homepage/js/quotes.js Normal file
View File

@@ -0,0 +1,149 @@
/*
quotes.js
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.
*/
// 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 = [
[ "Yeah, that's just how it is. Just, nothing. So much nothing that it hurts.",
"danger/u/ aefd79" ],
[ "Reason has always existed, but not always in a reasonable form.",
"Katy Perry" ],
[ "Consult your pineal gland.",
"Eris" ],
[ "Back to 8chan please",
"Skyglider" ], /* wirechan */
[ "No, I am your father.",
"Darth Vader" ], /* Star Wars 2 */
[ "A checklist can aid here.",
"Lance Leventhal" ],
[ "Special thanks to Ками for their help adding quotes to this page.",
"Deven Blake" ],
[ "You never know.",
"Mr. McSweeney" ],
[ "You lost the game.",
"Anonymous" ],
[ "Jerma isn't particularly religious.",
"Jerma985 Wikitubia Fandom article" ],
[ "put me on here now",
"arsonist catboy" ],
[ "These are no longer memes this is y'all repressed anger",
"Khalifist" ],
[ "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.",
"Bjarne Stroustrup" ],
[ "I'll sleep when I'm dead.",
"Warren Zevon" ],
[ "I would have made a good pope.",
"Richard M. Nixon" ],
[ "To sit alone with my conscience will be judgment enough for me.",
"Charles William Stubbs" ],
[ "Your enemy is where you are not.",
"Sun Tzu (paraphrased)" ], /* Art of War */
[ "Be everywhere.",
"social media influencing 101" ],
[ "I wish everyone was bald.",
"Anonymous" ], /* 4chan */
[ "Nah",
"Soldier G65434-2" ],
[ "The kill command is a basic UNIX system command.",
"Matthew Helmke" ], /* Ubuntu Linux Unleashed 2021 Edition; pg 283 */
[ "If you raise the effing hot dog, I will kill you. Figure it out.",
"Craig Jelinek" ],
[ "Don't think. Feel and you'll be tanasinn.",
"名無" ], /* 2chan */
[ "They had overshadowed her in life. They would obliterate her in death.",
"Khaled Hosseini" ], /* A Thousand Splendid Suns */
[ "are your bones made out of fucking depleted uranium",
"Anonymous" ], /* 4chan/x/ - tulpa peridot thread */
[ "Giving the Linus Torvalds award to the Free Software Foundation is sort of like giving the Han Solo award to the Rebel Fleet.",
"Richard Stallman" ], /* Revolution OS (2001) */
[ "Filthy Frank is the embodiment of everything a person should not be.",
"George Miller" ],
[ "It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.",
"Nathaniel Borenstein" ],
[ "An idiot admires complexity. A genius admires simplicity.",
"Terry A. Davis" ],
[ "When in doubt, use brute force.",
"Ken Thompson" ],
[ "Where MS Word is WYSIWYG (What You See Is What You Get), and Latex is WYGIWYW (What You Get Is What You Want), HTML is WYGIWYD (What You Get Is What You Deserve).",
"Anonymous" ],
[ "Easy is the opposite of hard, not the opposite of time-consuming.",
"Brad Fitzpatrick" ], /* discussion about plan9 support with Go */
[ "Blame the Nazis for making me become a gun designer. I always wanted to construct agricultural machinery.",
"Mikhail Kalashnikov" ],
[ "since KFC fired me the 11 herbs and spices are coriander, onion powder, garlic powder, salt, white pepper, black pepper basil, parsley, chili pepper, lemon pwder, thyme, and sage.",
"@ashley.shoy, Tiktok" ],
[ "Sooner or later there has to be peace.",
"Abigail Thorn" ], /* Identity: A Trans Coming Out Story */
[ "Ich bin ein Berliner.",
"John F. Kennedy" ],
[ "I am a Bangor!",
"Erwin Kreuz" ],
[ "It's not enough that I should succeed - others should fail.",
"Unknown" ],
[ "Secundus says hello to his Prima, wherever she is. I ask, my mistress, that you love me.",
"Unknown" ], /* House and Office of Volusius Iuvencus */
[ "Debugging on windows is like trying to fix spelling mistakes but you can't see the words",
"arwn" ] /* 9fans discord */
];
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!
*/
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);
// 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 there was a quote in use, let's put it back in the quotes array.
if(window.oldQuote) window.quotes.push(window.oldQuote);
// 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);
};

25
homepage/js/sheets.js Normal file
View File

@@ -0,0 +1,25 @@
/* Depends on cookies.js (non-free) */
/*
SHEETS.JS
PUBLIC DOMAIN CODE BY DEVEN BLAKE
setStyling(sheet) sets the stylesheet to the file at sheet.
e.g. setStyling("sheet.css") will change the stylesheet to "sheet.css"
initializesheets() just sets the sheet to the sheet in the cookie, if
the user saved their preferences.
Needs a <LINK HREF="" ID="styling" REL="stylesheet" /> somewhere on the
page in order to work.
You can use setStyling("") to reset it.
*/
window.setStyling = function(sheet) {
document.getElementById('styling').setAttribute('href', sheet);
return sheet;
};
window.initializesheets = function() {
var sheet = window.getCookie('sheet');
if(sheet != '') window.setStyling(sheet);
};