M3u8&mp4 Detect

try to take over the world!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         M3u8&mp4 Detect
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @run-at       document-start
// @match        http*://*/*
// @grant        unsafeWindow
// @grant        GM_setClipboard
// @grant        GM_notification
// @grant        GM_log
// @grant        GM_registerMenuCommand
// @grant        GM_openInTab
// ==/UserScript==

let menu_id = {};
function handler_m3u8(url){
    if(menu_id[url] == undefined){
        let idx = Object.keys(menu_id).length+1;
        let _id = GM_registerMenuCommand(`[${idx}] m3u8 open and copy`, function(){
            GM_openInTab(url);
            let out = document.title.replace(/\||<|>|\?|\*|:|\/|\\|"|\n/g, ' ');
            let cmd = `ffmpeg -i "${url}" -vcodec copy -acodec copy -absf aac_adtstoasc "${out}.mp4"\n`;
            GM_setClipboard(cmd);
        });
        GM_registerMenuCommand(`[${idx}] copy command`, function(){
            let out = document.title.replace(/\||<|>|\?|\*|:|\/|\\|"|\n/g, ' ');
            let cmd = `ffmpeg -i "${url}" -vcodec copy -acodec copy -absf aac_adtstoasc "${out}.mp4"\n`;
            GM_setClipboard(cmd);
        });

        menu_id[url] = _id;
    }
}

function handler_mp4(url){
    if(menu_id[url] == undefined){
        let idx = Object.keys(menu_id).length+1;
        let _id = GM_registerMenuCommand(`[${idx}] mp4 open`, function(){
            GM_openInTab(url);
            GM_setClipboard(url);
        });
        GM_registerMenuCommand(`[${idx}] mp4 open`, function(){
            let out = document.title.replace(/\||<|>|\?|\*|:|\/|\\|"|\n/g, ' ');
            GM_download(url, `${out}.mp4`);
        });
        menu_id[url] = _id;
    }
}

(function(open) {
    XMLHttpRequest.prototype.open = function() {
        this.addEventListener("readystatechange", function() {
            //console.log(this.readyState);
        }, false);
        let url = arguments[1];
        if(/http.*\.m3u8.*/.test(url)){
            GM_log(url);
            GM_notification({
                'text': url,
                'title': "Got m3u8 url ",
                'timeout': 2000,
            });

            handler_m3u8(url);
        }
        else if(/http.*\.mp4.*/.test(url)){
            GM_log(url);
            GM_notification({
                'text': url,
                'title': "Got mp4 url ",
                'timeout': 2000,
            });
            handler_m3u8(url);
        }
        open.apply(this, arguments);
    };
})(XMLHttpRequest.prototype.open);