mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
分离插件方法
This commit is contained in:
1 parent
044e75fb73
commit
2eb76650ba
4 files changed
+66
-30
No files matched your search
@@ -21,6 +21,7 @@ import Notice from './notice';
|
||||
import Mask from './mask';
|
||||
import Setting from './setting';
|
||||
import Storage from './storage';
|
||||
import Plugins from './plugins';
|
||||
|
||||
let id = 0;
|
||||
class Artplayer extends Emitter {
|
||||
@@ -125,24 +126,11 @@ class Artplayer extends Emitter {
|
||||
this.hotkey = new Hotkey(this);
|
||||
this.mask = new Mask(this);
|
||||
this.setting = new Setting(this);
|
||||
this.plugins = new Plugins(this);
|
||||
|
||||
id += 1;
|
||||
this.id = id;
|
||||
Artplayer.instances.push(this);
|
||||
|
||||
this.plugins = [];
|
||||
this.option.plugins.forEach((plugin, index) => {
|
||||
const resule = plugin(this);
|
||||
let pluginName = '';
|
||||
if (resule && resule.name) {
|
||||
pluginName = resule.name;
|
||||
} else if (plugin.name) {
|
||||
pluginName = plugin.name;
|
||||
} else {
|
||||
pluginName = `plugin${index}`;
|
||||
}
|
||||
this.plugins[pluginName] = resule;
|
||||
});
|
||||
}
|
||||
|
||||
destroy(removeHtml = false) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export default class Plugins {
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
this.id = 0;
|
||||
art.option.plugins.forEach(plugin => {
|
||||
this.add(plugin);
|
||||
});
|
||||
}
|
||||
|
||||
add(plugin) {
|
||||
this.id += 1;
|
||||
const result = plugin.call(this, this.art);
|
||||
let pluginName = '';
|
||||
if (result && result.name) {
|
||||
pluginName = result.name;
|
||||
} else if (plugin.name) {
|
||||
pluginName = plugin.name;
|
||||
} else {
|
||||
pluginName = `plugin${this.id}`;
|
||||
}
|
||||
this[pluginName] = result;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user