Last active
December 20, 2015 21:29
-
-
Save AaronO/6198332 to your computer and use it in GitHub Desktop.
Pull links from site to index
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
// Utility function | |
var startsWith = function (str1, str2) { | |
return str1.indexOf(str2) == 0; | |
} | |
// Url of page/domain | |
var baseUrl = "https://friendco.de"; | |
// Utility functions | |
var hrefExtractor = function(idx, el) { return el.href; }; | |
// Check if it belong to baseUrl | |
var belongsToBase = function(idx, url) { | |
return startsWith(url, baseUrl) | |
}; | |
// Slice out baseUrl | |
var relativeLink = function(idx, url) { | |
return url.slice(baseUrl.length); | |
} | |
var links = $("a").map(hrefExtractor).filter(belongsToBase).map(relativeLink).toArray(); | |
console.log(links.join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment