Skip to content

Commit 7f035fe

Browse files
committed
Close #83
1 parent 92c7e55 commit 7f035fe

File tree

8 files changed

+63
-70
lines changed

8 files changed

+63
-70
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spotify-lyrics",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"description": "Desktop Spotify Web Player Instant Synchronized Lyrics",
55
"scripts": {
66
"lint": "tsc --noEmit && eslint --ext .ts --fix src/",

Diff for: public/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/extend-chrome/manifest-json-schema/main/schema/manifest.schema.json",
33
"name": "__MSG_extensionName__",
4-
"version": "1.6.2",
4+
"version": "1.6.3",
55
"manifest_version": 3,
66
"description": "__MSG_extensionDescription__",
77
"default_locale": "en",

Diff for: src/background.ts

+21-17
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ function enableBrowserAction() {
5656
disableBrowserAction();
5757

5858
browser.runtime.onMessage.addListener(async (msg: Message, sender) => {
59+
const tabId = sender.tab?.id;
5960
const { type, data } = msg || {};
6061
switch (type) {
6162
case Event.GET_OPTIONS: {
6263
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage#Parameters
63-
return getOptions().then((options) => ({
64-
...options,
65-
i18nMap,
66-
}));
64+
const options = await getOptions();
65+
if (!tabId) return;
66+
67+
sendMessage(tabId, {
68+
type: Event.SEND_OPTIONS,
69+
data: { ...options, i18nMap },
70+
});
6771
}
6872
case Event.POPUP_ACTIVE: {
6973
if (data === true) {
@@ -85,7 +89,6 @@ browser.runtime.onMessage.addListener(async (msg: Message, sender) => {
8589
}
8690
case Event.SEND_REQUEST: {
8791
const { reqId, uri, options } = data as Req;
88-
const tabId = sender.tab?.id;
8992
if (!tabId) return;
9093

9194
const sendRes = (data: Omit<Res, 'reqId'>) => {
@@ -119,8 +122,6 @@ browser.commands.onCommand.addListener((command) => {
119122
}
120123
});
121124

122-
browser.runtime.setUninstallURL('https://forms.gle/bUWyEqfSTCU9NEwEA');
123-
124125
browser.contextMenus.create({
125126
id: ContextItems.WELCOME,
126127
title: i18n.menusWelcome(),
@@ -133,22 +134,21 @@ browser.contextMenus.create({
133134
contexts: ['action'],
134135
});
135136

136-
const storeLinkMap: Record<string, string> = {
137+
const storeLinkMap = {
137138
'{d5bcc68d-856a-41e2-8021-d4c51f3b8e4a}':
138139
'https://addons.mozilla.org/en-US/firefox/addon/spotify-lyrics/',
139-
'{9bbdd06f-4fe2-4d05-8c2d-1ef6bf71f84d}': 'https://github.com/mantou132/Spotify-Lyrics',
140140
mkjfooclbdgjdclepjeepbmmjaclipod:
141141
'https://chrome.google.com/webstore/detail/spotify-lyrics/mkjfooclbdgjdclepjeepbmmjaclipod/reviews',
142142
aiehldpoaeaidnljjimhbojpblkbembm:
143143
'https://microsoftedge.microsoft.com/addons/detail/spotify-lyrics/aiehldpoaeaidnljjimhbojpblkbembm',
144+
github: 'https://github.com/mantou132/Spotify-Lyrics',
144145
};
145-
if (storeLinkMap[browser.runtime.id]) {
146-
browser.contextMenus.create({
147-
id: ContextItems.RATE_ME,
148-
title: i18n.menusRateMe(),
149-
contexts: ['action'],
150-
});
151-
}
146+
147+
browser.contextMenus.create({
148+
id: ContextItems.RATE_ME,
149+
title: i18n.menusRateMe(),
150+
contexts: ['action'],
151+
});
152152

153153
const openPage = async (url: string) => {
154154
const { windowId } = await browser.tabs.create({ url });
@@ -164,11 +164,15 @@ browser.contextMenus.onClicked.addListener(async function (info) {
164164
openPage('https://github.com/mantou132/Spotify-Lyrics/issues');
165165
break;
166166
case ContextItems.RATE_ME:
167-
openPage(storeLinkMap[browser.runtime.id]);
167+
openPage(
168+
storeLinkMap[browser.runtime.id as keyof typeof storeLinkMap] || storeLinkMap.github,
169+
);
168170
break;
169171
}
170172
});
171173

174+
browser.runtime.setUninstallURL('https://forms.gle/bUWyEqfSTCU9NEwEA');
175+
172176
browser.runtime.onInstalled.addListener(({ reason }) => {
173177
if (reason === 'install') {
174178
openPage(browser.runtime.getURL('welcome.html'));

Diff for: src/common/constants.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Value } from '../options/elements/switch';
1+
import type { SwitchValue } from '../options/elements/switch';
22

33
// Read package.json `version` field
44
export const VERSION = process.env.VERSION || 'UNKNOWN';
@@ -14,25 +14,25 @@ export interface Message<T = any> {
1414
}
1515

1616
export enum Event {
17-
GET_SONGS = 'get-songs',
18-
SEND_SONGS = 'send-songs',
19-
SELECT_SONG = 'select-song',
20-
CONFIRMED_SONG = 'confirmed-song',
21-
GET_OPTIONS = 'get-options',
22-
SEND_OPTIONS = 'send-options',
23-
OPEN_OPTIONS = 'open-options',
24-
POPUP_ACTIVE = 'popup-active',
25-
CAPTURE_EXCEPTION = 'capture-exception',
26-
SEND_REQUEST = 'send-request',
27-
SEND_RESPONSE = 'send-response',
28-
TOGGLE = 'toggle',
17+
GET_SONGS = 100000,
18+
SEND_SONGS,
19+
SELECT_SONG,
20+
CONFIRMED_SONG,
21+
GET_OPTIONS,
22+
SEND_OPTIONS,
23+
OPEN_OPTIONS,
24+
POPUP_ACTIVE,
25+
CAPTURE_EXCEPTION,
26+
SEND_REQUEST,
27+
SEND_RESPONSE,
28+
TOGGLE,
2929
}
3030

31-
export const ContextItems = {
32-
FEEDBACK: 'feedback',
33-
RATE_ME: 'rate-me',
34-
WELCOME: 'welcome',
35-
};
31+
export enum ContextItems {
32+
FEEDBACK = 'feedback',
33+
RATE_ME = 'rate-me',
34+
WELCOME = 'welcome',
35+
}
3636

3737
export const LyricsPositions = ['page', 'pip'] as const;
3838
export const LyricsAlign = ['left', 'center'] as const;
@@ -42,16 +42,16 @@ export interface Options {
4242
'font-size': string;
4343
'font-family': (typeof LyricsFontFamily)[number] | string;
4444
'toggle-shortcut': string;
45-
'only-cover': Value;
46-
'clean-lyrics': Value;
47-
'hd-cover': Value;
48-
'use-unreviewed-lyrics': Value;
45+
'only-cover': SwitchValue;
46+
'clean-lyrics': SwitchValue;
47+
'hd-cover': SwitchValue;
48+
'use-unreviewed-lyrics': SwitchValue;
4949
'show-on': (typeof LyricsPositions)[number];
5050
'lyrics-align': (typeof LyricsAlign)[number];
51-
'traditional-chinese-lyrics': Value;
51+
'traditional-chinese-lyrics': SwitchValue;
5252
// Deprecated
53-
'lyrics-smooth-scroll'?: Value;
54-
'strict-mode'?: Value;
53+
'lyrics-smooth-scroll'?: SwitchValue;
54+
'strict-mode'?: SwitchValue;
5555
}
5656

5757
export type Platform = 'SPOTIFY' | 'YOUTUBE' | 'DEEZER' | 'TIDAL' | 'APPLE';

Diff for: src/content.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,10 @@ runtime.onMessage.addListener((msg: Message) => {
88

99
window.addEventListener('message', ({ data }) => {
1010
const { type } = data || {};
11-
switch (type) {
12-
case Event.GET_OPTIONS: {
13-
return runtime
14-
.sendMessage(data)
15-
.then((options) => {
16-
window.postMessage({ type: Event.SEND_OPTIONS, data: options }, '*');
17-
})
18-
.catch(() => {
19-
//
20-
});
21-
}
22-
case Event.SEND_REQUEST:
23-
case Event.POPUP_ACTIVE:
24-
case Event.CAPTURE_EXCEPTION:
25-
case Event.SEND_SONGS: {
26-
return runtime.sendMessage(data).catch(() => {
27-
//
28-
});
29-
}
11+
if (type in Event) {
12+
runtime.sendMessage(data).catch(() => {
13+
//
14+
});
3015
}
3116
});
3217

Diff for: src/options/elements/switch.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { customElement, attribute, refobject, RefObject } from '@mantou/gem/lib/
33

44
import { theme } from '../../common/theme';
55

6-
export type Value = 'off' | 'on';
6+
export type SwitchValue = 'off' | 'on';
77

88
@customElement('ele-switch')
99
export class Switch extends GemElement {
1010
@attribute name: string;
11-
@attribute defaultValue: Value;
11+
@attribute defaultValue: SwitchValue;
1212

1313
@refobject checkboxRef: RefObject<HTMLInputElement>;
1414

1515
get control() {
1616
return this.checkboxRef.element!;
1717
}
18-
get value(): Value {
18+
get value(): SwitchValue {
1919
return this.control.checked ? 'on' : 'off';
2020
}
2121

Diff for: src/page/element.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ const setPopupState = (active: boolean) => {
4040
};
4141

4242
lyricVideo.addEventListener('enterpictureinpicture', () => {
43-
setPopupState(true);
4443
lyricVideoIsOpen = true;
4544
});
4645
lyricVideo.addEventListener('leavepictureinpicture', () => {
47-
setPopupState(false);
4846
lyricVideoIsOpen = false;
4947
});
48+
49+
// service worker active will disabled browser action
50+
setInterval(() => setPopupState(lyricVideoIsOpen), 1000);
51+
5052
// When the lyrics are displayed on the page
5153
window.addEventListener('beforeunload', () => {
5254
if (lyricVideoIsOpen) setPopupState(false);

Diff for: src/page/lyrics.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export interface Song {
2727
name: string;
2828
artists: Artist[];
2929
album: Album;
30-
duration?: number; // ms
30+
/**ms */
31+
duration?: number;
3132
}
3233

3334
interface SearchSongsResult {
@@ -91,6 +92,7 @@ const simplifiedText = (s: string) => {
9192
const removeSongFeat = (s: string) => {
9293
return (
9394
s
95+
.replace(/-\s+\d*\s*remaster(ed)?\s*\d*/, '')
9496
.replace(/-\s+(feat|with).*/i, '')
9597
.replace(/(\(|\[)(feat|with)\.?\s+.*(\)|\])$/i, '')
9698
.trim() || s
@@ -410,7 +412,7 @@ export function parseLyrics(lyricStr: string, options: ParseLyricsOptions = {})
410412
const otherInfoKeys = [
411413
'作?\\s*词|作?\\s*曲|编\\s*曲?|监\\s*制?',
412414
'.*编写|.*和音|.*和声|.*合声|.*提琴|.*录|.*工程|.*工作室|.*设计|.*剪辑|.*制作|.*发行|.*出品|.*后期|.*混音|.*缩混',
413-
'原唱|翻唱|题字|文案|海报|古筝|二胡|钢琴|吉他|贝斯|笛子|鼓|弦乐',
415+
'母带|原唱|翻唱|题字|文案|海报|古筝|二胡|钢琴|吉他|贝斯|笛子|鼓|弦乐',
414416
'lrc|publish|vocal|guitar|program|produce|write',
415417
];
416418
const otherInfoRegexp = new RegExp(`^(${otherInfoKeys.join('|')}).*(:|:)`, 'i');

0 commit comments

Comments
 (0)