Skip to content

Commit

Permalink
feat: support cycanime
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Jul 17, 2024
1 parent 348e051 commit 3303e6e
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions meta.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// @include https://*43.240.156.118*
// @include https://www.mutedm.com/*
// @include https://www.mutean.com/*
// @include https://www.cycanime.com/*
// @include https://player.cycanime.com/*
// @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
8 changes: 8 additions & 0 deletions src/adapter/cycanime/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.cycanime.widescreen {
.header_nav0,
.top-back.hoa,
.fixedGroup {
visibility: hidden;
pointer-events: none;
}
}
44 changes: 44 additions & 0 deletions src/adapter/cycanime/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: ['.cycanime.'],
opts: [
{ test: '/watch', run: runInTop },
{ test: '/watch', run: iframePlayer.runInIframe, runInIframe: true },
{
test: () => location.hostname.includes('player.cycanime'),
run: parser,
runInIframe: true,
},
],
search: {
name: '次元城',
search: (name) => `https://www.cycanime.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' }, '*')
})
},
},
})
48 changes: 48 additions & 0 deletions src/adapter/cycanime/play.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { KPlayer } from '../../player'
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('cycanime')
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('#mui-player', {
eventToParentWindow: true,
})
player.src = url
}
1 change: 1 addition & 0 deletions src/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ import './agefans'
import './ntdm9'
import './bimiacg'
import './mutean'
import './cycanime'

0 comments on commit 3303e6e

Please sign in to comment.