-1

I downloaded a bit of books on edge, but sadly the browser stopped showing visited links in purple and i don't want to download duplicate files (edge just renames duplicate files and other download managers just download it then ask you what to do). So i resorted to a javascript code that can ust catch all links in download page of edge and export them to an external file where i will program another script to compare the links in this file with what is open

JS code:

    function findButton() {
  var buttons = document.querySelectorAll('button');
 for (var i = 0; i < buttons.length; i++) {

var elem = buttons[i];
var text = elem.textContent || elem.innerText;
if (text.includes("htt")){}
else {text = 0;}
      return text
  }  
}

var x = findButton();
alert(x);

inspect elements:

<button class="c0124348" id="open_link292" role="link" aria-label="https://onlinelibrary.wiley.com/doi/pdfdirect/10.1002/9780470132586">https://onlinelibrary.wiley.com/doi/pdfdirect/10.1002/9780470132586</button>

the sript returns only the value of first button which is (download list button) = 0.

NOTE:

  1. nothing is static in the attributes and class name of the buttons (classnames and ids change)

  2. if you have a simpler solution to this problem (a download manger that checks if download file is already present in the destination or any other solution) then i would like to try it.

mohamed
  • 231
  • 1
  • 13
  • a notepad on your desk. That would be a far more effective/efficient method than building a single purpose tool that keeps track of what you've downloaded. Note the last one before you walk away, and you know where to start next. – Kevin B Dec 14 '21 at 15:58
  • @KevinB, damage has already been done . I have hundreds of downloads . so, i need to save their links (i am talking about not less than 150-200) automatically – mohamed Dec 14 '21 at 16:22
  • I don't think you do, need to save their links, though. The file manager already has a way of telling you what files exist in the folder you're looking at. – Kevin B Dec 14 '21 at 16:23
  • @KevinB, i didnt make it obvious though. i download many links in a a matter of minutes, so downloads are forming in background it would be extremly hard to keep pressing on download button popups – mohamed Dec 14 '21 at 16:28
  • that doesn't change anything. They're still there, in the folder. – Kevin B Dec 14 '21 at 16:29
  • @KevinB, yes but the manager will rename tem automatically and redownload them or download first then ask. it consumes resources – mohamed Dec 14 '21 at 16:31
  • *"nothing is static in the attributes and class name of the buttons (classnames and ids change)"* that is incorrect, they all have an aria-label with similar values. They all have a role attribute. They all contain a similar text value. – Kevin B Dec 14 '21 at 16:32
  • @KevinB, books are diverse they are not from same site. its just one example – mohamed Dec 14 '21 at 16:33
  • i can guarantee that each site has a similar scenario. – Kevin B Dec 14 '21 at 16:33
  • @KevinB, yes they do but it doesnt matter captureing hrefs, the iner text is actually the link so you just need to capture inner links – mohamed Dec 14 '21 at 16:34
  • Do that then. ;) – Kevin B Dec 14 '21 at 16:35
  • @KevinB, i did that but the function return value of one button only – mohamed Dec 14 '21 at 16:36
  • That's what happens when you build a function that returns one element. – Kevin B Dec 14 '21 at 16:36
  • @KevinB, i now see i forgot to form an array – mohamed Dec 14 '21 at 16:38

1 Answers1

0

i edited the code and now it works fine

    function findButton() {
  var buttons = document.querySelectorAll('button');
             var arr = [];
 for (var i = 0; i < buttons.length; i++) {
     var elem = buttons[i++];
var text = elem.textContent || elem.innerText;
     arr.push(text);
 }
      return arr
}

var x = findButton();
alert(x);
  1. I forgot to form an array as KevinB has pointed out, so i declared arr an empty array

  2. the return statement was placed in wrong line it wan inside the for loop

mohamed
  • 231
  • 1
  • 13