MCPcopy
hub / github.com/hoothin/UserScripts / setHTML

Function setHTML

Pagetual/pagetual.user.js:4922–4962  ·  view source on GitHub ↗
(target, html, doc)

Source from the content-addressed store, hash-verified

4920 }
4921
4922 function setHTML(target, html, doc) {
4923 if (!target) return;
4924 const htmlStr = html === null || html === undefined ? '' : String(html);
4925 if (tryDirectSetHTML(target, htmlStr) || tryPolicySetHTML(target, htmlStr)) return;
4926 const targetDoc = doc || target.ownerDocument || document;
4927 const fragment = createHTML(htmlStr, targetDoc);
4928 const targetIsHtml = target.nodeType === 1 && target.nodeName.toLowerCase() === 'html';
4929 if (targetIsHtml) {
4930 let htmlNode = null;
4931 const fragChildren = fragment.childNodes;
4932 for (let i = 0; i < fragChildren.length; i++) {
4933 const child = fragChildren[i];
4934 if (child.nodeType === 1 && child.nodeName.toLowerCase() === 'html') {
4935 htmlNode = child;
4936 break;
4937 }
4938 }
4939 if (htmlNode) {
4940 const attrs = target.attributes;
4941 for (let i = attrs.length - 1; i >= 0; i--) {
4942 target.removeAttribute(attrs[i].name);
4943 }
4944 const srcAttrs = htmlNode.attributes;
4945 for (let i = 0; i < srcAttrs.length; i++) {
4946 target.setAttribute(srcAttrs[i].name, srcAttrs[i].value);
4947 }
4948 while (target.firstChild) {
4949 target.removeChild(target.firstChild);
4950 }
4951 const htmlChildren = Array.from(htmlNode.childNodes);
4952 for (let i = 0; i < htmlChildren.length; i++) {
4953 target.appendChild(htmlChildren[i]);
4954 }
4955 return;
4956 }
4957 }
4958 while (target.firstChild) {
4959 target.removeChild(target.firstChild);
4960 }
4961 target.appendChild(fragment);
4962 }
4963
4964 const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
4965

Callers 15

pagetual.user.jsFile · 0.70
preloadMethod · 0.70
addCssMethod · 0.70
initMethod · 0.70
addToStageMethod · 0.70
initMethod · 0.70
initMethod · 0.70
setSelectorDivMethod · 0.70
createEditFunction · 0.70
initConfigFunction · 0.70
initMethod · 0.70
updateNumMethod · 0.70

Calls 3

tryDirectSetHTMLFunction · 0.70
tryPolicySetHTMLFunction · 0.70
createHTMLFunction · 0.70

Tested by

no test coverage detected