Skip to content

Commit

Permalink
feat: support xfani.com
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Jul 21, 2024
1 parent fcde7c7 commit 1ae15ba
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [bimiacg](https://www.bimiacg10.net)
- [mutean](https://www.mutean.com)
- [次元城](https://www.cycanime.com)
- [稀饭动漫](https://dick.xfani.com)

**请使用 <kbd>?</kbd> 键查看脚本信息与快捷键**

Expand Down
3 changes: 2 additions & 1 deletion meta.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
// @include https://www.mutedm.com/*
// @include https://www.mutean.com/*
// @include https://www.cycanime.com/*
// @include https://player.cycanime.com/*
// @include https://dick.xfani.com/*
// @include https://player.moedot.net/*
// @run-at document-end
// @require https://registry.npmmirror.com/jquery/3.6.0/files/dist/jquery.min.js
// @require https://registry.npmmirror.com/plyr/3.6.4/files/dist/plyr.min.js
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "agefans",
"version": "1.42.0",
"description": "增强播放功能,实现自动换集、无缝换集、画中画、历史记录、断点续播、弹幕等功能。适配agefans、NT动漫、bimiacg、mutefun、次元城",
"description": "增强播放功能,实现自动换集、无缝换集、画中画、历史记录、断点续播、弹幕等功能。适配agefans、NT动漫、bimiacg、mutefun、次元城、稀饭动漫",
"main": "index.user.js",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import './ntdm9'
import './bimiacg'
import './mutean'
import './cycanime'
import './xfani'
8 changes: 8 additions & 0 deletions src/adapter/xfani/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.xfani.widescreen {
.header_nav0,
.top-back.hoa,
.fixedGroup {
visibility: hidden;
pointer-events: none;
}
}
44 changes: 44 additions & 0 deletions src/adapter/xfani/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { runtime } from '../../runtime'
import { iframePlayer, runInTop, parser } from './play'
import './index.scss'

runtime.register({
domains: ['.xfani.', 'player.moedot'],
opts: [
{ test: '/watch', run: runInTop },
{ test: '/watch', run: iframePlayer.runInIframe, runInIframe: true },
{
test: () => location.hostname.includes('player.moedot'),
run: parser,
runInIframe: true,
},
],
search: {
name: '稀饭动漫',
search: (name) => `https://dick.xfani.com/search.html?wd=${name}`,
getSearchName: () => {
return new Promise((resolve) => {
const fn = (e: MessageEvent<any>) => {
if (e.data.key === 'getSearchName') {
resolve(e.data.name)
window.removeEventListener('message', fn)
}
}
window.addEventListener('message', fn)
parent.postMessage({ key: 'getSearchName' }, '*')
})
},
getEpisode: () => {
return new Promise((resolve) => {
const fn = (e: MessageEvent<any>) => {
if (e.data.key === 'getEpisode') {
resolve(e.data.name)
window.removeEventListener('message', fn)
}
}
window.addEventListener('message', fn)
parent.postMessage({ key: 'getEpisode' }, '*')
})
},
},
})
58 changes: 58 additions & 0 deletions src/adapter/xfani/play.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { KPlayer } from '../../player'
import { execInUnsafeWindow } from '../../utils/execInUnsafeWindow'
import { queryDom } from '../../utils/queryDom'
import { wait } from '../../utils/wait'
import { defineIframePlayer } from '../common/defineIframePlayer'
function getActive() {
return $<HTMLAnchorElement>('.anthology-list-play li.on > a')
}
function switchPart(next: boolean) {
return getActive().parent()[next ? 'next' : 'prev']().find('a')[0]?.href
}

export function runInTop() {
$('body').addClass('xfani')
$('.player-news').remove()
iframePlayer.runInTop()
}

export const iframePlayer = defineIframePlayer({
iframeSelector: '#playleft iframe',
getActive,
setActive: (href) => {
$<HTMLAnchorElement>('.anthology-list-play li a').each((_, el) => {
if (el.href === href) {
el.parentElement!.classList.add('ecnav-dt', 'on')
$('.play-on').insertAfter($(el).find('span'))
} else {
el.parentElement!.classList.remove('ecnav-dt', 'on')
}
})
},
search: {
getSearchName: () => $('.player-title-link').text(),
getEpisode: () => getActive().text(),
},
getEpisodeList: () => $('.anthology-list-play li a'),
switchEpisode: (next) => switchPart(next),
})

export async function parser() {
const video = await queryDom<HTMLVideoElement>('video')

await wait(() => !!video.currentSrc)
let url = video.currentSrc
video.src = ''

const player = new KPlayer('#player', {
eventToParentWindow: true,
})
player.src = url

$('#loading').remove()

await execInUnsafeWindow(() => {
// @ts-ignore
PlayEr.void.destroy()
})
}

0 comments on commit 1ae15ba

Please sign in to comment.