let listFetched = false; let list = []; let position = 1; let rumor = ""; let addedToList = false; window.onload = function () { getRumor(position++); addEvent( document.getElementById('generate'), 'click', function () { getRumor(1 + position++); } ); addEvent( document.getElementById('listClear'), 'click', function () { clearList(); } ); addEvent( document.getElementById('listAdd'), 'click', function () { addToList(); } ); addEvent( document.getElementById('download'), 'click', function () { createPDF(); } ); }; function addEvent(element, evnt, funct){ if (element.attachEvent) return element.attachEvent('on'+evnt, funct); else return element.addEventListener(evnt, funct, false); } function generate() { if (!listFetched) { fetch("https://rumor.turtlebard.com/") .then(function (response) { return response.json(); }) .then(function (data) { let rumorData = data; list = rumorData; listFetched = true; position = 1; getRumor(1); }) .catch(function (err) { console.warn("Something went wrong.", err); }); } else { getRumor(position); addedToList = true; } } function getRumor(position) { if (position list.length || position == 0) { position++; listFetched = false; generate(); } else { addedToList = true; rumor = list[position-1].toString(); document.getElementById("rumor").innerHTML = '"' + rumor + '" '; } } window.jsPDF = window.jspdf.jsPDF; let rumorlist = ""; let listCount = 0; function createPDF() { if (listCount 0){ let pageWidth = 8.5, filename = "Fantasy Rumors :: Generated by TurtleBard_com.pdf"; lineHeight = 1.2, linesPerPage = 36, margin = 1, pageLines = [], maxLineWidth = pageWidth - margin * 2, fontSize = 14, ptsPerInch = 72, oneLineHeight = (fontSize * lineHeight) / ptsPerInch text = ""+ rumorlist + "\n\n\n" + "Generated using the Fantasy Rumor Generator at TurtleBard.com/rumor", doc = new jsPDF({ unit: "in", format: "letter", lineHeight: lineHeight }).setProperties({ title: "Fantasy Rumors (Generated by TurtleBard.com/rumors)", author: "Turtle Bard", creator: "Turtle Bard" }); // splitTextToSize takes your string and turns it in to an array of strings, // each of which can be displayed within the specified maxLineWidth. let textLines = doc .setFont("helvetica") .setFontSize(fontSize) .splitTextToSize(text, maxLineWidth); if (textLines.length linesPerPage) { let i = 0; while (i linesPerPage) { doc.addPage("letter", "portrait"); let i = 0; while (i Download (' + listCount +')'; } } function clearList() { listCount = 0; rumorlist = ""; addedToList = true; document.getElementById("download").innerHTML = 'Download'; } Generate Add to List Clear List Download