function build_next_prev() { var url = window.location.href var cur = Number(url.split('/')[6]); var app = url.split('/')[4]; var model = url.split('/')[5]; if (cur) { var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = '.np-container {padding-left: 0;} .prev, .next {display: inline-block; margin-right: .5em;} .prev:after { content: "|"; margin-left:.5em;} .prev a:before {content: "\u00AB"; margin-right: 3px;} .next a:after{content: "\u00BB"; margin-left: 3px;}'; document.getElementsByTagName('head')[0].appendChild(style); json_url = '/admin/data/'+app+'/'+model+'/'+cur+'/'; //console.log(json_url); var container = document.createElement("ul"); var next_li = document.createElement("li"); var next_link = document.createElement("a"); var prev_li = document.createElement("li"); var prev_link = document.createElement("a"); prev_li.className = "prev"; next_li.className = "next"; container.className = "np-container"; next_link.textContent = "Next"; prev_link.textContent = "Prev"; var request = new XMLHttpRequest(); request.open('GET', json_url, true); request.onload = function() { if (request.status >= 200 && request.status < 400) { var data = JSON.parse(request.responseText); next_link.href = data['next']; prev_link.href = data['prev']; if (data['next'] != '') { next_li.appendChild(next_link); } if (data['prev']) { prev_li.appendChild(prev_link); } } else { console.log("server error"); } }; request.onerror = function() { console.log("error on request"); }; request.send(); container.appendChild(prev_li); container.appendChild(next_li); //console.log(container); Array.from(document.getElementsByClassName('object-tools')).forEach(function(item) { item.parentNode.insertBefore(container, item.nextSibling); }) } else { return; } }; document.addEventListener("DOMContentLoaded", function(event) { build_next_prev(); });