(function () { var content = document.querySelector('.content'); if (!content) return; var headings = content.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!headings.length) return; headings.forEach(function (h, i) { if (h.querySelector('a.btn')) return; var a = document.createElement('a'); if (h.tagName === 'H1') { a.href = '?edit'; } else if (h.tagName === 'H2') { a.href = '?edit§ion=' + (i + 1) + '&span'; } else { return; } a.className = 'btn btn-small btn-float'; a.textContent = 'edit'; h.appendChild(document.createTextNode(' ')) h.appendChild(a); }); }());