Beatitudes and More
by Matt Saul
HTML
<div id="main">
<div id="poem_holder">
Loading...
</div>
</div>
CSS
#main {
text-align: center;
margin: auto;
background: #eed;
}
#poem_holder {
text-align: left;
background: #fff;
margin: 1em auto;
padding: .5em 2em;
font-family: Arial,helvetica,san-serif;
font-size: .8em;
max-width: 550px;
}
#poem_holder p {
margin-bottom: .6em;
}
JavaScript
var firstTenArray = [];
$(document).ready(function() {
// get latest tweet from Trump Twitter account
var k = "https://voteforyou.co/Auxiliary/tweets_puller/trump";
$.ajax({
dataType: 'json',
url: k,
success: function(data) {
$.each(data, function(i, item) {
item = item.full_text;
itemArray = item.split(" ");
fixedItem = '';
for (var i = 0, len = itemArray.length; i < len; i++) {
// console.log('|' + itemArray[i] + '|');
if (validateUrl(itemArray[i]) == false) {
fixedItem = fixedItem + itemArray[i] + " ";
}
}
// fixedItem = itemArray.join(" ");
firstTenArray.push(fixedItem + "<br>");
})
/*
// just first part of tweet
spaceSplit = tweet.split(" ");
debt = spaceSplit[0];
*/
// console.log(firstTenArray);
}
});
setTimeout(writePoem, 1600);
});
function validateUrl(textval) // return true or false.
{
/*
var regex = new RegExp("^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_\+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?");
found = regex.test(textval);
*/
var n = textval.indexOf("http://");
var o = textval.indexOf("https://");
if (n != -1 || o != -1){
found = true;
}
else {
found = false;
}
return found;
}
function writePoem() {
var finalPoemArray = [];
finalPoemArray[0] = "<p>Blessed are the poor in spirit: for theirs is the kingdom of Heaven.</p>";
finalPoemArray[2] = "<p>Blessed are those who mourn: for they will be comforted.</p>";
finalPoemArray[3] = "<p>Blessed are the meek: for they will inherit the earth.</p>";
finalPoemArray[4] = "<p>Blessed are those who hunger and thirst for righteousness: for they will be filled.</p>";
finalPoemArray[5] = "<p>Blessed are the merciful: for they will be shown mercy.</p>";
finalPoemArray[6] = "<p>Blessed are the pure in heart: for they will see God.</p>";
finalPoemArray[7] = "<p>Blessed are the peacemakers: for...