Skip to content

Commit

Permalink
修正了 2.10.X 无法继续播放音乐的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-xmh committed Jun 24, 2023
1 parent 9a4d290 commit 4b0ab07
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 85 deletions.
74 changes: 37 additions & 37 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
],
"description": "类 Apple Music 歌词页面插件|近乎完美的 Apple Music 歌词体验",
"preview": "preview.svg",
"version": "2.1.3",
"commit": "5986c3ede2036ed66036efcb854b178eab141fcc",
"version": "2.1.4",
"commit": "9a4d290ab13d48b06b12f2c3311d1d88ccb7edd2",
"type": "extension",
"noDevReload": true,
"ncm3-compatible": true,
Expand All @@ -29,7 +29,9 @@
"id": "csp-worker",
"from": "<meta http-equiv=\"Content-Security-Policy\" content=\"script-src ",
"to": "<meta http-equiv=\"Content-Security-Policy\" content=\"script-src data: blob: "
},
}
},
">= 3.0.0": {
"orpheus://orpheus/pub/hybrid/vendors": {
"type": "replace",
"id": "redux-dispatch-hook",
Expand Down
6 changes: 4 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"description": "类 Apple Music 歌词页面插件|近乎完美的 Apple Music 歌词体验",
"preview": "preview.svg",
"version": "2.1.3",
"version": "2.1.4",
"commit": "!SET_BY_BUILD_SCRIPT!",
"type": "extension",
"noDevReload": true,
Expand All @@ -29,7 +29,9 @@
"id": "csp-worker",
"from": "<meta http-equiv=\"Content-Security-Policy\" content=\"script-src ",
"to": "<meta http-equiv=\"Content-Security-Policy\" content=\"script-src data: blob: "
},
}
},
">= 3.0.0": {
"orpheus://orpheus/pub/hybrid/vendors": {
"type": "replace",
"id": "redux-dispatch-hook",
Expand Down
17 changes: 0 additions & 17 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,6 @@ window.addEventListener(
},
);

if (OPEN_PAGE_DIRECTLY) {
window.addEventListener(
"load",
() => {
const btn = document.querySelector<HTMLAnchorElement>(
"a[data-action='max']",
);
btn?.click();
},
{
once: true,
},
);
}

reloadStylesheet(cssContent);

export const useStyles = createStyles;

export const ThemeProvider: React.FC<React.PropsWithChildren> = (props) => {
Expand Down
40 changes: 27 additions & 13 deletions src/utils/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNCMV3 } from ".";
import { log, warn } from "./logger";
import { warn } from "./logger";

const registeredEvt = new Set<string>();
const callbacks = new Map<string, Set<Function>>();
Expand All @@ -19,29 +19,43 @@ export const appendRegisterCall = (
name: string,
namespace: string,
callback: Function,
) => appendRegisterCallRaw(`${namespace}.on${name}`, callback);
) =>
isNCMV3()
? appendRegisterCallRaw(`${namespace}.on${name}`, callback)
: legacyNativeCmder.appendRegisterCall(name, namespace, callback);

export const appendRegisterCallRaw = (name: string, callback: Function) => {
if (!registeredEvt.has(name)) {
registeredEvt.add(name);
channel.registerCall(name, (...args) => {
onRegisterCallEvent(name, args);
});
if (isNCMV3()) {
if (!registeredEvt.has(name)) {
registeredEvt.add(name);
channel.registerCall(name, (...args) => {
onRegisterCallEvent(name, args);
});
}
if (!callbacks.has(name)) callbacks.set(name, new Set());
callbacks.get(name)?.add(callback);
} else {
throw new TypeError("该功能在 3.0.0 之前不支持");
}
if (!callbacks.has(name)) callbacks.set(name, new Set());
callbacks.get(name)?.add(callback);
};

export const removeRegisterCall = (
name: string,
namespace: string,
callback: Function,
) => removeRegisterCallRaw(`${namespace}.on${name}`, callback);
) =>
isNCMV3()
? removeRegisterCallRaw(`${namespace}.on${name}`, callback)
: legacyNativeCmder.removeRegisterCall(name, namespace, callback);

export const removeRegisterCallRaw = (name: string, callback: Function) => {
if (callbacks.has(name)) {
callbacks.get(name)?.delete(callback);
if (callbacks.get(name)?.size === 0) callbacks.delete(name);
if (isNCMV3()) {
if (callbacks.has(name)) {
callbacks.get(name)?.delete(callback);
if (callbacks.get(name)?.size === 0) callbacks.delete(name);
}
} else {
throw new TypeError("该功能在 3.0.0 之前不支持");
}
};

Expand Down
23 changes: 10 additions & 13 deletions src/utils/page-injector/v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import { NCMEnvWrapper } from "../../components/netease-api-wrapper";
import { LyricView } from "../../components/lyric-player";
import { log } from "../logger";

let hideTimer: number = 0;

export let mainViewElement: HTMLDivElement = document.createElement("div");
mainViewElement.id = "applemusic-like-lyrics-view";
let mainViewRoot: Root;

export let fmViewElement: HTMLDivElement = document.createElement("div");
fmViewElement.id = "applemusic-like-lyrics-view-fm";
let fmViewRoot: Root;

const FMPlayerWrapper: React.FC = () => {
const [height, setHeight] = React.useState(0);

Expand Down Expand Up @@ -55,16 +65,6 @@ const FMPlayerWrapper: React.FC = () => {
);
};

let hideTimer: number = 0;

export let mainViewElement: HTMLDivElement = document.createElement("div");
mainViewElement.id = "applemusic-like-lyrics-view";
let mainViewRoot: Root;

export let fmViewElement: HTMLDivElement = document.createElement("div");
fmViewElement.id = "applemusic-like-lyrics-view-fm";
let fmViewRoot: Root;

const camelToSnakeCase = (str: string) =>
str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);

Expand Down Expand Up @@ -127,10 +127,7 @@ export function initInjector() {
}
setControlsVisibility(true);
hideTimer = setTimeout(() => {
// const lyricPageOpened = !!document.querySelector(".g-singlec-ct.j-fflag");
// if (lyricPageOpened) {
setControlsVisibility(false);
// }
}, (hideDuration || 5) * 1000);
};

Expand Down

0 comments on commit 4b0ab07

Please sign in to comment.