-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_plugins.js
43 lines (34 loc) · 986 Bytes
/
simple_plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
/**
Created by Complynx on 22.03.2019,
http://complynx.net
<[email protected]> Daniel Drizhuk
*/
import {isString, isFunction} from "./type_checks.js";
let plugins = {};
export {plugins};
export function plugin_call(plugin, method, ...args) {
if (isString(plugin)) plugin = plugins[plugin];
let field = plugin[method];
if (field)
return isFunction(field) ? field.apply(plugin, args) : field;
}
export function plugins_call() {
let results = {};
for (let plug_id in plugins) {
let res = plugin_call.call(this, plug_id, ...arguments);
if (res !== undefined) results[plug_id] = res;
}
return results;
}
export function process_node(node, params) {
if (!node.tagName) return;
plugins_call('process_node', node, params);
}
export function process_mutations(mutations) {
for (let i of mutations) {
if(i.addedNodes) for (let j of i.addedNodes) {
process_node(j);
}
}
}