-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom enhancements (#360)
* feat: add custom enhancements feat: Add configuration to hide lyrics on startup feat: Add auto-hide configuration for APlayer feat: Add configuration to show APlayer after loading is complete * docs: update configuration items * refactor: add unmounted for eventListerner & observer * refactor: change the code specification * refactor: change onMounted and add unmounted for observer & eventListerner --------- Co-authored-by: YunYouJun <me@yunyoujun.cn>
- Loading branch information
Showing
9 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { MetingOptions } from '../node/index' | ||
import { animationIn, autoHidden, handleOptions, useAPlayerMiniSwitcherEventListener } from './utils' | ||
import { setupHiddenLyricHidingObserver } from './observer' | ||
|
||
export enum Hook { | ||
metingInit = 'metingInit', | ||
metingLoadBefore = 'metingLoadBefore', | ||
metingLoad = 'metingLoad', | ||
} | ||
|
||
export function onMetingInit({ options }: MetingOptions) { | ||
handleOptions(options, { | ||
animationIn: () => import('../style/animation-in.scss'), | ||
}) | ||
} | ||
|
||
export function onMetingLoadBefore({ options }: MetingOptions) { | ||
handleOptions(options, { | ||
animationIn: () => animationIn(Hook.metingLoadBefore), | ||
}) | ||
} | ||
|
||
export function onMetingLoad({ options }: MetingOptions) { | ||
handleOptions(options, { | ||
lyricHidden: () => setupHiddenLyricHidingObserver(), | ||
animationIn: () => { | ||
animationIn(Hook.metingLoad) | ||
}, | ||
autoHidden: () => { | ||
useAPlayerMiniSwitcherEventListener() | ||
autoHidden(Hook.metingLoad) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { onUnmounted } from 'vue' | ||
import type { MetingOptions } from '../node/index' | ||
import { onMetingLoad, onMetingLoadBefore } from './hook' | ||
|
||
export function setupHiddenLyricHidingObserver() { | ||
let observer: MutationObserver | null | ||
|
||
observer = new MutationObserver((mutations) => { | ||
const lrcElement = document.querySelector('.aplayer-lrc .aplayer-lrc-contents .aplayer-lrc-current') as HTMLElement | ||
const lrcButton = document.querySelector('.aplayer-icon-lrc') as HTMLElement | ||
function removelrc() { | ||
if (lrcElement) { | ||
lrcElement.style.display = 'none' | ||
if (lrcElement.textContent !== 'Loading') { | ||
lrcButton.click() | ||
lrcElement.style.display = '' | ||
observer?.disconnect() | ||
} | ||
} | ||
} | ||
mutations.forEach((_mutation) => { | ||
removelrc() | ||
}) | ||
}) | ||
observer.observe(document.body, { childList: true, subtree: true }) | ||
|
||
onUnmounted(() => { | ||
observer?.disconnect() | ||
observer = null | ||
}) | ||
} | ||
|
||
export function useMetingLoadObserver(addon: MetingOptions) { | ||
let hasExecuted = false | ||
let observer: MutationObserver | null | ||
|
||
observer = new MutationObserver((mutations) => { | ||
function load() { | ||
if (hasExecuted) | ||
return | ||
const aplayerNarrowElement = document.querySelector('.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body') as HTMLElement | ||
if (aplayerNarrowElement) { | ||
hasExecuted = true | ||
setTimeout(() => { | ||
onMetingLoadBefore(addon) | ||
requestAnimationFrame(() => { | ||
onMetingLoad(addon) | ||
observer?.disconnect() | ||
observer = null | ||
}) | ||
}, 0) | ||
} | ||
} | ||
mutations.forEach((_mutation) => { | ||
load() | ||
}) | ||
}) | ||
observer.observe(document.body, { childList: true, subtree: true }) | ||
|
||
onUnmounted(() => { | ||
observer?.disconnect() | ||
observer = null | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { computed } from 'vue' | ||
import { useRuntimeConfig } from 'valaxy' | ||
import type { MetingOptions } from '../node/index' | ||
|
||
/** | ||
* get addon config | ||
*/ | ||
export function useAddonMeting() { | ||
const runtimeConfig = useRuntimeConfig() | ||
return computed<MetingOptions>(() => { | ||
return runtimeConfig.value.addons['valaxy-addon-meting'] as unknown as MetingOptions | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useEventListener } from '@vueuse/core' | ||
import { onMounted, onUnmounted } from 'vue' | ||
import type { MetingOptions } from '../node/index' | ||
import { Hook } from './hook' | ||
|
||
type Rules = { | ||
[K in string]: () => void; | ||
} | ||
export function handleOptions(options: MetingOptions['options'], rules: Rules) { | ||
if (!options) | ||
return | ||
Object.entries(rules).forEach(([key, action]) => { | ||
if (options[key as keyof typeof options]) | ||
action() | ||
}) | ||
} | ||
|
||
/** | ||
* APlayer mini switcher | ||
*/ | ||
export function useAPlayerMiniSwitcherEventListener() { | ||
let aplayerFixedElement: HTMLElement | ||
let aplayerIconButton: HTMLElement | ||
let aplayerNarrow = true | ||
|
||
function toggleAplayerVisibility() { | ||
aplayerNarrow = !aplayerNarrow | ||
} | ||
|
||
function hiddenAplayer() { | ||
if (aplayerNarrow) | ||
aplayerFixedElement.style.left = '-66px' | ||
} | ||
|
||
function showAplayer() { | ||
aplayerFixedElement.style.left = '0' | ||
} | ||
|
||
onMounted(() => { | ||
aplayerFixedElement = document.querySelector('.aplayer.aplayer-fixed .aplayer-body') as HTMLElement | ||
aplayerIconButton = document.querySelector('.aplayer-body .aplayer-miniswitcher .aplayer-icon') as HTMLElement | ||
|
||
useEventListener(aplayerFixedElement, 'mouseenter', showAplayer) | ||
useEventListener(aplayerFixedElement, 'mouseleave', hiddenAplayer) | ||
useEventListener(aplayerIconButton, 'click', toggleAplayerVisibility) | ||
}) | ||
|
||
onUnmounted(() => { | ||
aplayerFixedElement?.removeEventListener('mouseenter', showAplayer) | ||
aplayerFixedElement?.removeEventListener('mouseleave', hiddenAplayer) | ||
aplayerIconButton?.removeEventListener('click', toggleAplayerVisibility) | ||
}) | ||
} | ||
|
||
function handleAplayerAction(action: string, leftValue: string) { | ||
const aplayerNarrowElement = document.querySelector('.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body') as HTMLElement | ||
if (!aplayerNarrowElement) | ||
return | ||
|
||
if (action === Hook.metingLoadBefore) | ||
aplayerNarrowElement.style.display = 'initial' | ||
else if (action === Hook.metingLoad) | ||
aplayerNarrowElement.style.left = leftValue | ||
} | ||
|
||
export function animationIn(action: string) { | ||
handleAplayerAction(action, '0') | ||
} | ||
|
||
export function autoHidden(action: string) { | ||
handleAplayerAction(action, '-66px') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './client' | ||
export * from './node' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.aplayer.aplayer-fixed.aplayer-narrow { | ||
& .aplayer-body { | ||
display: none; | ||
left: -100px; | ||
} | ||
} |