Save List of Links from Array to Text File (almost got it working)
HTML
<a href="www.google.com">Google</a>
<a href="www.twitter.com">Twitter</a>
<a href="www.youtube.com">Youtube</a>
JavaScript
(function() {
var links = document.querySelectorAll('a');
var linksArray = [];
// Loop through all links
for (var i = 0; i < links.length; i++) {
// Store links in variable
linksArray.push(links[i]);
// Works fine in console
console.log(linksArray);
}
// Create text document — only saves 1st link in text doc
var textDoc = document.createElement('a');
textDoc.href = 'data:attachment/text,' + encodeURI(linksArray.join('\n'));
textDoc.target = '_blank';
textDoc.download = 'myFile.txt';
textDoc.click();
})();