Skip to content

Commit

Permalink
Add shadowRoot Extraction (#85)
Browse files Browse the repository at this point in the history
* Add shadowRoot Extraction

* Remove Title on Bug Template

* Update Issue Template

* Clean Up Extraction
  • Loading branch information
smashedr authored Jul 4, 2024
1 parent 955d779 commit 7491be9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
13 changes: 6 additions & 7 deletions .github/ISSUE_TEMPLATE/0-bug.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
name: "⚠️ Report an Issue"
description: "Something Not Working Right? Please let us know..."
title: "[Bug] "
labels: ["bug"]
assignees:
- smashedr

body:
- type: markdown
attributes:
value: |
All bugs that we can verify will be fixed. Thank you for taking the time to make this report!
- type: input
id: website
validations:
Expand All @@ -34,6 +28,11 @@ body:
validations:
required: true
attributes:
label: Paste Support Information
label: Support Information
description: Open the extension options, scroll to the bottom, click Copy Support Information and paste below.
render: shell

- type: markdown
attributes:
value: |
All issues/bugs that we can verify will be fixed. Thank you for taking the time to make this report!
45 changes: 40 additions & 5 deletions src/js/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,55 @@ function onMessage(message, sender, sendResponse) {
}
}

// /**
// * Extract links
// * @function extractAllLinks
// * @return {Array}
// */
// function extractAllLinks() {
// console.debug('extractAllLinks')
// const links = []
// for (const element of document.links) {
// if (element.href) {
// pushElement(links, element)
// }
// }
// console.debug('links:', links)
// return links
// }

/**
* Extract links
* @function extractAllLinks
* @return {Array}
*/
function extractAllLinks() {
console.debug('extractAllLinks')
const links = findLinks(document)
console.debug('links:', links)
return links
}

/**
* Recursively Find Links from shadowRoot
* @function findLinks
* @param {Document|ShadowRoot} root
* @return {Array}
*/
function findLinks(root) {
console.debug('findLinks:', root)
const links = []
for (const element of document.links) {
if (element.href) {
pushElement(links, element)
}
if (root.querySelectorAll) {
root.querySelectorAll('a').forEach((el) => {
pushElement(links, el)
})
}
console.debug('links:', links)
const roots = Array.from(root.querySelectorAll('*')).filter(
(el) => el.shadowRoot
)
roots.forEach((el) => {
links.push(...findLinks(el.shadowRoot))
})
return links
}

Expand Down

0 comments on commit 7491be9

Please sign in to comment.