Youtube download button → ytmp3.la (auto‑download) - (by SuchtiOnTour)

מוסיף כפתור הורדה ליד הירשם ומוריד אוטומטית את ה‑MP3 דרך ytmp3.la

// ==UserScript==
// @name            Youtube download button → ytmp3.la (auto‑download) - (by SuchtiOnTour)
// @name:de         Youtube download button → ytmp3.la (Auto‑Download) - (by SuchtiOnTour)
// @namespace       Violentmonkey Scripts
// @version         1.5.0
// @author          SuchtiOnTour
// @license         MIT
// @match           https://www.youtube.com/watch*
// @match           https://*.youtube.com/*
// @match           https://ytmp3.la/*
// @grant           GM_addStyle
// @run-at          document-idle
// @description     Adds a Download button next to Subscribe and auto‑downloads the MP3 via ytmp3.la
// @description:pt-BR Adiciona um botão Download ao lado de Inscrever‑se e baixa MP3 automaticamente pelo ytmp3.la
// @description:ar  يضيف زر تنزيل بجوار الاشتراك ويحمل MP3 تلقائياً عبر ytmp3.la
// @description:bg  Добавя бутон „Сваляне“ до „Абонирай се“ и автоматично сваля MP3 чрез ytmp3.la
// @description:cs  Přidá tlačítko Stáhnout vedle Odebírat a automaticky stáhne MP3 přes ytmp3.la
// @description:da  Tilføjer en Download‑knap ved siden af Abonner og downloader automatisk MP3 via ytmp3.la
// @description:de  Fügt neben „Abonnieren“ einen Download‑Button ein und lädt die MP3 über ytmp3.la automatisch herunter
// @description:el  Προσθέτει κουμπί Λήψη δίπλα στην Εγγραφή και κατεβάζει αυτόματα το MP3 μέσω ytmp3.la
// @description:eo  Aldonas elŝutan butonon apud Aboni kaj aŭtomate elŝutas MP3 per ytmp3.la
// @description:es  Añade un botón Descargar junto a Suscribirse y descarga automáticamente el MP3 vía ytmp3.la
// @description:fi  Lisää Lataa‑painikkeen Tilaa‑napin viereen ja lataa MP3‑tiedoston automaattisesti ytmp3.la‑palvelusta
// @description:fr  Ajoute un bouton Télécharger à côté de S’abonner et lance automatiquement le téléchargement MP3 via ytmp3.la
// @description:fr-CA Ajoute un bouton Télécharger à côté de S’abonner et télécharge automatiquement le MP3 via ytmp3.la
// @description:he  מוסיף כפתור הורדה ליד הירשם ומוריד אוטומטית את ה‑MP3 דרך ytmp3.la
// @description:hu  Letöltés gombot ad a Feliratkozás mellé és automatikusan letölti az MP3‑at a ytmp3.la‑n
// @description:id  Menambahkan tombol Download di samping Subscribe dan otomatis mengunduh MP3 via ytmp3.la
// @description:it  Aggiunge un pulsante Download accanto a Iscriviti e scarica automaticamente l’MP3 tramite ytmp3.la
// @description:ja  チャンネル登録ボタンの隣にダウンロードボタンを追加し、ytmp3.laで自動的にMP3をダウンロードします
// @description:ko  구독 옆에 다운로드 버튼을 추가하고 ytmp3.la를 통해 MP3를 자동으로 다운로드합니다
// @description:nb  Legger til en Last ned‑knapp ved siden av Abonner og laster automatisk ned MP3 via ytmp3.la
// @description:nl  Voegt een Download‑knop naast Abonneren toe en downloadt automatisch de MP3 via ytmp3.la
// @description:pl  Dodaje przycisk Pobierz obok Subskrybuj i automatycznie pobiera MP3 przez ytmp3.la
// @description:ro  Adaugă un buton de Download lângă Subscribe și descarcă automat MP3‑ul prin ytmp3.la
// @description:ru  Добавляет кнопку «Скачать» рядом с «Подписаться» и автоматически скачивает MP3 через ytmp3.la
// @description:sk  Pridá tlačidlo Stiahnuť vedľa Odoberať a automaticky stiahne MP3 cez ytmp3.la
// @description:sr  Додаје дугме Преузми поред Пријави се и аутоматски преузима MP3 преко ytmp3.la
// @description:sv  Lägger till en Hämta‑knapp bredvid Prenumerera och hämtar automatiskt MP3 via ytmp3.la
// @description:th  เพิ่มปุ่มดาวน์โหลดถัดจาก สมัครสมาชิก และดาวน์โหลด MP3 อัตโนมัติผ่าน ytmp3.la
// @description:tr  Abone Ol’un yanına İndir düğmesi ekler ve MP3’i ytmp3.la ileดาวน์โหลดอัตโนมัติ
// @description:uk  Додає кнопку Завантажити поруч із Підписатися та автоматично завантажує MP3 через ytmp3.la
// @description:ug  Subscribe تەڭلىكى يېنىغا چۈشۈرۈش كۇنۇپكىسى قوشىدۇ، ytmp3.la ئارقىلىق MP3 نى ئاپتوماتىك چۈشۈرۈدۇ
// @description:vi  Thêm nút Tải xuống bên cạnh Đăng ký và tự động tải MP3 qua ytmp3.la
// @description:zh-CN 在订阅旁添加下载按钮,并通过 ytmp3.la 自动下载 MP3
// @description:zh-TW 在訂閱旁新增下載按鈕,並透過 ytmp3.la 自動下載 MP3
// ==/UserScript==

(() => {
/* ---------- YouTube: Button einfügen ---------- */
if (location.host.includes('youtube.com')) {
    const API        = 'https://ytmp3.la/#';
    const BTN_ID     = 'dwnldBtn';
    const TARGET_SEL = '#owner';

    GM_addStyle(`
        #${BTN_ID}{
            background:#0F0F0F;color:#FFF;border:1px solid rgba(255,255,255,.25);
            margin-left:8px;padding:0 16px;border-radius:18px;
            font:500 14px/normal Roboto,Noto,sans-serif;display:inline-flex;align-items:center;
            height:36px;text-decoration:none}
        #${BTN_ID}:hover{background:#3F3F3F;border-color:#3F3F3F}
    `);

    const wait = s=>new Promise(ok=>{
        if (document.querySelector(s)) return ok(document.querySelector(s));
        new MutationObserver((_,o)=>{if(document.querySelector(s)){ok(document.querySelector(s));o.disconnect();}})
            .observe(document.body,{childList:true,subtree:true});
    });

    const id  = () => (/v=([\w-]{11})|shorts\/([\w-]{11})/i.exec(location.href)||[]).slice(1).find(Boolean);
    const url = () => API + id() + '/mp3';

    function add(){
        wait(TARGET_SEL).then(p=>{
            if(!p||document.getElementById(BTN_ID)) return;
            const a = Object.assign(document.createElement('a'),{
                id:BTN_ID,textContent:'Download',href:url(),target:'_blank',rel:'noopener'
            });
            p.appendChild(a);
        });
    }
    function refresh(){ const b=document.getElementById(BTN_ID); if(b) b.href=url(); }

    let done=false;
    const init=()=>{ if(location.pathname==='/watch'&&!done){ add(); done=true; setTimeout(refresh,1200);} };
    window.addEventListener('yt-navigate-finish',()=>{done=false;init();});
    init();
}

/* ---------- ytmp3.la: Auto‑Download ---------- */
if (location.host === 'ytmp3.la') {
    const isDl = el=>{
        if(!el) return false;
        const t=el.textContent.trim().toLowerCase();
        return t==='download' || t.startsWith('download ');
    };
    const click = ()=>{
        const el=[...document.querySelectorAll('a,button')].find(isDl);
        if(el){ el.click(); console.log('[YTMP3] Download‑Button geklickt'); }
        else   setTimeout(click,400);
    };
    click();
}
})();