Mp4Hydra Movie/Video Downloader

Adds a movie download button to the mp4hydra.org video player. Clicking the button will start the download of the mp4 video file.

< Mp4Hydra Movie/Video Downloaderについてのフィードバック

レート:良 – スクリプトは良好に動作する

§
投稿日: 2024/01/10
編集日: 2024/01/10

Your code isn't working, but I was able to fix it. Here is the corrected code:

// ==UserScript== // @name Mp4Hydra Movie/Video Downloader // @namespace https://greasyfork.org/ // @version 1.13 // @description Adds a movie download button to the mp4hydra.org video player. Clicking the button will start the download of the mp4 video file. // @author paleocode // @match https://mp4hydra.org/movie/* // @icon https://mp4hydra.org/favicon-32x32.png // @license MIT // @unwrap // @downloadURL https://update.greasyfork.org/scripts/484039/Mp4Hydra%20MovieVideo%20Downloader.user.js // @updateURL https://update.greasyfork.org/scripts/484039/Mp4Hydra%20MovieVideo%20Downloader.meta.js // ==/UserScript==

(function () { if (document.title === 'Movie Not Found | Mp4Hydra.org') { return; }

function getVideoSrc() {
    var player = document.querySelector('video'); // Assuming the video player is a <video> element
    if (player) {
        var src = player.src;
        console.log("Source: " + src);
        return src;
    }
    return null;
}

var button = Object.assign(document.createElement('button'), {
    innerHTML: 'Download',
    title: 'Download Movie',
    style: 'display: inline-block; margin: 0 0 0 10px; color: #000;',
    onclick: function () {
        var vidSrc = getVideoSrc();
        if (vidSrc) {
            var link = document.createElement("a");
            link.href = vidSrc + '?dl=dl';
            link.setAttribute('download', 'video.mp4'); // Set a default filename
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
    }
});

const interval = setInterval(function () {
    var vcount = document.querySelector('#vcount > small');
    if (!vcount || vcount.innerText === "---") return;

    clearInterval(interval);
    var videoSrc = getVideoSrc();
    if (videoSrc) {
        document.querySelector('#vbar').appendChild(button);
    }
}, 100);

})();

Fixed:

Added a check to ensure the video player element (<video>) is properly obtained.

Improved the naming and scoping of variables (vidSrc -> videoSrc for clarity).

Set the download attribute for the created <a> element to suggest a default filename for the downloaded video.

hope this helps.

paleocode作者
§
投稿日: 2024/01/10

Thanks, I will implement these changes soon. I should have tested the previous code on more browsers. Your improvements also gets the new source if the user changes video server, which is much better.

返信を投稿

返信を投稿するにはログインしてください。