Skip to content

Commit

Permalink
Add lyrics server option
Browse files Browse the repository at this point in the history
Closed #128
  • Loading branch information
mantou132 committed Jul 28, 2024
1 parent 4bfc889 commit a4b43ef
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spotify-lyrics",
"version": "1.6.6",
"version": "1.6.7",
"description": "Desktop Spotify Web Player Instant Synchronized Lyrics",
"scripts": {
"lint": "tsc --noEmit && eslint --ext .ts --fix src/",
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
"message": "Lyrics transform"
},

"optionsLyricsServer": {
"message": "Lyrics server"
},

"optionsLyricsTransformDetail": {
"message": "When using simplified Chinese, try to load the translated lyrics"
},
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
"message": "歌词转换"
},

"optionsLyricsServer": {
"message": "歌词服务"
},

"optionsLyricsTransformDetail": {
"message": "当使用简体中文时会尝试加载翻译的歌词"
},
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/extend-chrome/manifest-json-schema/main/schema/manifest.schema.json",
"name": "__MSG_extensionName__",
"version": "1.6.6",
"version": "1.6.7",
"manifest_version": 3,
"description": "__MSG_extensionDescription__",
"default_locale": "en",
Expand Down
2 changes: 2 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const LyricsPositions = ['page', 'pip'] as const;
export const LyricsAlign = ['left', 'center'] as const;
export const LyricsFontFamily = ['CircularSp', 'Sans-Serif', 'Serif', 'Cursive'] as const;
export const LyricsTransform = ['Origin', 'Simplified', 'Traditional'] as const;
export const LyricsServer = ['NetEase', 'LRCLIB'] as const;
export interface Options {
cid: string;
'font-size': string;
Expand All @@ -52,6 +53,7 @@ export interface Options {
/**@deprecated */
'traditional-chinese-lyrics': SwitchValue;
'lyrics-transform': (typeof LyricsTransform)[number];
'lyrics-server': (typeof LyricsServer)[number];
/**@deprecated */
'lyrics-smooth-scroll'?: SwitchValue;
'strict-mode'?: SwitchValue;
Expand Down
8 changes: 8 additions & 0 deletions src/options/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LyricsAlign,
LyricsFontFamily,
LyricsTransform,
LyricsServer,
} from '../common/constants';
import { sendEvent, events } from '../common/ga';
import { theme } from '../common/theme';
Expand Down Expand Up @@ -196,6 +197,13 @@ export class OptionsApp extends GemElement<State> {
default-value=${options['use-unreviewed-lyrics']}
></ele-switch>
</ele-form-item>
<ele-form-item label="${i18n.optionsLyricsServer()} *">
<ele-select
name=${'lyrics-server' as keyof Options}
default-value=${options['lyrics-server']}
.options=${LyricsServer.map((e) => ({ label: e, value: e }))}
></ele-select>
</ele-form-item>
</ele-form>
<ul class="tip">
<li>* ${i18n.optionsSaveTip1()}</li>
Expand Down
1 change: 1 addition & 0 deletions src/options/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaultOptions: Options = {
'toggle-shortcut': 'l',
'traditional-chinese-lyrics': uiLanguage === 'zh-TW' || uiLanguage === 'zh-HK' ? 'on' : 'off',
'lyrics-transform': 'Origin',
'lyrics-server': 'NetEase',
};

export async function getOptions() {
Expand Down
4 changes: 4 additions & 0 deletions src/page/share-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { optionsPromise } from './options';
import { captureException, querySelector } from './utils';
import { audioPromise } from './element';
import { configPromise } from './config';
import { fetchNetEaseSongList } from './netease';
import { fetchLRCLIBSongList } from './lrclib';

interface CacheReq {
name: string;
Expand Down Expand Up @@ -186,6 +188,8 @@ export class SharedData {
const parseLyricsOptions = await this._getParseLyricsOptions();
const [{ list, id }, remoteData] = await Promise.all([
matchingLyrics(this.req, {
fetchSongList:
options['lyrics-server'] === 'NetEase' ? fetchNetEaseSongList : fetchLRCLIBSongList,
getDuration: async () => {
const audioMetadataLoaded = new Promise<any>((res) =>
audio.addEventListener('loadedmetadata', res, { once: true }),
Expand Down
7 changes: 4 additions & 3 deletions src/page/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export function documentQueryHasSelector(s: string) {
}

export function querySelectorAll(selector: string) {
const [rootSelector, sub] = selector.split('>>');
if (sub) {
const root = querySelector(rootSelector);
const parts = selector.split('>>');
if (parts.length > 1) {
const sub = parts.pop()!;
const root = querySelector(parts.join('>>'));
return root?.shadowRoot?.querySelectorAll(sub);
}
return document.querySelectorAll(selector);
Expand Down

0 comments on commit a4b43ef

Please sign in to comment.