Skip to content

atomutek/fortune

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 

Repository files navigation

Fortune

Fortune aims to be a minimalist fortune script. Quotes / fortunes with equations in MathJax are supported.

How it works

Generate a quote

The fortune function gets a random fortune from the quotes array and writes it in the HTML document.

function fortune(){
  /* calculate a random index */
  index = Math.floor(Math.random() * quotes.length);
  /* display the quotation */
  document.write("<p>" + quotes[index] + "</p>");
};

To do so in the html just add:

<script type="text/javascript" src="js/fortune.js" type="text/javascript"></script>
<script type="text/javascript">fortune();</script>

Add a new quote or modify a quote

Open the fortune.js file and modify the quotes array.

Add MathJax support

Add the following code to support MathJax quotes:

<script>
    MathJax = {
        tex: {
            inlineMath: [
                ['$', '$'],
                ['\\(', '\\)']
            ]
        }
    };
</script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

Example

To see what fortune.js can do for you, check the index.html file in the example folder.

Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published