Motherless Download Button

Adds a direct MP4 download button below the video

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Motherless Download Button
// @namespace https://github.com/zzzoiddd
// @version     1.2.1
// @description  Adds a direct MP4 download button below the video
// @author       Neurøid Racoon — Zøid
// @license      MIT
// @match        https://motherless.com/*
// @match        https://*.motherless.com/*
// @grant        GM_addStyle
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    const INIT_KEY = Symbol('mldb_init');

    const safeInit = () => {
        if (unsafeWindow[INIT_KEY]) return;
        unsafeWindow[INIT_KEY] = true;
        init();
    };

    const _push = history.pushState;
    const _replace = history.replaceState;
    history.pushState = function(...a) { _push.apply(this, a); delete unsafeWindow[INIT_KEY]; setTimeout(safeInit, 200); };
    history.replaceState = function(...a) { _replace.apply(this, a); delete unsafeWindow[INIT_KEY]; setTimeout(safeInit, 200); };
    window.addEventListener('popstate', () => { delete unsafeWindow[INIT_KEY]; setTimeout(safeInit, 200); });

    const $ = (s, c = document) => c.querySelector(s);

    const getVideoUrl = () => {
        const v = $('video');
        if (!v) return null;
        return v.currentSrc || v.src || $('video source')?.getAttribute('src') || null;
    };

    const findVideoContainer = () => {
        const selectors = [
            '.video-container',
            '.video-player-container',
            '#media-player',
            '.player-container',
            '.main-video-container',
            '.video-wrap'
        ];
        for (const sel of selectors) {
            const el = $(sel);
            if (el) return el;
        }
        const vid = $('video');
        return vid ? vid.closest('div') : null;
    };

    const triggerDownload = (url) => {
        const a = document.createElement('a');
        a.href = url;
        a.target = '_blank';
        a.rel = 'noopener noreferrer';
        a.download = '';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
    };

    const injectButton = () => {
        const videoUrl = getVideoUrl();
        const container = findVideoContainer();
        if (!videoUrl || !container) return false;
        if ($('.zoid-dl-btn-full')) return true;

        const btn = document.createElement('div');
        btn.className = 'zoid-dl-btn-full';
        btn.innerHTML = `<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg><span>Download Video</span>`;

        const syncWidth = () => {
            const rect = container.getBoundingClientRect();
            btn.style.width = rect.width + 'px';
        };

        btn.addEventListener('click', (e) => {
            e.preventDefault();
            const url = getVideoUrl();
            if (url) triggerDownload(url);
            else alert('Scriptoid\u00B7Z: Video URL not found. Please reload the page.');
        });

        container.after(btn);
        syncWidth();

        const ro = new ResizeObserver(syncWidth);
        ro.observe(container);

        return true;
    };

    const init = () => {
        GM_addStyle(`
            .zoid-dl-btn-full {
                display: flex;
                align-items: center;
                justify-content: center;
                gap: 8px;
                background: #252525;
                color: #ffffff;
                padding: 12px 0;
                margin-top: 5px;
                cursor: pointer;
                font-weight: bold;
                font-size: 14px;
                text-transform: uppercase;
                border-radius: 2px;
                box-sizing: border-box;
                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
                user-select: none;
                transition: background 0.15s;
            }
            .zoid-dl-btn-full:hover { background: #333333; }
            .zoid-dl-btn-full svg { flex-shrink: 0; }
            @media (max-width: 600px) {
                .zoid-dl-btn-full { font-size: 12px; padding: 10px 0; gap: 6px; }
                .zoid-dl-btn-full svg { width: 16px; height: 16px; }
            }
        `);

        if (injectButton()) return;

        const obs = new MutationObserver((_, o) => {
            if (injectButton()) o.disconnect();
        });

        obs.observe(document.body, { childList: true, subtree: true });
        setTimeout(() => obs.disconnect(), 15000);
    };

    safeInit();
})();