-
Notifications
You must be signed in to change notification settings - Fork 3
/
marginalia.min.js
3 lines (3 loc) · 1.35 KB
/
marginalia.min.js
1
2
3
(function(){function k(d,b){for(var a=d.childNodes,c=0,f,g=[];f=a[c];++c)1==f.nodeType&&-1!==(f.innerText||f.textContent||"").replace(/\s+/g," ").indexOf(b)&&(g=g.concat(k(f,b)));return g.length?g:d}function l(d,b){var a=d.nextElementSibling||!1;if(!a||!a.classList.contains("marginalia-list")){a=document.createElement(m);a.setAttribute("class","marginalia-list ");var c=document.createElement("button");c.setAttribute("class","marginalia-button ");c.innerHTML="<span>Show</span>";c.addEventListener("click",
function(){for(var a=document.querySelectorAll("[data-marginalia-active]"),b=0,e;e=a[b];b++)e!=d&&(e.removeAttribute("data-marginalia-active"),e.querySelector(".marginalia-button").innerHTML="<span>Show</span>");d.hasAttribute("data-marginalia-active")?(d.removeAttribute("data-marginalia-active"),c.innerHTML="<span>Show</span>"):(d.setAttribute("data-marginalia-active",""),c.innerHTML="<span>Hide</span>")},!1);d.appendChild(c);d.parentNode.insertBefore(a,d.nextSibling)}a.appendChild(b)}function n(d){var b=
d.getAttribute("data-fragmention");if(b){var a=decodeURIComponent(b.substring(2)).replace(/\+/g," ").split(" "),b=a[0],a=parseFloat(a[1])||0,b=k(document,b),c=b.length,a=c&&a%c;(a=c&&b[c&&0<=a?a:c+a])&&a!=document&&l(a,d)}}for(var e=document.querySelector("#response-list"),m=e.tagName,e=e.querySelectorAll("[data-fragmention]"),h=0;h<e.length;h++)n(e[h])})();