Last active
October 24, 2019 02:05
-
-
Save samkcarlile/596e3182aebf3915f504f55179c62eb4 to your computer and use it in GitHub Desktop.
Get File Links on a Webpage
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
function getURLFileExtension(url) { | |
if (url && url.length > 0) { | |
let results = url.match(/(?:[\d\w]+\.[\d\w]+)(?:\/.+)\.([^/]*)$/); | |
if (results && results.length == 2) { | |
return results[1]; | |
} | |
} | |
return undefined | |
} | |
[...document.querySelectorAll("a")] | |
.map(e => e.href) | |
.filter(href => href && href.length > 1) | |
.map(href => ({ href, ext: getURLFileExtension(href)})) | |
.filter(o => o.ext) | |
.reduce((str, {href}) => str + href + "\n", "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment