-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.min.js
More file actions
1 lines (1 loc) · 3.83 KB
/
Copy pathindex.min.js
File metadata and controls
1 lines (1 loc) · 3.83 KB
1
(()=>{let f=Element.prototype.setHTMLUnsafe,i=ShadowRoot.prototype.setHTMLUnsafe;function p(t,n,e,r,a={}){e="safe"===e;let o=r;var s=(o=r instanceof ShadowRoot?r.host:o)instanceof Element?o.tagName:"DIV";if(n&&!e){n=document.createRange();r instanceof Element?n.selectNodeContents(r):r instanceof ShadowRoot?n.selectNodeContents(r.host):(r=r.ownerDocument?.body||document.body,n.selectNodeContents(r));let e=n.createContextualFragment(t);return function e(t){var n;for(n of t.querySelectorAll("template[shadowrootmode]")){var r=n.getAttribute("shadowrootmode"),a=n.parentNode;!a||"open"!==r&&"closed"!==r||((a=a.attachShadow({mode:r})).appendChild(n.content),n.remove(),e(a))}}(e),e}var r=(new DOMParser).parseFromString("<!DOCTYPE html><html><body></body></html>","text/html"),f=r.createElement(s);if(r.body.appendChild(f),e){if(!("setHTML"in f))throw new Error("Safe parsing requested but setHTML is not available.");f.setHTML(t,a)}else"setHTMLUnsafe"in f?f.setHTMLUnsafe(t):f.innerHTML=t;let i=document.createDocumentFragment();for(;f.firstChild;)i.appendChild(document.adoptNode(f.firstChild));return i}function o(t,n,r,a={},o){var e="safe"===r,s=!!a.runScripts;if("replaceChildren"===o){if(e){if("setHTML"in t)return void t.setHTML(n,a);throw new Error("Safe setting requested but setHTML is not available.")}if(s){let e=p(n,!0,"unsafe",t,a);t.replaceChildren(e)}else{e=t instanceof ShadowRoot?i:f;e?e.call(t,n):t.innerHTML=n}}else{let e=p(n,s,r,t,a);switch(o){case"replaceWith":t.replaceWith(e);break;case"before":t.before(e);break;case"prepend":t.prepend(e);break;case"append":t.append(e);break;case"after":t.after(e)}}}function t(e,t,n={},r){let a="";return new WritableStream({write(e){a+=e},close(){o(e,a,t,n,r)}})}for(var e of[Element.prototype,ShadowRoot.prototype]){let n=e.setHTMLUnsafe;e.setHTMLUnsafe=function(e,t){(!t||!t.runScripts)&&n?n.call(this,e):o(this,e,"unsafe",t,"replaceChildren")},e.appendHTMLUnsafe??=function(e,t){o(this,e,"unsafe",t,"append")},e.prependHTMLUnsafe??=function(e,t){o(this,e,"unsafe",t,"prepend")},e.streamHTMLUnsafe??=function(e){return t(this,"unsafe",e,"replaceChildren")},e.streamAppendHTMLUnsafe??=function(e){return t(this,"unsafe",e,"append")},e.streamPrependHTMLUnsafe??=function(e){return t(this,"unsafe",e,"prepend")},"setHTML"in Element.prototype&&(e.appendHTML??=function(e,t){o(this,e,"safe",t,"append")},e.prependHTML??=function(e,t){o(this,e,"safe",t,"prepend")},e.streamHTML??=function(e){return t(this,"safe",e,"replaceChildren")},e.streamAppendHTML??=function(e){return t(this,"safe",e,"append")},e.streamPrependHTML??=function(e){return t(this,"safe",e,"prepend")})}for(var n of[Element.prototype,CharacterData.prototype,DocumentType.prototype])n.beforeHTMLUnsafe??=function(e,t){o(this,e,"unsafe",t,"before")},n.afterHTMLUnsafe??=function(e,t){o(this,e,"unsafe",t,"after")},n.replaceWithHTMLUnsafe??=function(e,t){o(this,e,"unsafe",t,"replaceWith")},n.streamBeforeHTMLUnsafe??=function(e){if(this.parentNode)return t(this,"unsafe",e,"before");throw new Error("Node has no parent")},n.streamAfterHTMLUnsafe??=function(e){if(this.parentNode)return t(this,"unsafe",e,"after");throw new Error("Node has no parent")},n.streamReplaceWithHTMLUnsafe??=function(e){if(this.parentNode)return t(this,"unsafe",e,"replaceWith");throw new Error("Node has no parent")},"setHTML"in Element.prototype&&(n.beforeHTML??=function(e,t){o(this,e,"safe",t,"before")},n.afterHTML??=function(e,t){o(this,e,"safe",t,"after")},n.replaceWithHTML??=function(e,t){o(this,e,"safe",t,"replaceWith")},n.streamBeforeHTML??=function(e){if(this.parentNode)return t(this,"safe",e,"before");throw new Error("Node has no parent")},n.streamAfterHTML??=function(e){if(this.parentNode)return t(this,"safe",e,"after");throw new Error("Node has no parent")},n.streamReplaceWithHTML??=function(e){if(this.parentNode)return t(this,"safe",e,"replaceWith");throw new Error("Node has no parent")})})();