UNPKG

universalviewer

Version:

The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎

2 lines (1 loc) 1.06 kB
var T=function(r){try{if(typeof r!="string"||r==="")return r;var a=document.createDocumentFragment(),i=document.createElement("div");a.appendChild(i),i.innerHTML=r,y.forEach(function(c){for(var u=a.querySelectorAll(c),s=u.length-1;s>=0;s--){var t=u[s];t.parentNode?t.parentNode.removeChild(t):a.removeChild(t);for(var h=f(t),l=0;l<h.length;l++)n(h[l])}});for(var o=f(a),e=0;e<o.length;e++)n(o[e]);var v=document.createElement("div");v.appendChild(a);var p=v.querySelector("div");return p!==null?p.innerHTML:v.innerHTML}catch(c){return console.error(c),""}},n=function(r){if(!(r.nodeType&&r.nodeType!==1)){for(var a=r.attributes.length-1;a>=0;a--){var i=r.attributes.item(a),o=i.name;if(!d.includes(o.toLowerCase())){r.removeAttribute(o);continue}var e=i.value;e!=null&&e.toLowerCase().includes("javascript:")&&r.removeAttribute(o)}for(var v=f(r),a=0;a<v.length;a++)n(v[a])}},f=function(r){return r.children!=null?r.children:r.childNodes},d=["class","id","href","src","name","slot"],y=["script","style","iframe","meta","link","object","embed"];export{T as a};