Skip to content

Commit 364d477

Browse files
committed
Closed #143
在 console 中使用 `executeScript` 能打开 pip,但是写在 background.ts 中无效
1 parent a4b43ef commit 364d477

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

Diff for: src/common/bg.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ import browser from 'webextension-polyfill';
22

33
import { Event, isProd, type Message } from './constants';
44

5-
export function sendMessage<T>(tabId: number, msg: Message<T>): void;
6-
export function sendMessage<T>(msg: Message<T>): void;
7-
export function sendMessage<T>(tabIdOrMsg: number | Message<T>, msg?: Message<T>) {
5+
export async function getTags() {
6+
return browser.tabs.query({
7+
url: browser.runtime.getManifest().content_scripts![0].matches,
8+
});
9+
}
10+
11+
export async function sendMessage<T>(tabId: number, msg: Message<T>): Promise<void>;
12+
export async function sendMessage<T>(msg: Message<T>): Promise<void>;
13+
export async function sendMessage<T>(tabIdOrMsg: number | Message<T>, msg?: Message<T>) {
814
if (typeof tabIdOrMsg === 'number') {
915
browser.tabs.sendMessage(tabIdOrMsg, msg);
1016
} else {
11-
browser.tabs
12-
.query({ url: browser.runtime.getManifest().content_scripts![0].matches })
13-
.then((tabs) => {
14-
tabs.forEach((tab) => {
15-
// Only the tab that open the lyrics will response
16-
if (tab?.id) browser.tabs.sendMessage(tab.id, tabIdOrMsg);
17-
});
18-
});
17+
const tabs = await getTags();
18+
tabs.forEach((tab) => {
19+
// Only the tab that open the lyrics will response
20+
if (tab?.id) browser.tabs.sendMessage(tab.id, tabIdOrMsg);
21+
});
1922
}
2023
}
2124

Diff for: src/options/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class OptionsApp extends GemElement<State> {
6565

6666
copyIdHandler = (e: KeyboardEvent) => {
6767
const { options } = this.state;
68-
if (e.key === 'c' && options) {
68+
if (e.key.toLowerCase() === 'c' && options) {
6969
navigator.clipboard.writeText(options.cid);
7070
}
7171
};

Diff for: src/page/btn.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ window.addEventListener(
5050
) {
5151
return;
5252
}
53-
if (e.key === options['toggle-shortcut'] && !e.repeat) {
53+
if (e.key.toLowerCase() === options['toggle-shortcut'] && !e.repeat) {
5454
// Execute in current microtask
5555
e.stopImmediatePropagation();
5656
e.stopPropagation();
@@ -102,6 +102,7 @@ export const insetLyricsBtn = async () => {
102102

103103
btnWrapper.style.display = 'flex';
104104
const lyricsBtn = likeBtn.cloneNode(true) as HTMLButtonElement;
105+
(window as any).lyricsBtn = lyricsBtn;
105106
lyricsBtn.classList.add(localConfig.LYRICS_CLASSNAME);
106107

107108
lyricsBtn.disabled = false;

Diff for: src/popup/elements/root.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { i18n } from '../../i18n';
99
import './list';
1010

1111
window.addEventListener('keydown', (e) => {
12-
if (e.key === 'i') {
12+
if (e.key.toLowerCase() === 'i') {
1313
const id = Number(prompt('Enter NetEase Cloud Music ID:'));
1414
if (id) changeSong(id);
1515
}

0 commit comments

Comments
 (0)