Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
はてなブログに最終更新日時を追加するためのjs
window.onload = function () {
if (location.href.indexOf('entry') > 0) {
fragments = location.href.split('/');
year = fragments[4];
month = parseInt(fragments[5], 10);
$.get("https://blog.innotamago.com/sitemap_periodical.xml", {year: year, month: month}, function (data) {
$(data).find("url").each(function (index, dom) {
if ($(dom).find("loc").text() === location.href) {
lastUpdatedAt = Date.parse($(dom).find("lastmod").text());
publishedAt = $('meta[property="article:published_time"]').attr("content");
if (lastUpdatedAt > publishedAt) {
datetime = new Date(lastUpdatedAt);
$('div.entry-date').append(
'<a class="last-updated-at"><span><span class="date-year">'
+ datetime.getFullYear()
+ '</span><span class="hyphen">-</span><span class="date-month">'
+ ('0' + (datetime.getMonth() + 1)).slice(-2)
+ '</span><span class="hyphen">-</span><span class="date-day">'
+ ('0' + datetime.getDate()).slice(-2) + '</span></span></a>'
);
}
}
});
});
}
}
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.