$('#main-button').click(); // click the "MAIN" button (scrolls up) setTimeout(changeTexts, 1000); // run after 1 second (to give time to scrolling) function changeTexts() { fade("#title", "Practice coding") const action = random(["try", "run", "execute", "modify"]) const js = link("JavaScript", "https://developer.mozilla.org/docs/Web/JavaScript") fade("#text1", "You can " + action + " the " + js + " code below") const functions = join(["fade", "join", "link", "random"]); fade("#text2", "Use functions like " + functions) fade(".button.run", "Run it again") $('#main-section').animate({'min-height': '0'}, 1500); // slowly shrink main section } // If you dare, run this. It will load code that, when run, creates an Arkham Horror LGC tracker app. //fetchCode("https://gist.github.com/fmaylinch/c511180f974da8d352663d4f2e499438/raw"); // You may also try the Arkham Horror LGC tracker with this link: https://bit.ly/arkham-lgc-tracker // Loads code from url and replaces current code in editor function fetchCode(url) { fetch(url) .then(resp => resp.text()) .then(setCode) } // Replaces current code in editor function setCode(code) { codeMirrorEditorView.dispatch({ changes: { from: 0, to: codeMirrorEditorView.state.doc.length, insert: code }, }); } // Updates a page element, by its CSS selector function set(selector, value) { let element = document.querySelector(selector) element.innerHTML = value } // It's like set(), but uses jQuery for a fade-in-out effect function fade(selector, value) { let elem = $(selector) elem.fadeOut('slow', () => { elem.html(value).fadeIn('slow') }); } // Joins the values with commas and "and" function join(values) { if (!Array.isArray(values)) { return values } return values.length === 1 ? values[0] : values.slice(0, values.length-1).join(", ") + " and " + values[values.length-1] } // Builds an HTML link function link(text, url) { return `${text}` } // Returns a random number between 0 and n-1. // If n is an array, returns a random element of n. function random(n) { if (Array.isArray(n)) { return n[random(n.length)] } return Math.floor(Math.random() * n) }