Skip to content

Instantly share code, notes, and snippets.

@qinlili23333
Created March 8, 2022 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qinlili23333/e6c7adb01092ecd094c76b7e2021cd1f to your computer and use it in GitHub Desktop.
Save qinlili23333/e6c7adb01092ecd094c76b7e2021cd1f to your computer and use it in GitHub Desktop.
使用potplayer播放wmp控件的视频
// ==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 });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment