mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-20 09:38:37 +08:00
Add: Load fps plugin snippet
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import util from '../lib/util'
|
||||
import emitter from '../lib/emitter.es6'
|
||||
|
||||
export default [
|
||||
{
|
||||
@@ -39,6 +40,14 @@ export default [
|
||||
body.contentEditable = body.contentEditable !== 'true';
|
||||
},
|
||||
desc: 'Toggle body contentEditable'
|
||||
},
|
||||
{
|
||||
name: 'Load Fps Plugin',
|
||||
fn()
|
||||
{
|
||||
loadPlugin('fps');
|
||||
},
|
||||
desc: 'Display page fps'
|
||||
}
|
||||
];
|
||||
|
||||
@@ -99,3 +108,17 @@ function traverse(root, processor)
|
||||
|
||||
return processor(root);
|
||||
}
|
||||
|
||||
function loadPlugin(name)
|
||||
{
|
||||
let globalName = 'eruda' + util.upperFirst(name);
|
||||
if (window[globalName]) return;
|
||||
|
||||
util.loadJs('//cdn.jsdelivr.net/npm/eruda-' + name, (isLoaded) =>
|
||||
{
|
||||
if (!isLoaded || !window[globalName]) return emitter.emit(emitter.LOG, 'error', 'Fail to load plugin ' + name);
|
||||
|
||||
emitter.emit(emitter.ADD, window[globalName]);
|
||||
emitter.emit(emitter.SHOW, name);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import Features from './Features/Features.es6'
|
||||
import Sources from './Sources/Sources.es6'
|
||||
import Settings from './Settings/Settings.es6'
|
||||
import util from './lib/util'
|
||||
import emitter from './lib/emitter.es6'
|
||||
import config from './lib/config.es6'
|
||||
import logger from './lib/logger.es6'
|
||||
import extraUtil from './lib/extraUtil.es6'
|
||||
@@ -25,6 +26,7 @@ module.exports = {
|
||||
this._initEntryBtn();
|
||||
this._initSettings();
|
||||
this._initTools(tool);
|
||||
this._registerListener();
|
||||
},
|
||||
_isInit: false,
|
||||
version: VERSION,
|
||||
@@ -66,6 +68,11 @@ module.exports = {
|
||||
|
||||
return this;
|
||||
},
|
||||
_registerListener()
|
||||
{
|
||||
emitter.on(emitter.ADD, (...args) => this.add(...args));
|
||||
emitter.on(emitter.SHOW, (...args) => this.show(...args));
|
||||
},
|
||||
_checkInit()
|
||||
{
|
||||
if (!this._isInit) logger.error('Please call "eruda.init()" first');
|
||||
|
||||
8
src/lib/emitter.es6
Normal file
8
src/lib/emitter.es6
Normal file
@@ -0,0 +1,8 @@
|
||||
import util from './util'
|
||||
|
||||
let emitter = new util.Emitter();
|
||||
emitter.ADD = 'ADD';
|
||||
emitter.LOG = 'LOG';
|
||||
emitter.SHOW = 'SHOW';
|
||||
|
||||
module.exports = emitter;
|
||||
@@ -1,4 +1,5 @@
|
||||
import util from './util'
|
||||
import emitter from './emitter.es6'
|
||||
|
||||
let logger;
|
||||
|
||||
@@ -10,3 +11,5 @@ logger.formatter = function (type, argList)
|
||||
|
||||
return argList;
|
||||
};
|
||||
|
||||
emitter.on(emitter.LOG, (type, ...args) => logger[type](...args));
|
||||
|
||||
Reference in New Issue
Block a user