网页播放器替换脚本 - 使用 iframe 嵌入自定义播放器
// ==UserScript== // @name 网页播放器替换脚本 // @namespace Violentmonkey Scripts // @version 1.0 // @description 根据播放容器配置替换页面中的播放容器为自定义的 iframe 播放器 // @author Your name // @match :///* // @grant none // ==/UserScript==
(function() { 'use strict';
// 播放容器配置
var playerContainers = [
{
host: 'v.qq.com',
container: '.player__container'
}
];
// 解析列表配置
var videoParseList = [
{'name': '超级播放器', 'url': 'https://www.superplayer.top/player/ec.php?code=qw&if=1&url='}
];
// 检查当前页面所在域名是否符合要求
function checkHost() {
var currentHost = window.location.host;
for (var i = 0; i < playerContainers.length; i++) {
if (currentHost === playerContainers[i].host) {
return true;
}
}
return false;
}
// 替换播放容器
function replaceContainer() {
var containers = document.querySelectorAll(playerContainers[0].container);
for (var i = 0; i < containers.length; i++) {
var container = containers[i];
container.innerHTML = '<div style="width:100%;height:100%;z-index:999999;">' +
'<iframe id="iframe-player" src="' + videoParseList[0].url + window.location.href + '" ' +
'style="border:none;" allowfullscreen="true" width="100%" height="100%"></iframe>' +
'</div>';
}
}
// 监听地址变化事件
window.addEventListener('hashchange', function() {
if (checkHost()) {
replaceContainer();
}
});
// 初始加载时替换播放容器
if (checkHost()) {
replaceContainer();
}
})();
原文地址: https://www.cveoy.top/t/topic/qg5h 著作权归作者所有。请勿转载和采集!