mega dl button fix

switches the download buttons and colors the inline button red

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         mega dl button fix
// @version      0.2
// @match        https://mega.nz/*
// @description  switches the download buttons and colors the inline button red
// @grant        none
// @namespace https://greasyfork.org/users/29657
// ==/UserScript==

waitForButton();

function doEverything() {
    msbut = document.getElementsByClassName("with-megasync")[0];
    inbut = document.getElementsByClassName("throught-browser")[0];
    // msbut.style.display = "none";
    msbut.className = msbut.className.replace( /(?:^|\s)red(?!\S)/g , '' );
    inbut.className += " red";
    swapElements(msbut, inbut);
}

function waitForButton() {
    buttons = document.getElementsByClassName("throught-browser").length;
    
    if(buttons > 0) {
        doEverything();
    } else {
        setTimeout(waitForButton, 50);
    }
}

function swapElements(obj1, obj2) {
    // from http://stackoverflow.com/a/10717422/4504269
    var parent2 = obj2.parentNode;
    var next2 = obj2.nextSibling;
    if (next2 === obj1) {
        parent2.insertBefore(obj1, obj2);
    } else {
        obj1.parentNode.insertBefore(obj2, obj1);
        if (next2) {
            parent2.insertBefore(obj1, next2);
        } else {
            parent2.appendChild(obj1);
        }
    }
}