过滤广告 on www.iyf.com
当前为
// ==UserScript==
// @name IYF Ad Blocker
// @name:zh-CN IYF Ad Blocker on www.iyf.com
// @namespace http://tampermonkey.net/
// @version 0.1.5
// @description Filter ads on www.iyf.com
// @description:zh-CN 过滤广告 on www.iyf.com
// @author Dylan Zhang
// @include https://www.iyf.tv/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=iyf.tv
// @license MIT
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// variables
const win = unsafeWindow
let homePageStyle
let playPageStyle
let listPageStyle
const TIME_OUT = 5000
/* utilities */
function $(selector) {
return document.querySelector(selector)
}
function getCurrentPath() {
const path = win.location.pathname.split('/')[1]
return path ? `/${path}` : ''
}
function addEvent(el, type, handler) {
if (typeof el === 'string') el = $(el)
el.addEventListener(type, handler, false)
}
function nextTick(fn) {
setTimeout(fn)
}
function checkExistingDOM(selector) {
let timer
let timeout
return new Promise((resolve, reject) => {
const find = () => {
const el = $(selector)
if (el) {
clearInterval(timer)
clearTimeout(timeout)
resolve(el)
}
}
timer = setInterval(find, 1000)
timeout = setTimeout(reject, TIME_OUT)
})
}
/* meta modification */
const history = win.history
const originalPushState = history.pushState
const originalReplaceState = history.replaceState
const pushstateEvent = new Event('pushstate')
const replacestate = new Event('replacestate')
// override pushState
history.pushState = function() {
const result = originalPushState.apply(this, arguments)
window.dispatchEvent(pushstateEvent)
return result
};
// override replaceState
history.replaceState = function() {
const result = originalReplaceState.apply(this, arguments)
window.dispatchEvent(replacestate)
return result
}
;['popstate', 'pushstate', 'replaceState'].forEach(function(eventName) {
window.addEventListener(eventName, () => {
// ensure that the event is triggered after the DOMContentLoaded event
requestAnimationFrame(() => {
main()
})
})
})
/* common ads */
function filterCommonAds() {
nextTick(() => {
$('app-dn-user-menu-item:has(span.iconVIP)')?.remove()
})
}
/* home page */
function filterHomePage() {
if (!homePageStyle) {
homePageStyle = GM_addStyle(`
app-recommended-news:nth-of-type(2),
app-classified-top-videos:nth-of-type(1) > app-home-collection,
div:has(> app-discovery-in-home),
.new-list {
display: none!important;
}
`)
}
}
/* play/watch page */
function filterPlayPage() {
if (!playPageStyle) {
playPageStyle = GM_addStyle(`
div.ps > div.bl,
vg-pause-f,
.caption {
display: none!important;
}
`)
}
nextTick(() => {
$(`app-video-user-data-bar + div`)?.remove()
})
filterPlayer()
}
function filterPlayer() {
let playerEl
let pauseOverlayEl
init()
function init() {
checkExistingDOM('#video_player').then(el => {
playerEl = el
setPlayer()
})
}
function setPlayer(){
addEvent(playerEl, 'pause', onPause)
closeDanmu()
}
function closeDanmu() {
const btn = $('.action-pannel i.iconfont')
const openedName = 'icondanmukai'
const closedName = 'icondanmuguan'
if (btn?.classList.contains(openedName)) {
btn.click()
}
}
function onPause(){
pauseOverlayEl = $('.publicbox')
if (pauseOverlayEl) {
pauseOverlayEl.remove()
pauseOverlayEl = null
if (playerEl.paused) {
playerEl.play()
}
}
}
}
/* list page */
function filterListPage() {
if (!listPageStyle) {
listPageStyle = GM_addStyle(`
div.ss-ctn:has(img[alt="广告"]) {
display: none!important;
}
`)
}
}
// main
function main() {
const path = getCurrentPath()
console.log(path)
switch (path) {
case '':
filterHomePage()
break
case '/watch':
case '/play':
filterPlayPage()
break
case '/list':
filterListPage()
break
}
filterCommonAds()
}
main()
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址