<script>
(function () {
    var data = window.blogData;
    if (!data || !data.articles || !data.articles.length) return;
    var id = document.body.getAttribute("data-note-id");
    var all = data.articles;
    var me = null;
    for (var i = 0; i < all.length; i++) { if (all[i].id === id) { me = all[i]; break; } }
    if (!me) return;
    var list = me.category ? all.filter(function (a) { return a.category === me.category; }) : all;
    var idx = list.indexOf(me);
    var builtin = document.querySelector("#content-footer .navigation");
    if (builtin) builtin.style.display = "none";
    var content = document.getElementById("content");
    if (!content) return;
    var prev = idx + 1 < list.length ? list[idx + 1] : null;
    var next = idx > 0 ? list[idx - 1] : null;
    if (!prev && !next) return;
    var box = document.createElement("nav");
    box.className = "blog-prevnext";
    var inner = "";
    if (prev) {
        inner += '<a class="blog-pn prev" href="' + prev.url + '"><span class="blog-pn-label">Previous</span><span class="blog-pn-title">' + prev.title + '</span></a>';
    } else {
        inner += '<span class="blog-pn empty"></span>';
    }
    if (next) {
        inner += '<a class="blog-pn next" href="' + next.url + '"><span class="blog-pn-label">Next</span><span class="blog-pn-title">' + next.title + '</span></a>';
    } else {
        inner += '<span class="blog-pn empty"></span>';
    }
    box.innerHTML = inner;
    content.appendChild(box);
})();
</script>