MCPcopy Index your code
hub / github.com/XIU2/UserScript / insScript

Function insScript

Autopage.user.js:2317–2336  ·  view source on GitHub ↗
(selector, contextNode = document, toE = document.body)

Source from the content-addressed store, hash-verified

2315 }
2316 // 插入 <Script>
2317 function insScript(selector, contextNode = document, toE = document.body) {
2318 let scriptElems = contextNode;
2319 if (selector) {
2320 if (contextNode instanceof Array) {
2321 scriptElems = []; contextNode.forEach(function (one) {scriptElems = scriptElems.concat(getAll(selector, one, one));})
2322 } else {
2323 scriptElems = getAll(selector, contextNode, contextNode);
2324 }
2325 }
2326
2327 scriptElems.forEach(function (one) {
2328 if (one.tagName === 'SCRIPT') {
2329 if (one.src) {
2330 toE.appendChild(document.createElement('script')).src = one.src;
2331 } else {
2332 toE.appendChild(document.createElement('script')).textContent = one.textContent;//.replaceAll('document.write', '');
2333 }
2334 }
2335 });
2336 }
2337 // 插入 <Style>
2338 function insStyle(style) {
2339 if (style.indexOf('{') === -1){style += '{display: none !important;}'}

Callers 4

mangabz_insertEFunction · 0.85
dm5_insertEFunction · 0.85
xmanhua_insertEFunction · 0.85
processElemsFunction · 0.85

Calls 1

getAllFunction · 0.85

Tested by

no test coverage detected