Motherless Download Button

Adds a direct MP4 download button below the video

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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