Greasy Fork is available in English.

音视频通用下载器

下载所有网站上的音乐、视频。单击页面最右边的《 来打开捕获列表,双击捕获列表来关闭它。

Fra 2019-07-02 19:32:52 UTC. Se den seneste versjonen.

// ==UserScript==
// @name         音视频通用下载器
// @version      1.1
// @description  下载所有网站上的音乐、视频。单击页面最右边的《 来打开捕获列表,双击捕获列表来关闭它。
// @author       Sam0230
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license      GPL-3.0-or-later
// @namespace    https://greasyfork.org/users/207000
// ==/UserScript==

(function () {
    'use strict';
    window.MediaSource = undefined;
    delete window.MediaSource;
    if (document.contentType.indexOf("audio") == 0 || document.contentType.indexOf("video") == 0) {
        var link = document.createElement("a");
        document.body.appendChild(link);
        function hide_1() {
            link.style.backgroundColor = "rgba(255, 255, 255, 0.3)";
            link.style.color = "rgba(255, 255, 255, 0.5)";
        }
        function show_1() {
            link.style.backgroundColor = "rgba(255, 255, 255, 0.5)";
            link.style.color = "rgba(255, 255, 255, 1)";
        }
        link.style.border = "none";
        link.style.zIndex = 99999999;
        link.style.height = "31px";
        link.style.width = "20px";
        link.style.position = "fixed";
        link.style.right = "0";
        link.style.top = "50%";
        link.style.margin = "-15px 0 0 0";
        link.style.backgroundColor = "rgba(255, 255, 255, 0.3)";
        link.style.transition = "all 0.3s linear";
        link.style.cursor = "pointer";
        link.style.lineHeight = "150%";
        link.style.color = "rgba(255, 255, 255, 0.5)";
        link.style.fontSize = "20px";
        link.style.fontFamily = "Microsoft YaHei,Microsoft YaHei UI,Microsoft JhengHei,Microsoft JhengHei UI,Segoe UI,Lucida Grande,Helvetica,Arial,Noto Sans CJK SC,Droid Sans Fallback,Noto Sans Mono CJK SC,FreeSans,Arimo,Droid Sans,Hiragino Sans GB,Hiragino Sans GB W3,FontAwesome,PingFang SC,Source Han Sans CN,Wenquanyi Micro Hei,WenQuanYi Zen Hei,sans-serif";
        link.style.textDecoration = "none";
        link.style.transition = "all 0.3s linear";
        link.onselectstart = function () {
            return false;
        };
        link.onmousedown = function () {
            return false;
        };
        link.onmouseup = function () {
            return false;
        };
        link.onmouseover = show_1;
        link.onmouseout = hide_1;
        link.href = location.href;
        link.download = "";
        link.innerHTML = "\u2193";
        return undefined;
    }
    function getRandStr(chs, len) {
        var str = '';
        while(len--) {
            str += chs[parseInt(Math.random() * chs.length)];
        }
        return str;
    }
    function process(outerHTML) {
        var i, result = "";
        while (outerHTML.indexOf("src=\"") != -1) {
            i = outerHTML.indexOf("src=\"") + 5;
            while (outerHTML[i] != '"' && i < outerHTML.length) {
                result += outerHTML[i];
                ++ i;
            }
            if (i < outerHTML.length) {
                result += "\r\n";
            }
            outerHTML = outerHTML.replace("src=\"", "");
        }
        return result;
    }
    (function () {
        var playOriginal = HTMLAudioElement.prototype.play;
        function play() {
            console.log(this);
            if (this.src) {
                window.top.postMessage(Array("audioVideoCapturer", this.src), '*');
            } else {
                window.top.postMessage(Array("audioVideoCapturer", process(this.outerHTML)), '*');
            }
            this.play = playOriginal;
            var result = this.play();
            this.play = play;
            return result;
        }
        HTMLAudioElement.prototype.play = play;
        HTMLAudioElement.prototype.play.toString = function () {
            return "function play() { [native code] }";
        };
    })();
    (function () {
        var playOriginal = HTMLVideoElement.prototype.play;
        function play() {
            if (this.src) {
                window.top.postMessage(Array("audioVideoCapturer", this.src), '*');
            } else {
                window.top.postMessage(Array("audioVideoCapturer", process(this.outerHTML)), '*');
            }
            this.play = playOriginal;
            var result = this.play();
            this.play = play;
            return result;
        }
        HTMLVideoElement.prototype.play = play;
        HTMLVideoElement.prototype.play.toString = function () {
            return "function play() { [native code] }";
        };
    })();
    var lastBackquote=0, backquoteNum=1, iframe2, forceEnableIntervalID;
    function forceEnable() {
        if (document.body) {
            forceEnableIntervalID = setInterval(function() {
                document.body.onkeydown = function(event) {
                    if (event.key == "`") {
                        var time = (new Date()).valueOf();
                        if (time - lastBackquote <= 5000) {
                            backquoteNum++;
                            if (backquoteNum == 100) {
                                clearInterval(forceEnableIntervalID);
                                document.body.onkeydown = undefined;
                                alert("AudioVideoCapturer is enabled by force!");
                                window.top.postMessage("audioVideoCapturerShow", '*');
                            }
                        } else {
                            lastBackquote = time;
                            backquoteNum = 0;
                        }
                    } else {
                        lastBackquote = 0;
                    }
                }
            }, 100);
        } else {
            setTimeout(forceEnable, 100);
        }
    }
    forceEnable();
    function showUI() {
        if (document.body) {
            function hide_1() {
                iframe.style.backgroundColor = "rgba(0, 0, 0, 0.1)";
                iframe.contentDocument.body.style.color = "rgba(255, 255, 255, 0.4)";
            }
            function show_1() {
                iframe.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
                iframe.contentDocument.body.style.color = "rgba(255, 255, 255, 0.8)";
            }
            function show_2_hide_1() {
                iframe2.style.transform = "translate(-300px, 0)";
                iframe.contentDocument.body.onmousemove = undefined;
                iframe.contentDocument.body.onmouseout = undefined;
                iframe.contentDocument.body.onmouseover = undefined;
                setTimeout(function() {
                    iframe.style.backgroundColor = "rgba(0, 0, 0, 0)";
                    iframe.contentDocument.body.style.color = "rgba(255, 255, 255, 0)";
                }, 50);
            }
            function show_1_hide_2() {
                iframe2.style.transform = "none";
                iframe.contentDocument.body.onmousemove = show_1;
                iframe.contentDocument.body.onmouseover = show_1;
                iframe.contentDocument.body.onmouseout = hide_1;
                hide_1();
            }
            var iframe = document.createElement("iframe"); //to cope with different CSS Style, DOCTYPE
            iframe.style.border = "none";
            iframe.style.zIndex = 99999999;
            iframe.style.height = "31px";
            iframe.style.width = "23px";
            iframe.style.position = "fixed";
            iframe.style.right = "0";
            iframe.style.top = "50%";
            iframe.style.margin = "-15px 0 0 0";
            iframe.style.backgroundColor = "rgba(0, 0, 0, 0.1)";
            iframe.style.transition = "all 0.3s linear";
            document.body.appendChild(iframe);
            setTimeout(function() {
                iframe.contentDocument.body.style.cursor = "pointer";
                iframe.contentDocument.body.style.margin = 0;
                iframe.contentDocument.body.style.lineHeight = "150%";
                iframe.contentDocument.body.style.color = "rgba(255, 255, 255, 0.4)";
                iframe.contentDocument.body.style.fontSize = "20px";
                iframe.contentDocument.body.style.fontFamily = "Microsoft YaHei,Microsoft YaHei UI,Microsoft JhengHei,Microsoft JhengHei UI,Segoe UI,Lucida Grande,Helvetica,Arial,Noto Sans CJK SC,Droid Sans Fallback,Noto Sans Mono CJK SC,FreeSans,Arimo,Droid Sans,Hiragino Sans GB,Hiragino Sans GB W3,FontAwesome,PingFang SC,Source Han Sans CN,Wenquanyi Micro Hei,WenQuanYi Zen Hei,sans-serif";
                iframe.contentDocument.body.style.transition = "all 0.3s linear";
                setTimeout(function() {
                    iframe.contentDocument.body.innerHTML = "\u300a";
                }, 500);
                iframe.contentDocument.body.onclick = show_2_hide_1;
                iframe.contentDocument.body.onmouseover = show_1;
                iframe.contentDocument.body.onmouseout = hide_1;
                iframe.contentDocument.body.onselectstart = function () {
                    return false;
                };
                iframe.contentDocument.body.onmousedown = function () {
                    return false;
                };
                iframe.contentDocument.body.onmouseup = function () {
                    return false;
                };
            }, 100);
            iframe2.style.border = "none";
            iframe2.style.border = "none";
            iframe2.style.zIndex = 99999999;
            iframe2.style.height = "100%";
            iframe2.style.width = "300px";
            iframe2.style.position = "fixed";
            iframe2.style.left = "100%";
            iframe2.style.top = "0";
            iframe2.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
            iframe2.style.transition = "all 0.3s";
            document.body.appendChild(iframe2);
            setTimeout(function() {
                iframe2.contentDocument.body.style.whiteSpace = "pre";
                iframe2.contentDocument.body.style.color = "#fff";
                iframe2.contentDocument.body.style.lineHeight = "120%";
                iframe2.contentDocument.body.style.fontSize = "0.8em";
                iframe2.contentDocument.body.style.fontFamily = "Microsoft YaHei,Microsoft YaHei UI,Microsoft JhengHei,Microsoft JhengHei UI,Segoe UI,Lucida Grande,Helvetica,Arial,Noto Sans CJK SC,Droid Sans Fallback,Noto Sans Mono CJK SC,FreeSans,Arimo,Droid Sans,Hiragino Sans GB,Hiragino Sans GB W3,FontAwesome,PingFang SC,Source Han Sans CN,Wenquanyi Micro Hei,WenQuanYi Zen Hei,sans-serif";
                var clickTime;
                iframe2.contentDocument.onclick = function() {
                    var time = (new Date()).valueOf();
                    if (time - clickTime <= 400) {
                        show_1_hide_2();
                        clickTime = 0;
                    } else {
                        clickTime = time;
                    }
                };
            }, 100);
        } else {
            setTimeout(showUI, 100);
        }
    }
    var show = false;
    if (window.top == window) {
        window.addEventListener('message', function(event) {
            if (event.data == "audioVideoCapturerShow" && show == false) {
                show = true;
                iframe2 = document.createElement("iframe");
                window.addEventListener('message', function(event) {
                    if (event.data[0] == "audioVideoCapturer") {
                        var id = getRandStr("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", 100);
                        // Some website blocks an empty referer, so don't use <a href="XXX">XXX</a>.
                        iframe2.contentDocument.body.innerHTML += "<a id=\"" + id + "\" style=\"text-decoration: underline; cursor: pointer;\">" + event.data[1] + "</a>\r\n";
                        iframe2.contentDocument.getElementById(id).onclick = function() {
                            var link = document.createElement("a");
                            link.href = event.data[1];
                            link.click();
                            setTimeout(function() {
                                location.href = event.data[1];
                            }, 200);
                        };
                    }
                });
                showUI();
            }
        });
    }
    if (location.href.toLocaleLowerCase().indexOf("play") != -1 || location.href.toLocaleLowerCase().indexOf("sing") != -1 || location.href.toLocaleLowerCase().indexOf("song") != -1 || location.href.toLocaleLowerCase().indexOf("album") != -1 || location.href.toLocaleLowerCase().indexOf("audio") != -1 || location.href.toLocaleLowerCase().indexOf("music") != -1 || location.href.toLocaleLowerCase().indexOf("yinyue") != -1 || location.href.toLocaleLowerCase().indexOf("video") != -1 || location.href.toLocaleLowerCase().indexOf("movie") != -1 || location.href.toLocaleLowerCase().indexOf("film") != -1 || location.href.toLocaleLowerCase().indexOf("watch") != -1 || location.href.toLocaleLowerCase().indexOf("dianying") != -1 || location.href.toLocaleUpperCase().indexOf("%E6%AD%8C") != -1 || location.href.toLocaleUpperCase().indexOf("%E4%B9%90") != -1 || location.href.toLocaleUpperCase().indexOf("%E6%9B%B2") != -1 || location.href.toLocaleUpperCase().indexOf("%E5%BD%B1") != -1 || location.href.toLocaleUpperCase().indexOf("%E5%89%A7") != -1) {
        window.top.postMessage("audioVideoCapturerShow", '*');
    }
})();