Pornhub视频下载

Pornhub视频下载与链接显示

Från och med 2023-06-05. Se den senaste versionen.

// ==UserScript==
// @name         Pornhub视频下载
// @name:en      Pornhub website video download
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Pornhub视频下载与链接显示
// @description:en Pornhub video download and link display
// @author       geigei717
// @license      MIT
// @match        https://*.pornhub.com/view_video.php?viewkey=*
// @icon         https://img-blog.csdnimg.cn/20181221195058594.gif
// @grant        unsafeWindow
// @require      https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js
// ==/UserScript==

(function() {
    var set = setInterval(function(){
        url()
    },100);

    function url(){
        if(media_5!=undefined&&media_5!==""&&media_5!=null){
            stopSet()
            $(".video-actions-menu").after('<div class="myporhub" style="color: red;font-size: 13px;"><div class="mp4Url">视频链接:<textarea style="width: 90%;height:50px;background-color: black;color: white;padding: 0 5px; margin-left: 65px;margin-top: -15px;"  onclick="this.focus();this.select()" readonly="readOnly"></textarea></div><div class="mp4Donwload" style="height: 40px;line-height: 40px;" >视频下载:<div  style="width: 90%;display: -webkit-flex;display: flex;-webkit-justify-content: space-around;justify-content: space-around;margin-top: -40px;margin-left: 10%;" ></div></div>')
            $.getJSON(media_5, function(data){
                for(let i=0;i<data.length;i++){
                    var s = data[i]
                    if(s.defaultQuality==true){
                        $(".mp4Url").children("textarea").val(s.videoUrl)
                    }
                    if(s.format="mp4"){
                        $(".mp4Donwload>div").append('<input type="button" style="width: 15%;height: 40px;border-radius: 7px;border: none;background-color: #048011;color: white;text-align: center;cursor: pointer;" onclick="downloadUrlFile(\''+s.videoUrl+'\',this)" class="'+s.quality+'p" value="'+s.quality+'p" >')
                    }else{
                        $(".mp4Donwload>div").append('<input type="button" style="width: 15%;height: 40px;border-radius: 7px;border: none;background-color: #7d7e85;color: white;text-align: center;" data-src="'+s.videoUrl+'" class="'+s.quality+'p" title="非MP4格式,暂不能下载" disabled value="'+s.quality+'p" >')
                    }
                }
            });
        }
    }

    function stopSet(){
        clearInterval(set);
    }

     /**
     * 获取页面文件名
     * @param url 文件url
     */
    unsafeWindow.downloadUrlFile = function (url,obj){
        var th = $(obj);
        th.val("下载中:0%")
        th.attr("disabled", '')
        url= url.replace(/\\/g, '/');
        var xhr = new XMLHttpRequest;
        xhr.open('get', url);
        xhr.responseType = 'arraybuffer';
        xhr.onprogress = (event) => {
            if (event.lengthComputable) {
                var loaded = parseInt(event.loaded / event.total * 100);
                if(loaded==100){
                    th.val("下载完成")
                    th.removeAttr("disabled")
                }else{
                    th.val("下载中:"+loaded+"%")
                }
            }
        }
        xhr.onload = function () {
            var link = document.createElement('a');
            link.href = window.URL.createObjectURL(new Blob([xhr.response]));
            link.download = $(".inlineFree").text()+".mp4";
            link.click();
            link.remove();
        };
        xhr.onerror = () => {
            th.val("下载失败,请重试")
            th.removeAttr("disabled")
        }
        xhr.send();
    }
})();