Last active
January 28, 2022 16:04
-
-
Save thehandsomezebra/01c1ba0e56aaecb3d5bf3b9c1554c9cf to your computer and use it in GitHub Desktop.
get all links from a current page in your browser
This file contains hidden or 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
var x = document.querySelectorAll("a"); | |
var myarray = [] | |
for (var i=0; i<x.length; i++){ | |
var nametext = x[i].textContent; | |
var cleanlink = x[i].href; | |
if (cleanlink.includes('.pdf')) { | |
myarray.push([cleanlink]); | |
} | |
}; | |
function make_table() { | |
var table = '<table><thead><th>Links</th></thead><tbody>'; | |
for (var i=0; i<myarray.length; i++) { | |
table += '<tr><td><a href='+myarray[i]+'>'+myarray[i]+'</a></td></tr>'; | |
}; | |
var w = window.open(""); | |
w.document.write(table); | |
} | |
make_table() |
This file contains hidden or 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
var x = document.querySelectorAll("a"); | |
var myarray = [] | |
for (var i=0; i<x.length; i++){ | |
var nametext = x[i].textContent; | |
var cleantext = nametext.replace(/\s+/g, ' ').trim(); | |
var cleanlink = x[i].href; | |
myarray.push([cleantext,cleanlink]); | |
}; | |
function make_table() { | |
var table = '<table><thead><th>Name</th><th>Links</th></thead><tbody>'; | |
for (var i=0; i<myarray.length; i++) { | |
table += '<tr><td>'+ myarray[i][0] + '</td><td>'+myarray[i][1]+'</td></tr>'; | |
}; | |
var w = window.open(""); | |
w.document.write(table); | |
} | |
make_table() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment