dbr.ee: instant download

creates a direct download button on dbr.ee and clicks it

  1. // ==UserScript==
  2. // @name dbr.ee: instant download
  3. // @namespace mailto:morten.with@gmail.com
  4. // @locale en
  5. // @include *dbr.ee*
  6. // @version 1.4
  7. // @run-at document-start
  8. // @grant none
  9. // @description creates a direct download button on dbr.ee and clicks it
  10. // ==/UserScript==
  11.  
  12. (function()
  13. {
  14. 'use strict';
  15.  
  16. function in_array(needle, haystack)
  17. {
  18. var length = haystack.length;
  19. for(var i = 0; i < length; i++)
  20. {
  21. if(haystack[i] == needle) return true;
  22. }
  23. return false;
  24. }
  25.  
  26. var fileid = window.location.href.split("/").slice(-1)[0];
  27. var ignoreurls =
  28. [
  29. "",
  30. "help",
  31. "dmca",
  32. ];
  33.  
  34. if(!in_array(fileid, ignoreurls) && fileid.length == 4)
  35. {
  36. document.addEventListener("DOMContentLoaded", waitForDLButton);
  37. }
  38.  
  39. function doEverything(btn)
  40. {
  41. var newbtnform = document.createElement("form");
  42. newbtnform.setAttribute("class", "button_to");
  43. newbtnform.setAttribute("method", "get");
  44. newbtnform.setAttribute("action", "/"+fileid+"/d");
  45.  
  46. var newbtnspan = document.createElement("span");
  47. newbtnspan.setAttribute("class", "icon-download");
  48.  
  49. var newbtn = document.createElement("button");
  50. newbtn.setAttribute("class", "btn btn--block");
  51. newbtn.setAttribute("title", "Direct Download");
  52. newbtn.setAttribute("data-disable-with", "Downloading...");
  53. newbtn.setAttribute("type", "submit");
  54. newbtn.innerHTML = "&nbsp;DOWNLOAD";
  55.  
  56. newbtn.insertBefore(newbtnspan, newbtn.childNodes[0]);
  57. newbtnform.appendChild(newbtn);
  58.  
  59. var btnparent = btn.parentElement;
  60. btn.remove();
  61. btnparent.appendChild(newbtnform);
  62.  
  63. newbtnform.submit();
  64. }
  65.  
  66. function waitForDLButton()
  67. {
  68. var spinner = document.getElementsByClassName("spinner");
  69.  
  70. if(spinner.length > 0)
  71. {
  72. doEverything(spinner[0].parentElement);
  73. }
  74. else
  75. {
  76. setTimeout(waitForDLButton, 100);
  77. }
  78. }
  79. })();