2.0.0 • Published 7 years ago
quote-roulette v2.0.0
quote-roulette
yarn install quote-roulette
npm install quote-roulette
A whole npm package dedicated to Hollywood quotes?
Surely you can't be serious. I am serious... and don't call me Shirley.
How to Contribute
Fork this repo. Add a line to the end of quotes.txt and make a pull request.
Each line in quotes.txt
should contain the IMDb title ID, a tab character, and the quote:
tt0304141 I solemnly swear that I am up to no good.
Browse imdb.com for quote transcripts and title IDs.
Format
quotes.json
has the following structure:
{
"quotes": []
}
Where quotes
is an array of objects:
{
"imdbID": "tt0304141",
"quote": "I solemnly swear that I am up to no good.",
"scooptvURL": "https://scooptv.io/title/tt0304141/",
"imdbURL": "http://www.imdb.com/title/tt0304141/"
}
How to Use
jQuery
Put quotes.json
somewhere on your server.
<div id="quote-roulette"></div
var quoteRoulette = $('#quote-roulette');
var allQuotes = null;
$.getJSON('/quotes.json', function(data) {
allQuotes = data.quotes;
updateQuote();
});
quoteRoulette.click(function(e) {
e.preventDefault();
updateQuote();
});
function updateQuote(obj) {
var index = getRandomInt(0, allQuotes.length);
quoteRoulette.text(allQuotes[index].quote);
}
// returns an integer, min <= integer < max
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}