Last active
August 17, 2018 07:50
-
-
Save Shilo/d66009a55777218fa153d46829096491 to your computer and use it in GitHub Desktop.
Blogger page that will list quotes in all the posts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function () { | |
var feed = "/feeds/posts/default?alt=rss"; | |
$.ajax(feed, { | |
accepts: { | |
xml: "application/rss+xml" | |
}, | |
dataType: "xml", | |
error: function (xhr, status, error) { | |
var contentsDiv = $("#contents"); | |
contentsDiv.html(status+"<br/>"+error); | |
}, | |
success: function (data) { | |
var contentsDiv = $("#contents"); | |
var quotesList = $("<ol></ol>").text(""); | |
contentsDiv.empty(); | |
contentsDiv.append(quotesList); | |
$(data).find("item").each(function () { | |
var el = $(this); | |
var title = el.find("title").text(); | |
var link = el.find("link").text(); | |
var description = el.find("description").text(); | |
var tag_regex = /(<([^>]+)>)/ig | |
var description2 = description.replace(/<br>/ig, '\n').replace(/<br\/>/ig, '\n').replace(/<br \/>/ig, '\n').replace(tag_regex, ''); | |
var all_lines = description2.split("\n"); | |
var lines = $.map(all_lines, function (v) { | |
return v === "" ? null : v; | |
}); | |
if (lines.length > 0) { | |
var last_line_index = lines.length - 1; | |
var last_line = lines[last_line_index]; | |
var has_quotes = false; | |
var quote_lines = ""; | |
while (last_line_index >= 0 && last_line != null && last_line.charAt(0) == "\"") { | |
quote_lines = last_line + "<br/><br/>" + quote_lines; | |
last_line_index--; | |
last_line = lines[last_line_index]; | |
has_quotes = true; | |
} | |
if (quote_lines.length > 0) { | |
var quoteContent = "<b><a href=\"" + link + "\">" + title + "</a></b><br/>" + quote_lines; | |
var quoteItem = $("<li></li>").html(quoteContent); | |
quotesList.append(quoteItem); | |
} | |
} | |
}); | |
} | |
}); | |
}); | |
</script> | |
<div id="contents">Loading...</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment