mega dl button fix

switches the download buttons and colors the inline button red

  1. // ==UserScript==
  2. // @name mega dl button fix
  3. // @version 0.2
  4. // @match https://mega.nz/*
  5. // @description switches the download buttons and colors the inline button red
  6. // @grant none
  7. // @namespace https://greasyfork.org/users/29657
  8. // ==/UserScript==
  9.  
  10. waitForButton();
  11.  
  12. function doEverything() {
  13. msbut = document.getElementsByClassName("with-megasync")[0];
  14. inbut = document.getElementsByClassName("throught-browser")[0];
  15. // msbut.style.display = "none";
  16. msbut.className = msbut.className.replace( /(?:^|\s)red(?!\S)/g , '' );
  17. inbut.className += " red";
  18. swapElements(msbut, inbut);
  19. }
  20.  
  21. function waitForButton() {
  22. buttons = document.getElementsByClassName("throught-browser").length;
  23. if(buttons > 0) {
  24. doEverything();
  25. } else {
  26. setTimeout(waitForButton, 50);
  27. }
  28. }
  29.  
  30. function swapElements(obj1, obj2) {
  31. // from http://stackoverflow.com/a/10717422/4504269
  32. var parent2 = obj2.parentNode;
  33. var next2 = obj2.nextSibling;
  34. if (next2 === obj1) {
  35. parent2.insertBefore(obj1, obj2);
  36. } else {
  37. obj1.parentNode.insertBefore(obj2, obj1);
  38. if (next2) {
  39. parent2.insertBefore(obj1, next2);
  40. } else {
  41. parent2.appendChild(obj1);
  42. }
  43. }
  44. }