wuhu-torn-helper/src/ts/class/utils/ActionButtonUtils.ts
2022-12-08 16:20:02 +08:00

25 lines
874 B
TypeScript

import WuhuBase from "../WuhuBase";
import Log from "../Log";
import ZhongIcon from "../ZhongIcon";
export default class ActionButtonUtils extends WuhuBase {
className = 'ActionButtonUtils';
private hasAdded: boolean = false;
public add(txt: string, func: (ev: Event) => void = () => null): void {
if (!this.hasAdded) this.handle(txt, func);
else Log.warn('ActionButton已存在');
}
private handle(txt, func): void {
let btn = document.createElement('button');
btn.style.padding = '8px 13px 8px 0';
btn.style.verticalAlign = 'bottom';
btn.style.color = '#4CAF50';
btn.innerHTML = txt;
btn.addEventListener('click', func);
ZhongIcon.ZhongNode.querySelector('button').after(btn);
this.hasAdded = true;
Log.info('ActionButton已添加', { txt, func, btn });
}
}