WMP播放器

拉起PotPlayer播放原WMP控件视频

当前为 2022-03-08 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WMP播放器
// @namespace    https://qinlili.bid/
// @version      0.1
// @description  拉起PotPlayer播放原WMP控件视频
// @author       琴梨梨
// @match        *://*/*
// @grant        none
// @run-at       document-body
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    console.log(document.documentElement)
    const getUrl=obj=>{
        let url;
        [].forEach.call(obj.getElementsByTagName("param"),param=>{
            if(param.getAttribute("name")=="url"){
                url=param.getAttribute("value")
            }
        })
        return url;
    }
    var observer = new MutationObserver(function(){
        if(document.getElementsByTagName("object").length){
            [].forEach.call(document.getElementsByTagName("object"),obj=>{
                if(obj.getElementsByTagName("embed")[0].getAttribute("type")=="application/x-mplayer2"){
                    let embed=obj.getElementsByTagName("embed")[0];
                    let videoUrl=embed.getAttribute("url")||getUrl(obj)
                    console.log("获取视频地址成功!"+videoUrl);
                    let videoCover=document.createElement("img");
                    videoCover.style="object-fit:contain"
                    videoCover.src="https://pic3.zhimg.com/80/v2-5804288d666a3443ea8d01828ad3782a.png"
                    videoCover.height=embed.height;
                    videoCover.width=embed.width;
                    videoCover.addEventListener("click",()=>{
                        let success=false;
                        const processFocus=()=>{
                            success=true;
                            console.log("拉起PotPlayer成功")
                            window.removeEventListener('blur', processFocus);
                        }
                        window.addEventListener('blur', processFocus);
                        location.href="potplayer://"+videoUrl;
                        setTimeout(()=>{
                            if(!success){
                                console.log("拉起PotPlayer失败")
                                window.removeEventListener('blur', processFocus);
                                location.href="https://t1.daumcdn.net/potplayer/PotPlayer/Version/Latest/PotPlayerSetup64.exe"
                            }
                        },500)
                    })
                    obj.removeChild(embed);
                    obj.appendChild(videoCover)
                }
            })
        }
    });
    observer.observe(document.documentElement, { childList: true });
})();