Skip to content

Instantly share code, notes, and snippets.

@Shilo Shilo/blogger_quotes.js
Last active Aug 17, 2018

Embed
What would you like to do?
Blogger page that will list quotes in all the posts.
<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
You can’t perform that action at this time.