WMP播放器

拉起PotPlayer播放原WMP控件视频

目前為 2022-03-08 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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 });
})();