只显示 PandaLive 网站上的 19+ 直播
当前为
// ==UserScript==
// @name PandaLive 19+ Filter
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 只显示 PandaLive 网站上的 19+ 直播
// @author skktck
// @match https://www.pandalive.co.kr/*
// @match https://pandalive.co.kr/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 主函数,用于过滤直播
function filterLiveStreams() {
console.log("PandaLive 19+ 过滤器已启动");
// 找到所有直播卡片的父容器元素 (li)
const liveCardContainers = document.querySelectorAll('li[data-sentry-component="BroadcastUserItem"], .card, .live-card, [class*="card"]');
liveCardContainers.forEach(container => {
// 检查卡片是否包含19+图标 (寻找包含 ico_19.png 的图片元素)
const has19Plus = container.querySelector('img[src*="ico_19.png"]');
if (!has19Plus) {
// 如果不是19+直播,完全隐藏该卡片容器
container.style.display = 'none';
} else {
// 确保19+直播是可见的
container.style.display = '';
}
});
}
// 创建一个观察器来处理动态加载的内容
function createObserver() {
// 观察整个文档变化
const observer = new MutationObserver((mutations) => {
let shouldFilter = false;
// 检查是否有相关变化
mutations.forEach(mutation => {
if (mutation.addedNodes.length > 0 ||
(mutation.type === 'attributes' && mutation.target.tagName === 'IMG') ||
(mutation.type === 'childList')) {
shouldFilter = true;
}
});
// 如果有相关变化,执行过滤
if (shouldFilter) {
filterLiveStreams();
}
});
// 配置观察器选项
const config = {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['src', 'class', 'style']
};
// 开始观察
observer.observe(document.body, config);
return observer;
}
// 添加控制按钮,可以临时开关过滤功能
function addControlButton() {
const button = document.createElement('button');
button.textContent = '19+ 过滤: 开启';
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = '9999';
button.style.padding = '5px 10px';
button.style.backgroundColor = '#ff4757';
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
let filterEnabled = true;
button.addEventListener('click', () => {
filterEnabled = !filterEnabled;
button.textContent = filterEnabled ? '19+ 过滤: 开启' : '19+ 过滤: 关闭';
button.style.backgroundColor = filterEnabled ? '#ff4757' : '#7f8fa6';
// 获取所有卡片容器元素并恢复/过滤它们
const allContainers = document.querySelectorAll('li[data-sentry-component="BroadcastUserItem"], .card, .live-card, [class*="card"]');
allContainers.forEach(container => {
if (filterEnabled) {
// 过滤模式
const has19Plus = container.querySelector('img[src*="ico_19.png"]');
container.style.display = has19Plus ? '' : 'none';
} else {
// 显示所有
container.style.display = '';
}
});
});
document.body.appendChild(button);
}
// 初始化函数
function init() {
// 添加CSS样式确保隐藏的元素不占用空间
const style = document.createElement('style');
style.textContent = `
li[data-sentry-component="BroadcastUserItem"][style*="display: none"],
.card[style*="display: none"],
.live-card[style*="display: none"],
[class*="card"][style*="display: none"] {
margin: 0 !important;
padding: 0 !important;
height: 0 !important;
width: 0 !important;
overflow: hidden !important;
}
`;
document.head.appendChild(style);
// 首次加载时执行过滤
setTimeout(filterLiveStreams, 1000);
// 创建观察器处理动态内容
const observer = createObserver();
// 添加控制按钮
addControlButton();
// 每2秒再次检查一次,以防有些内容没有被观察器捕获
setInterval(filterLiveStreams, 2000);
}
// 页面加载完成后启动脚本
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();