Created
February 19, 2022 14:55
-
-
Save huffmanks/4ee39b0534f0b9f74eda6767635a045c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @title Get all links on a page | |
* @desc Creates table of all links | |
*/ | |
const x = document.querySelectorAll('a') | |
let myarray = [] | |
for (let i = 0; i < x.length; i++) { | |
const nameText = x[i].textContent | |
const cleanText = nameText.replace(/\s+/g, ' ').trim() | |
const cleanLink = x[i].href | |
myarray.push([cleanText, cleanLink]) | |
} | |
function makeTable() { | |
let table = '<table><thead><th>Name</th><th>Links</th></thead><tbody>' | |
for (let i = 0; i < myarray.length; i++) { | |
table += '<tr><td>' + myarray[i][0] + '</td><td>' + myarray[i][1] + '</td></tr>' | |
} | |
const w = window.open('') | |
w.document.write(table) | |
} | |
makeTable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment