MCPcopy Create free account
hub / github.com/XIU2/UserScript / getAllElements

Function getAllElements

V2ex-Enhanced.user.js:588–605  ·  view source on GitHub ↗
(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined)

Source from the content-addressed store, hash-verified

586 }
587 }
588 function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
589 if (!selector) return [];
590 contextNode = contextNode || doc;
591 if (typeof selector === 'string') {
592 if (selector.search(/^css;/i) === 0) {
593 return getAllElementsByCSS(selector.slice(4), contextNode);
594 } else {
595 return getAllElementsByXpath(selector, contextNode, doc);
596 }
597 } else {
598 const query = selector(doc, win, _cplink);
599 if (!Array.isArray(query)) {
600 throw new Error('getAllElements 返回错误类型');
601 } else {
602 return query;
603 }
604 }
605 }
606})();

Callers 1

Calls 2

getAllElementsByCSSFunction · 0.70
getAllElementsByXpathFunction · 0.70

Tested by

no test coverage detected