Motherless Download Button

Adds a direct MP4 download button below the video

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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();
})();