mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
commit
93f6afa869
1
registry/dist/components/style/clear-home.js
vendored
Normal file
1
registry/dist/components/style/clear-home.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(e,a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define([],a):"object"==typeof exports?exports["style/clear-home"]=a():e["style/clear-home"]=a()}(globalThis,(()=>(()=>{"use strict";var e={d:(a,l)=>{for(var t in l)e.o(l,t)&&!e.o(a,t)&&Object.defineProperty(a,t,{enumerable:!0,get:l[t]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a)},a={};e.d(a,{component:()=>c});const l=coreApis.componentApis.define,t=coreApis.settings,s=[];let d=!1,o=!0;const i=(0,l.defineOptionsMetadata)({广告:{displayName:"广告",defaultValue:!0},番剧:{displayName:"番剧",defaultValue:!0},电影:{displayName:"电影",defaultValue:!0},国创:{displayName:"国创",defaultValue:!0},电视剧:{displayName:"电视剧",defaultValue:!0},综艺:{displayName:"综艺",defaultValue:!0},纪录片:{displayName:"纪录片",defaultValue:!0},动画:{displayName:"动画",defaultValue:!0},游戏:{displayName:"游戏",defaultValue:!0},鬼畜:{displayName:"鬼畜",defaultValue:!0},音乐:{displayName:"音乐",defaultValue:!0},舞蹈:{displayName:"舞蹈",defaultValue:!0},影视:{displayName:"影视",defaultValue:!0},娱乐:{displayName:"娱乐",defaultValue:!0},知识:{displayName:"知识",defaultValue:!0},科技:{displayName:"科技",defaultValue:!0},资讯:{displayName:"资讯",defaultValue:!0},美食:{displayName:"美食",defaultValue:!0},生活:{displayName:"生活",defaultValue:!0},汽车:{displayName:"汽车",defaultValue:!0},时尚:{displayName:"时尚",defaultValue:!0},运动:{displayName:"运动",defaultValue:!0},动物圈:{displayName:"动物圈",defaultValue:!0},VLOG:{displayName:"VLOG",defaultValue:!0},搞笑:{displayName:"搞笑",defaultValue:!0},单机游戏:{displayName:"单机游戏",defaultValue:!0},虚拟UP主:{displayName:"虚拟UP主",defaultValue:!0},公益:{displayName:"公益",defaultValue:!0},公开课:{displayName:"公开课",defaultValue:!0},专栏:{displayName:"专栏",defaultValue:!0},直播:{displayName:"直播",defaultValue:!0},赛事:{displayName:"赛事",defaultValue:!0},活动:{displayName:"活动",defaultValue:!0},课堂:{displayName:"课堂",defaultValue:!0},社区中心:{displayName:"社区中心",defaultValue:!0},新歌热榜:{displayName:"新歌热榜",defaultValue:!0},漫画:{displayName:"漫画",defaultValue:!0}});function u(e){console.log(e);for(const a of e)if(a.classList)if(a.classList.contains("floor-single-card")){const e=a.querySelector(".badge").textContent;e&&s.includes(e)&&(a.remove(),console.log("remove",e))}else a.classList.contains("bili-live-card")?d&&(a.remove(),console.log("remove live")):(a.classList.contains("bili-video-card")||a.classList.contains("feed-card"))&&o&&(a.querySelector(".bili-video-card__info--ad")||a.querySelector(".bili-video-card__info--creative-ad"))&&(a.remove(),console.log("remove ads"))}function n(e){const a=[];for(const l of e){const e=l.target;if(!(e.classList&&e.classList.contains("carousel-transform")||"SPAN"===e.tagName)&&l.addedNodes.length>0)for(const e of l.addedNodes){const l=e;"#text"===l.nodeName||l.classList&&l.classList.contains("bili-watch-later")||a.push(l)}}a.length>0&&u(a)}const c=(0,l.defineComponentMetadata)({name:"clear-home",author:{name:"RieN7",link:"https://github.com/rien7"},tags:[componentsTags.style],displayName:"首页净化",description:"删除首页特定类型的卡片",entry:async e=>{let{metadata:a,settings:l}=e;const i=document.querySelector("main > .feed2 > .recommended-container_floor-aside > .container");if(!i)return;new MutationObserver(n).observe(i,{childList:!0}),Object.keys(l.options).forEach((e=>{(0,t.addComponentListener)(`${a.name}.${e}`,(a=>{if(a){if("广告"===e)return void(o=!0);s.push(e),"直播"===e&&(d=!0)}}),!0)}));u(i.children)},options:i,commitHash:"1167f721dc805a6bfd3d4bcba753607eff4bacd5",coreVersion:"2.7.0"});return a=a.component})()));
|
||||
270
registry/lib/components/style/clear-home/index.ts
Normal file
270
registry/lib/components/style/clear-home/index.ts
Normal file
@ -0,0 +1,270 @@
|
||||
import {
|
||||
OptionsOfMetadata,
|
||||
defineComponentMetadata,
|
||||
defineOptionsMetadata,
|
||||
} from '@/components/define'
|
||||
import { ComponentEntry } from '@/components/types'
|
||||
import { addComponentListener } from '@/core/settings'
|
||||
|
||||
type Options = OptionsOfMetadata<typeof options>
|
||||
|
||||
const removeBadgeList: string[] = []
|
||||
let removeLive = false
|
||||
let removeAds = true
|
||||
|
||||
const options = defineOptionsMetadata({
|
||||
广告: {
|
||||
displayName: '广告',
|
||||
defaultValue: true,
|
||||
},
|
||||
番剧: {
|
||||
displayName: '番剧',
|
||||
defaultValue: true,
|
||||
},
|
||||
电影: {
|
||||
displayName: '电影',
|
||||
defaultValue: true,
|
||||
},
|
||||
国创: {
|
||||
displayName: '国创',
|
||||
defaultValue: true,
|
||||
},
|
||||
电视剧: {
|
||||
displayName: '电视剧',
|
||||
defaultValue: true,
|
||||
},
|
||||
综艺: {
|
||||
displayName: '综艺',
|
||||
defaultValue: true,
|
||||
},
|
||||
纪录片: {
|
||||
displayName: '纪录片',
|
||||
defaultValue: true,
|
||||
},
|
||||
动画: {
|
||||
displayName: '动画',
|
||||
defaultValue: true,
|
||||
},
|
||||
游戏: {
|
||||
displayName: '游戏',
|
||||
defaultValue: true,
|
||||
},
|
||||
鬼畜: {
|
||||
displayName: '鬼畜',
|
||||
defaultValue: true,
|
||||
},
|
||||
音乐: {
|
||||
displayName: '音乐',
|
||||
defaultValue: true,
|
||||
},
|
||||
舞蹈: {
|
||||
displayName: '舞蹈',
|
||||
defaultValue: true,
|
||||
},
|
||||
影视: {
|
||||
displayName: '影视',
|
||||
defaultValue: true,
|
||||
},
|
||||
娱乐: {
|
||||
displayName: '娱乐',
|
||||
defaultValue: true,
|
||||
},
|
||||
知识: {
|
||||
displayName: '知识',
|
||||
defaultValue: true,
|
||||
},
|
||||
科技: {
|
||||
displayName: '科技',
|
||||
defaultValue: true,
|
||||
},
|
||||
资讯: {
|
||||
displayName: '资讯',
|
||||
defaultValue: true,
|
||||
},
|
||||
美食: {
|
||||
displayName: '美食',
|
||||
defaultValue: true,
|
||||
},
|
||||
生活: {
|
||||
displayName: '生活',
|
||||
defaultValue: true,
|
||||
},
|
||||
汽车: {
|
||||
displayName: '汽车',
|
||||
defaultValue: true,
|
||||
},
|
||||
时尚: {
|
||||
displayName: '时尚',
|
||||
defaultValue: true,
|
||||
},
|
||||
运动: {
|
||||
displayName: '运动',
|
||||
defaultValue: true,
|
||||
},
|
||||
动物圈: {
|
||||
displayName: '动物圈',
|
||||
defaultValue: true,
|
||||
},
|
||||
VLOG: {
|
||||
displayName: 'VLOG',
|
||||
defaultValue: true,
|
||||
},
|
||||
搞笑: {
|
||||
displayName: '搞笑',
|
||||
defaultValue: true,
|
||||
},
|
||||
单机游戏: {
|
||||
displayName: '单机游戏',
|
||||
defaultValue: true,
|
||||
},
|
||||
虚拟UP主: {
|
||||
displayName: '虚拟UP主',
|
||||
defaultValue: true,
|
||||
},
|
||||
公益: {
|
||||
displayName: '公益',
|
||||
defaultValue: true,
|
||||
},
|
||||
公开课: {
|
||||
displayName: '公开课',
|
||||
defaultValue: true,
|
||||
},
|
||||
专栏: {
|
||||
displayName: '专栏',
|
||||
defaultValue: true,
|
||||
},
|
||||
直播: {
|
||||
displayName: '直播',
|
||||
defaultValue: true,
|
||||
},
|
||||
赛事: {
|
||||
displayName: '赛事',
|
||||
defaultValue: true,
|
||||
},
|
||||
活动: {
|
||||
displayName: '活动',
|
||||
defaultValue: true,
|
||||
},
|
||||
课堂: {
|
||||
displayName: '课堂',
|
||||
defaultValue: true,
|
||||
},
|
||||
社区中心: {
|
||||
displayName: '社区中心',
|
||||
defaultValue: true,
|
||||
},
|
||||
新歌热榜: {
|
||||
displayName: '新歌热榜',
|
||||
defaultValue: true,
|
||||
},
|
||||
漫画: {
|
||||
displayName: '漫画',
|
||||
defaultValue: true,
|
||||
},
|
||||
})
|
||||
|
||||
function cardClear(mutationsList: HTMLElement[]) {
|
||||
for (const mutation of mutationsList) {
|
||||
if (!mutation.classList) {
|
||||
continue
|
||||
}
|
||||
if (mutation.classList.contains('floor-single-card')) {
|
||||
const badge = mutation.querySelector('.badge').textContent
|
||||
if (badge && removeBadgeList.includes(badge)) {
|
||||
mutation.remove()
|
||||
}
|
||||
} else if (mutation.classList.contains('bili-live-card')) {
|
||||
if (removeLive) {
|
||||
mutation.remove()
|
||||
}
|
||||
} else if (
|
||||
mutation.classList.contains('bili-video-card') ||
|
||||
mutation.classList.contains('feed-card')
|
||||
) {
|
||||
if (
|
||||
removeAds &&
|
||||
(mutation.querySelector('.bili-video-card__info--ad') ||
|
||||
mutation.querySelector('.bili-video-card__info--creative-ad'))
|
||||
) {
|
||||
mutation.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cardFilter(mutationsList: MutationRecord[]) {
|
||||
const filteredList: HTMLElement[] = []
|
||||
for (const mutation of mutationsList) {
|
||||
const mutationTarget = mutation.target as HTMLElement
|
||||
if (
|
||||
(mutationTarget.classList && mutationTarget.classList.contains('carousel-transform')) ||
|
||||
mutationTarget.tagName === 'SPAN'
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (mutation.addedNodes.length > 0) {
|
||||
for (const node of mutation.addedNodes) {
|
||||
const nodeTarget = node as HTMLElement
|
||||
if (
|
||||
nodeTarget.nodeName === '#text' ||
|
||||
(nodeTarget.classList && nodeTarget.classList.contains('bili-watch-later'))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
filteredList.push(nodeTarget)
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (filteredList.length > 0) {
|
||||
cardClear(filteredList)
|
||||
}
|
||||
}
|
||||
|
||||
const clearHome: ComponentEntry<Options> = async ({ metadata, settings }) => {
|
||||
const container = document.querySelector(
|
||||
'main > .feed2 > .recommended-container_floor-aside > .container',
|
||||
)
|
||||
if (!container) {
|
||||
return
|
||||
}
|
||||
const config = { childList: true }
|
||||
const observer = new MutationObserver(cardFilter)
|
||||
observer.observe(container, config)
|
||||
|
||||
Object.keys(settings.options).forEach(disableType => {
|
||||
addComponentListener(
|
||||
`${metadata.name}.${disableType}`,
|
||||
(value: boolean) => {
|
||||
if (value) {
|
||||
if (disableType === '广告') {
|
||||
removeAds = true
|
||||
return
|
||||
}
|
||||
removeBadgeList.push(disableType)
|
||||
if (disableType === '直播') {
|
||||
removeLive = true
|
||||
}
|
||||
}
|
||||
},
|
||||
true,
|
||||
)
|
||||
})
|
||||
const containerList = container.children as unknown as HTMLElement[]
|
||||
cardClear(containerList)
|
||||
}
|
||||
|
||||
export const component = defineComponentMetadata({
|
||||
name: 'clear-home',
|
||||
author: {
|
||||
name: 'RieN7',
|
||||
link: 'https://github.com/rien7',
|
||||
},
|
||||
tags: [componentsTags.style],
|
||||
displayName: '首页净化',
|
||||
description: '删除首页特定类型的卡片',
|
||||
entry: clearHome,
|
||||
options,
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user