I have been creating my first Chrome Extension, and it suppose to do something simple find a specific href and donwload it.
The extension is a Page Action so it is only triggered in the url page that I want, and a using the chrome.download on a specific href set is working.
Here my manifest.json:
{
"name": "HrefDownloader",
"version": "1.0",
"manifest_version": 2,
"description":"Download all specific hrefs",
"background":{
"scripts": ["background.js"],
"persistent": false
},
"icons":
{
"128": "HrefDownloader.png"
},
"page_action":{
"default_title":"Href downloader",
"default_popup": "popup.html"
},
"permissions":[
"downloads","storage","declarativeContent","<all_urls>"
]
}
Background.js:
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'url.domain.com'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
});
and my popup.js:
$(function(){
$('#DownloadAll').click(function(){
chrome.downloads.download({url: 'https://url.domain.com/something/Download/Document/10f7cb46-1dc7-56eb-8bde-9e3f55d6baa2'})
})
})
This is working fine, but what I want is to download all the links that start with "https://url.domain.com/something/Download/Document/"
so I tried to get all the links and then download with a for loop:
$(document).ready(function() {
var links = document.getElementsByTagName("a'href=https://url.domain.com/something/Download/Document/'")
});
$(function(){
$('#DownloadAll').click(function(){
for (var i = 0; i < links.length;i++){
chrome.downloads.download({url: links[i]})
}
})
})
I got an that links is not defined but I have defined it so I am not sure what to do now.
For information I am completly new to JS and jQuery, I have been learning how to make a chrome extension since last thursday.
I do want a solution but I also wants to understand what is wrong and what should I check in order to make it work.
Thank you for reading!
Edit: Corrected i++ missing from the code