Last active
February 21, 2023 09:41
-
-
Save asdf8601/5b5fcf9eed3443227bcd00fa8c09fae5 to your computer and use it in GitHub Desktop.
Find all links with csv in the string
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 extension = prompt("choose an extension? (csv, xls, xlsx, txt, json, xml, shp, zip)"); | |
var div = document.createElement("div"); | |
div.innerHTML = ` | |
<h1>All ${extension} links</h1> | |
<button id='findAllLinkBut${extension}'>Find all ${extension} links</button> | |
<details><summary>Click to expand</summary> | |
<div id='listUrlExtension${extension}'></div> | |
</details> | |
`; | |
document.body.appendChild(div); | |
div = document.getElementById(`listUrlExtension${extension}`) | |
ol = document.createElement("ol"); | |
div.appendChild(ol); | |
// Asignar un controlador de eventos al botón | |
button = document.getElementById(`findAllLinkBut${extension}`) | |
button.addEventListener("click", function() { | |
var links = document.getElementsByTagName("a"); | |
var host = window.location.host; | |
for (var i = 0; i < links.length; i++) { | |
var link = links[i]; | |
// if link contains extension and is not empty | |
if (link.getAttribute("aria-label") && link.getAttribute("aria-label").match(extension)) { | |
var csvUrl = host + link.getAttribute("href"); | |
a = document.createElement("a"); | |
a.href = csvUrl; | |
a.text = csvUrl; | |
li = document.createElement("li"); | |
li.appendChild(a); | |
ol.appendChild(li); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment