mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
feat: migrate to new plugin api
Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
17
src/plugins/compact-sidebar/index.ts
Normal file
17
src/plugins/compact-sidebar/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { createPluginBuilder } from '../utils/builder';
|
||||
|
||||
const builder = createPluginBuilder('compact-sidebar', {
|
||||
name: 'Compact Sidebar',
|
||||
restartNeeded: false,
|
||||
config: {
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default builder;
|
||||
|
||||
declare global {
|
||||
interface PluginBuilderList {
|
||||
[builder.id]: typeof builder;
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,27 @@
|
||||
export default () => {
|
||||
const compactSidebar = document.querySelector('#mini-guide');
|
||||
const isCompactSidebarDisabled
|
||||
= compactSidebar === null
|
||||
|| window.getComputedStyle(compactSidebar).display === 'none';
|
||||
import builder from './index';
|
||||
|
||||
if (isCompactSidebarDisabled) {
|
||||
document.querySelector<HTMLButtonElement>('#button')?.click();
|
||||
}
|
||||
};
|
||||
export default builder.createRenderer(() => {
|
||||
const getCompactSidebar = () => document.querySelector('#mini-guide');
|
||||
const isCompactSidebarDisabled = () => {
|
||||
const compactSidebar = getCompactSidebar();
|
||||
return compactSidebar === null || window.getComputedStyle(compactSidebar).display === 'none';
|
||||
};
|
||||
|
||||
return {
|
||||
onLoad() {
|
||||
if (isCompactSidebarDisabled()) {
|
||||
document.querySelector<HTMLButtonElement>('#button')?.click();
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
if (!isCompactSidebarDisabled()) {
|
||||
document.querySelector<HTMLButtonElement>('#button')?.click();
|
||||
}
|
||||
},
|
||||
onConfigChange() {
|
||||
if (isCompactSidebarDisabled()) {
|
||||
document.querySelector<HTMLButtonElement>('#button')?.click();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user