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

47 lines
2.1 KiB
TypeScript

import WuhuBase from "../WuhuBase";
import Log from "../Log";
import WuhuConfig from "../WuhuConfig";
import CommonUtils from "../utils/CommonUtils";
import TornStyleBlock from "../utils/TornStyleBlock";
import TornStyleSwitch from "../utils/TornStyleSwitch";
import FetchUtils from "../utils/FetchUtils";
export default class ProfileHelper extends WuhuBase {
className = 'ProfileHelper';
constructor() {
super();
CommonUtils.addStyle('body.wh-hide_profile_img .profile-image a.profile-image-wrapper .img-wrap img{display:none;}');
let id = document.querySelector('link[rel="canonical"]').getAttribute('href').split('=')[1];
// id获取格式判断
if (!CommonUtils.getInstance().isValidUid(id)) {
Log.error('[ProfileHelper] id格式错误');
}
if (WuhuConfig.get('HideProfileImg')) {
Log.info('[ProfileHelper] 隐藏头像');
document.body.classList.toggle('wh-hide_profile_img');
}
let block = new TornStyleBlock('芜湖助手').insert2Dom();
// 隐藏头像
let hideImgSwitch = new TornStyleSwitch('隐藏头像', WuhuConfig.get('HideProfileImg'));
block.append(hideImgSwitch.getBase());
hideImgSwitch.getInput().addEventListener('change', () => {
document.body.classList.toggle('wh-hide_profile_img');
WuhuConfig.set('HideProfileImg', hideImgSwitch.getInput().checked, true);
});
// 曾用名
let nameHistoryNode;
if (WuhuConfig.get('ShowNameHistory')) {
nameHistoryNode = document.createElement('p');
nameHistoryNode.innerHTML = '曾用名:';
block.append(nameHistoryNode);
FetchUtils.getInstance().getProfile(id).then((res) => {
if (res.userInformation.previousAliases.length > 0) {
res.userInformation.previousAliases.forEach(item => nameHistoryNode.innerHTML += item + ' ');
} else {
nameHistoryNode.innerHTML += '暂无';
}
});
}
}
}