MCPcopy Index your code
hub / github.com/hoothin/UserScripts / getElement

Function getElement

Pagetual/pagetual.user.js:4597–4628  ·  view source on GitHub ↗
(sel, doc, contextNode, bySort)

Source from the content-addressed store, hash-verified

4595 }
4596
4597 function getElement(sel, doc, contextNode, bySort) {
4598 try {
4599 if (!isXPath(sel)) {
4600 let checkShadow = s => {
4601 let selSplit = s.split(" =>> ");
4602 if (selSplit.length === 2) {
4603 let ele = doc.querySelector(selSplit[0]);
4604 return ele && ele.shadowRoot && ele.shadowRoot.querySelector(selSplit[1]);
4605 } else return doc.querySelector(s);
4606 };
4607 if (!bySort) {
4608 return checkShadow(sel);
4609 } else {
4610 let selArr = sel.split(",");
4611 try {
4612 for (let i = 0; i < selArr.length; i++) {
4613 let ele = checkShadow(selArr[i].trim());
4614 if (ele) {
4615 return ele;
4616 }
4617 }
4618 } catch(e) {
4619 return checkShadow(sel);
4620 }
4621 return null;
4622 }
4623 }
4624 } catch(e) {
4625 debug(e, 'Error selector');
4626 }
4627 return getElementByXpath(sel, doc, contextNode);
4628 }
4629
4630 function compareNodeName(node, names) {
4631 if (!node || !node.nodeName || !node.nodeName.toLowerCase) {

Callers 14

getAllElementsFunction · 0.85
ruleMatchPreMethod · 0.85
ruleMatchReadyMethod · 0.85
scrollToShowMethod · 0.85
waitElementMethod · 0.85
getNextLinkMethod · 0.85
filterElesMethod · 0.85
checkStopSignMethod · 0.85
getInsertMethod · 0.85
initPageMethod · 0.85
initMethod · 0.85
initMethod · 0.85

Calls 4

checkShadowFunction · 0.85
debugFunction · 0.85
isXPathFunction · 0.70
getElementByXpathFunction · 0.70

Tested by

no test coverage detected