Thunder Harvester

This script will search for thunder and magnet links on every webpage,when found, it shows a button to download them all (by sending them to the clipboard).

  1. // ==UserScript==
  2. // @name Thunder Harvester
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description This script will search for thunder and magnet links on every webpage,when found, it shows a button to download them all (by sending them to the clipboard).
  6. // @author DKing
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var thunder_linktext = '';
  13.  
  14. (function() {
  15. var links = find_links();
  16. if(links) add_button(links);
  17. })();
  18.  
  19. function find_links()
  20. {
  21. var htmltext = document.getElementsByTagName('html')[0].innerHTML;
  22. var regthunder = new RegExp(/thunder:\/\/[A-Za-z0-9=]+(?![A-Za-z0-9=])|magnet:\?[a-zA-Z]{2}(.[12])?=[A-Za-z0-9:\?]+(?![A-Za-z0-9:\?])/, "g");
  23. var links = htmltext.match(regthunder);
  24. return links;
  25. }
  26.  
  27. function add_button(links)
  28. {
  29. thunder_linktext = '';
  30. for(var i = 0;i<links.length;i++){
  31. thunder_linktext = thunder_linktext + links[i] + '\n';
  32. }
  33. var block = document.createElement('div');
  34. block.style.position='fixed';
  35. block.style.top='5%';
  36. block.style.left='90%';
  37. block.style.width='120px';
  38. block.style.height='50px';
  39. block.style.zIndex=9999;
  40. block.innerHTML='<div style="cursor:pointer; text-align: center; border:2px solid;border-radius:5px; border-color: rgba(70,100,255,0.8); background-color: rgba(200,200,200,0.8);"><span style="width:30px; text-align: center;"><b> &#9733; </b>' + links.length + ' Tasks</span><br><span style="width:90px; text-align: center; color: blue;"> <b>&#10010;</b> Thunder</span></div>';
  41. block.onclick = function(){Copy2Clipboard(thunder_linktext);};
  42. document.body.appendChild(block);
  43. }
  44.  
  45.  
  46. function Copy2Clipboard(text){
  47. var id = "mycustom-clipboard-textarea-hidden-id";
  48. var existsTextarea = document.getElementById(id);
  49.  
  50. if(!existsTextarea){
  51. var textarea = document.createElement("textarea");
  52. textarea.id = id;
  53. // Place in top-left corner of screen regardless of scroll position.
  54. textarea.style.position = 'fixed';
  55. textarea.style.top = 0;
  56. textarea.style.left = 0;
  57.  
  58. // Ensure it has a small width and height. Setting to 1px / 1em
  59. // doesn't work as this gives a negative w/h on some browsers.
  60. textarea.style.width = '1px';
  61. textarea.style.height = '1px';
  62.  
  63. // We don't need padding, reducing the size if it does flash render.
  64. textarea.style.padding = 0;
  65.  
  66. // Clean up any borders.
  67. textarea.style.border = 'none';
  68. textarea.style.outline = 'none';
  69. textarea.style.boxShadow = 'none';
  70.  
  71. // Avoid flash of white box if rendered for any reason.
  72. textarea.style.background = 'transparent';
  73. document.querySelector("body").appendChild(textarea);
  74. existsTextarea = document.getElementById(id);
  75. }
  76. existsTextarea.value = text;
  77. existsTextarea.select();
  78.  
  79. try {
  80. var status = document.execCommand('copy');
  81. } catch (err) {
  82. console.log('Unable to copy.');
  83. }
  84. }