更新
This commit is contained in:
parent
975f9f2e80
commit
f929b5c6b1
@ -9,6 +9,8 @@ import SidebarHelper from "./action/SidebarHelper";
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
import Log from "./Log";
|
||||
import FetchUtils from "./utils/FetchUtils";
|
||||
import ZhongIcon from "./ZhongIcon";
|
||||
import Alert from "./utils/Alert";
|
||||
|
||||
export class Common extends WuhuBase {
|
||||
className = 'Common';
|
||||
@ -74,5 +76,21 @@ export class Common extends WuhuBase {
|
||||
Log.info('应用自定义CSS');
|
||||
CommonUtils.addStyle(WuhuConfig.get('CustomCss'));
|
||||
}
|
||||
|
||||
// 现金变动提醒
|
||||
if (WuhuConfig.get('CashChangeAlert')) CommonUtils.elementReady("#user-money").then(userMoney => {
|
||||
new MutationObserver((mutations, observer) => {
|
||||
Log.info("现金变动提醒", mutations);
|
||||
mutations.forEach(item => {
|
||||
if (item.attributeName === 'data-money') {
|
||||
ZhongIcon.getInstance().updateCashView(userMoney.innerText);
|
||||
new Alert(
|
||||
'提醒: 现金变动 ' + item.oldValue + ' -> ' + userMoney.innerText,
|
||||
{ sysNotify: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
}).observe(userMoney, { attributes: true, attributeOldValue: true })
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +121,10 @@ export default class WuhuConfig extends WuhuBase {
|
||||
{ key: 'IconPosition', val: {} },
|
||||
// 记住图标位置
|
||||
{ key: 'SaveIconPosition', val: false },
|
||||
// 现金变动提醒
|
||||
{ key: 'CashChangeAlert', val: false },
|
||||
// 收集数据以改进翻译质量
|
||||
{ key: 'CollectPlayerData', val: true },
|
||||
|
||||
/**
|
||||
* 危险行为⚠️
|
||||
|
||||
@ -27,6 +27,7 @@ export default class ZhongIcon extends WuhuBase {
|
||||
className = 'ZhongIcon';
|
||||
public static ZhongNode: MyHTMLElement = null;
|
||||
private menuItemList: MenuItemConfig[] = null;
|
||||
private cashView: HTMLElement = null;
|
||||
|
||||
// private settingItemList: MenuItemConfig[] = null;
|
||||
|
||||
@ -52,6 +53,168 @@ export default class ZhongIcon extends WuhuBase {
|
||||
}
|
||||
}
|
||||
|
||||
public updateCashView(content: string): void {
|
||||
if (!this.cashView || !ZhongIcon.ZhongNode.contains(this.cashView)) {
|
||||
this.cashView = document.createElement('div');
|
||||
this.cashView.id = 'wh-cash-monitor';
|
||||
ZhongIcon.ZhongNode.append(this.cashView);
|
||||
}
|
||||
this.cashView.innerText = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加左侧图标
|
||||
*/
|
||||
private insert2Dom(): ZhongIcon {
|
||||
let zhongNode: MyHTMLElement = document.querySelector('div#wh-trans-icon');
|
||||
let settings = this.menuItemList;
|
||||
let { version } = WuhuBase.glob;
|
||||
if ((self !== top) || !!zhongNode) return null;
|
||||
zhongNode = document.createElement('div');
|
||||
ZhongIcon.ZhongNode = zhongNode;
|
||||
zhongNode.id = 'wh-trans-icon';
|
||||
zhongNode.classList.add('cont-gray');
|
||||
zhongNode.innerHTML = ZHONG_MENU_HTML.replace('{{}}', version.slice(-1) === '$' ? 'DEV' : version);
|
||||
// 助手菜单
|
||||
const menu_cont = zhongNode.querySelector('#wh-gSettings');
|
||||
// 遍历菜单node设置、生成node、插入dom
|
||||
this.menuItemList.forEach(setting => CommonUtils.getInstance().elemGenerator(setting, menu_cont));
|
||||
Log.info('生成元素插入完成');
|
||||
// 计时node
|
||||
zhongNode.initTimer = zhongNode.querySelector('#wh-inittimer');
|
||||
// 芜湖助手图标点击事件
|
||||
(<MyHTMLElement>zhongNode.querySelector('#wh-trans-icon-btn')).onclick = () => {
|
||||
zhongNode.classList.toggle('wh-icon-expanded');
|
||||
const click_func = e => {
|
||||
Log.info(e.target);
|
||||
if (e.target === zhongNode.querySelector('#wh-trans-icon-btn')) return;
|
||||
if (!zhongNode.contains(e.target)) {
|
||||
Log.info('移除事件监听器');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
zhongNode.classList.remove('wh-icon-expanded');
|
||||
}
|
||||
};
|
||||
if (zhongNode.classList.contains('wh-icon-expanded')) {
|
||||
Log.info('芜湖助手图标点击->添加监听');
|
||||
document.body.addEventListener('click', click_func);
|
||||
} else {
|
||||
Log.info('芜湖助手图标->移除监听');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
}
|
||||
};
|
||||
// 更新按钮点击事件
|
||||
(<MyHTMLElement>zhongNode.querySelector('#wh-update-btn')).onclick = e => {
|
||||
(<HTMLButtonElement>e.target).blur();
|
||||
const innerHtml = ZHONG_UPDATE_HTML;
|
||||
// 直接复制的按钮
|
||||
new Popup(innerHtml, '如何更新')
|
||||
.getElement()
|
||||
.querySelector('button').onclick = async (e) => {
|
||||
let target = e.target as HTMLButtonElement;
|
||||
target.innerHTML = '加载中';
|
||||
const js_text = await CommonUtils.COFetch(`https://jjins.github.io/fyfuzhi/release.min.user.js?${ performance.now() }`);
|
||||
target.innerHTML = '点击复制到剪切板';
|
||||
target.onclick = () => {
|
||||
const textarea_node = document.createElement('textarea');
|
||||
textarea_node.innerHTML = js_text;
|
||||
target.parentElement.append(textarea_node);
|
||||
textarea_node.focus();
|
||||
textarea_node.select();
|
||||
document.execCommand('Copy');
|
||||
textarea_node.remove();
|
||||
target.innerHTML = '已复制';
|
||||
target.onclick = null;
|
||||
new Alert('脚本已复制,请前往粘贴');
|
||||
};
|
||||
};
|
||||
};
|
||||
// 节日
|
||||
zhongNode.querySelectorAll('#wh-trans-fest-date button').forEach((el, i) => i === 0
|
||||
? el.addEventListener('click', () => {
|
||||
let html = '<table>';
|
||||
settings.fest_date_list.sort().forEach(date =>
|
||||
html += `<tr><td>${ 1 + ((<any>date.slice(0, 2)) | 0) }月${ date.slice(2) }日</td><td>${ settings.fest_date_dict[date].name }</td><td>${ settings.fest_date_dict[date].eff }</td></tr>`
|
||||
);
|
||||
new Popup(html += '</table>', '节日');
|
||||
})
|
||||
: el.addEventListener('click', null));
|
||||
// 活动
|
||||
zhongNode.querySelectorAll('#wh-trans-event-cont button').forEach((el, i) => i === 0
|
||||
? el.addEventListener('click', () => {
|
||||
let html = '<table>';
|
||||
settings.events.forEach(el =>
|
||||
html += `<tr><td><b>${ el.name }</b></td><td>${ el.start[0] + 1 }月${ el.start[1] }日${ el.start[2] }:00~${ el.end[0] + 1 }月${ el.end[1] }日${ el.end[2] }:00</td></tr><tr><td colspan="2">${ el.eff }</td></tr>`);
|
||||
new Popup(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
|
||||
})
|
||||
: el.addEventListener('click', null));
|
||||
// 调整图标至有记录的位置
|
||||
if (WuhuConfig.get("SaveIconPosition")) {
|
||||
let iconPosition = WuhuConfig.get("IconPosition");
|
||||
let documentSize = { x: document.documentElement.offsetWidth, y: document.documentElement.offsetHeight };
|
||||
ZhongIcon.setPosition(
|
||||
iconPosition.x > documentSize.x ? documentSize.x * 0.9 | 0 : iconPosition.x,
|
||||
iconPosition.y > documentSize.y ? documentSize.y * 0.9 | 0 : iconPosition.y
|
||||
);
|
||||
}
|
||||
document.body.append(zhongNode);
|
||||
// 引入torn自带浮动提示
|
||||
Log.info('引入torn自带浮动提示');
|
||||
(window.initializeTooltip) && (window.initializeTooltip('.wh-container', 'white-tooltip'));
|
||||
// 加载torn mini profile
|
||||
Log.info('加载torn mini profile');
|
||||
let miniProfileInterval = {
|
||||
id: window.setInterval(() => {
|
||||
miniProfileInterval.counter++;
|
||||
if (window.$ || (window.unsafeWindow && window.unsafeWindow.$)) {
|
||||
initMiniProf('#wh-trans-icon');
|
||||
window.clearInterval(miniProfileInterval.id);
|
||||
}
|
||||
if (miniProfileInterval.counter > 30) window.clearInterval(miniProfileInterval.id);
|
||||
}, 1000),
|
||||
counter: 0
|
||||
};
|
||||
Log.info('图标加入文档树完成');
|
||||
return this;
|
||||
}
|
||||
|
||||
private dragHandler(): ZhongIcon {
|
||||
let isMouseDown = false;
|
||||
let isMouseMoved = false;
|
||||
let offsetXY = { x: 0, y: 0 };
|
||||
ZhongIcon.ZhongNode.addEventListener('mousedown', (e) => {
|
||||
if (e.button === 0) {
|
||||
e.preventDefault();
|
||||
isMouseDown = true;
|
||||
let nodeXY = ZhongIcon.getPosition();
|
||||
offsetXY.x = e.x - nodeXY.x;
|
||||
offsetXY.y = e.y - nodeXY.y;
|
||||
}
|
||||
});
|
||||
document.addEventListener('mouseup', () => {
|
||||
isMouseDown = false;
|
||||
if (isMouseMoved) {
|
||||
isMouseMoved = false;
|
||||
if (WuhuConfig.get("SaveIconPosition")) {
|
||||
WuhuConfig.set("IconPosition", ZhongIcon.getPosition());
|
||||
}
|
||||
}
|
||||
});
|
||||
document.addEventListener('mousemove', (e) => {
|
||||
if (isMouseDown) {
|
||||
ZhongIcon.setPosition(e.x - offsetXY.x, e.y - offsetXY.y);
|
||||
isMouseMoved = true;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
private static getPosition(): { x: number, y: number } {
|
||||
return {
|
||||
x: ZhongIcon.ZhongNode.style.left ? parseInt(ZhongIcon.ZhongNode.style.left.slice(0, -2)) : ZhongIcon.ZhongNode.offsetLeft,
|
||||
y: ZhongIcon.ZhongNode.style.top ? parseInt(ZhongIcon.ZhongNode.style.top.slice(0, -2)) : ZhongIcon.ZhongNode.offsetTop
|
||||
}
|
||||
}
|
||||
|
||||
// 菜单
|
||||
private constructMenuList(): ZhongIcon {
|
||||
Log.info('构造展开菜单列表开始');
|
||||
@ -209,7 +372,7 @@ export default class ZhongIcon extends WuhuBase {
|
||||
});
|
||||
// 全屏
|
||||
if (!Global.getInstance().isPDA) list.push({
|
||||
domType: 'button', domId: '', domText: '🖥 进入全屏', clickFunc() {
|
||||
domType: 'button', domId: '', domText: '🖥️ 进入全屏', clickFunc() {
|
||||
document.documentElement.requestFullscreen().then();
|
||||
}
|
||||
});
|
||||
@ -274,159 +437,6 @@ export default class ZhongIcon extends WuhuBase {
|
||||
Log.info('构造展开菜单列表结束' + timer.getTimeMs());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加左侧图标
|
||||
*/
|
||||
private insert2Dom(): ZhongIcon {
|
||||
let zhongNode: MyHTMLElement = document.querySelector('div#wh-trans-icon');
|
||||
let settings = this.menuItemList;
|
||||
let { version } = WuhuBase.glob;
|
||||
if ((self !== top) || !!zhongNode) return null;
|
||||
zhongNode = document.createElement('div');
|
||||
ZhongIcon.ZhongNode = zhongNode;
|
||||
zhongNode.id = 'wh-trans-icon';
|
||||
zhongNode.classList.add('cont-gray');
|
||||
zhongNode.innerHTML = ZHONG_MENU_HTML.replace('{{}}', version.slice(-1) === '$' ? 'DEV' : version);
|
||||
// 助手菜单
|
||||
const menu_cont = zhongNode.querySelector('#wh-gSettings');
|
||||
// 遍历菜单node设置、生成node、插入dom
|
||||
this.menuItemList.forEach(setting => CommonUtils.getInstance().elemGenerator(setting, menu_cont));
|
||||
Log.info('生成元素插入完成');
|
||||
// 计时node
|
||||
zhongNode.initTimer = zhongNode.querySelector('#wh-inittimer');
|
||||
// 芜湖助手图标点击事件
|
||||
(<MyHTMLElement>zhongNode.querySelector('#wh-trans-icon-btn')).onclick = () => {
|
||||
zhongNode.classList.toggle('wh-icon-expanded');
|
||||
const click_func = e => {
|
||||
Log.info(e.target);
|
||||
if (e.target === zhongNode.querySelector('#wh-trans-icon-btn')) return;
|
||||
if (!zhongNode.contains(e.target)) {
|
||||
Log.info('移除事件监听器');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
zhongNode.classList.remove('wh-icon-expanded');
|
||||
}
|
||||
};
|
||||
if (zhongNode.classList.contains('wh-icon-expanded')) {
|
||||
Log.info('芜湖助手图标点击->添加监听');
|
||||
document.body.addEventListener('click', click_func);
|
||||
} else {
|
||||
Log.info('芜湖助手图标->移除监听');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
}
|
||||
};
|
||||
// 更新按钮点击事件
|
||||
(<MyHTMLElement>zhongNode.querySelector('#wh-update-btn')).onclick = e => {
|
||||
(<HTMLButtonElement>e.target).blur();
|
||||
const innerHtml = ZHONG_UPDATE_HTML;
|
||||
// 直接复制的按钮
|
||||
new Popup(innerHtml, '如何更新')
|
||||
.getElement()
|
||||
.querySelector('button').onclick = async (e) => {
|
||||
let target = e.target as HTMLButtonElement;
|
||||
target.innerHTML = '加载中';
|
||||
const js_text = await CommonUtils.COFetch(`https://jjins.github.io/fyfuzhi/release.min.user.js?${ performance.now() }`);
|
||||
target.innerHTML = '点击复制到剪切板';
|
||||
target.onclick = () => {
|
||||
const textarea_node = document.createElement('textarea');
|
||||
textarea_node.innerHTML = js_text;
|
||||
target.parentElement.append(textarea_node);
|
||||
textarea_node.focus();
|
||||
textarea_node.select();
|
||||
document.execCommand('Copy');
|
||||
textarea_node.remove();
|
||||
target.innerHTML = '已复制';
|
||||
target.onclick = null;
|
||||
new Alert('脚本已复制,请前往粘贴');
|
||||
};
|
||||
};
|
||||
};
|
||||
// 节日
|
||||
zhongNode.querySelectorAll('#wh-trans-fest-date button').forEach((el, i) => i === 0
|
||||
? el.addEventListener('click', () => {
|
||||
let html = '<table>';
|
||||
settings.fest_date_list.sort().forEach(date =>
|
||||
html += `<tr><td>${ 1 + ((<any>date.slice(0, 2)) | 0) }月${ date.slice(2) }日</td><td>${ settings.fest_date_dict[date].name }</td><td>${ settings.fest_date_dict[date].eff }</td></tr>`
|
||||
);
|
||||
new Popup(html += '</table>', '节日');
|
||||
})
|
||||
: el.addEventListener('click', null));
|
||||
// 活动
|
||||
zhongNode.querySelectorAll('#wh-trans-event-cont button').forEach((el, i) => i === 0
|
||||
? el.addEventListener('click', () => {
|
||||
let html = '<table>';
|
||||
settings.events.forEach(el =>
|
||||
html += `<tr><td><b>${ el.name }</b></td><td>${ el.start[0] + 1 }月${ el.start[1] }日${ el.start[2] }:00~${ el.end[0] + 1 }月${ el.end[1] }日${ el.end[2] }:00</td></tr><tr><td colspan="2">${ el.eff }</td></tr>`);
|
||||
new Popup(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
|
||||
})
|
||||
: el.addEventListener('click', null));
|
||||
// 调整图标至有记录的位置
|
||||
if (WuhuConfig.get("SaveIconPosition")) {
|
||||
let iconPosition = WuhuConfig.get("IconPosition");
|
||||
let documentSize = { x: document.documentElement.offsetWidth, y: document.documentElement.offsetHeight };
|
||||
ZhongIcon.setPosition(
|
||||
iconPosition.x > documentSize.x ? documentSize.x * 0.9 | 0 : iconPosition.x,
|
||||
iconPosition.y > documentSize.y ? documentSize.y * 0.9 | 0 : iconPosition.y
|
||||
);
|
||||
}
|
||||
document.body.append(zhongNode);
|
||||
// 引入torn自带浮动提示
|
||||
Log.info('引入torn自带浮动提示');
|
||||
(window.initializeTooltip) && (window.initializeTooltip('.wh-container', 'white-tooltip'));
|
||||
// 加载torn mini profile
|
||||
Log.info('加载torn mini profile');
|
||||
let miniProfileInterval = {
|
||||
id: window.setInterval(() => {
|
||||
miniProfileInterval.counter++;
|
||||
if (window.$ || (window.unsafeWindow && window.unsafeWindow.$)) {
|
||||
initMiniProf('#wh-trans-icon');
|
||||
window.clearInterval(miniProfileInterval.id);
|
||||
}
|
||||
if (miniProfileInterval.counter > 30) window.clearInterval(miniProfileInterval.id);
|
||||
}, 1000),
|
||||
counter: 0
|
||||
};
|
||||
Log.info('图标加入文档树完成');
|
||||
return this;
|
||||
}
|
||||
|
||||
private dragHandler(): ZhongIcon {
|
||||
let isMouseDown = false;
|
||||
let isMouseMoved = false;
|
||||
let offsetXY = { x: 0, y: 0 };
|
||||
ZhongIcon.ZhongNode.addEventListener('mousedown', (e) => {
|
||||
if (e.button === 0) {
|
||||
e.preventDefault();
|
||||
isMouseDown = true;
|
||||
let nodeXY = ZhongIcon.getPosition();
|
||||
offsetXY.x = e.x - nodeXY.x;
|
||||
offsetXY.y = e.y - nodeXY.y;
|
||||
}
|
||||
});
|
||||
document.addEventListener('mouseup', () => {
|
||||
isMouseDown = false;
|
||||
if (isMouseMoved) {
|
||||
isMouseMoved = false;
|
||||
if (WuhuConfig.get("SaveIconPosition")) {
|
||||
WuhuConfig.set("IconPosition", ZhongIcon.getPosition());
|
||||
}
|
||||
}
|
||||
});
|
||||
document.addEventListener('mousemove', (e) => {
|
||||
if (isMouseDown) {
|
||||
ZhongIcon.setPosition(e.x - offsetXY.x, e.y - offsetXY.y);
|
||||
isMouseMoved = true;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
private static getPosition(): { x: number, y: number } {
|
||||
return {
|
||||
x: ZhongIcon.ZhongNode.style.left ? parseInt(ZhongIcon.ZhongNode.style.left.slice(0, -2)) : ZhongIcon.ZhongNode.offsetLeft,
|
||||
y: ZhongIcon.ZhongNode.style.top ? parseInt(ZhongIcon.ZhongNode.style.top.slice(0, -2)) : ZhongIcon.ZhongNode.offsetTop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface MenuItemConfig {
|
||||
|
||||
@ -97,6 +97,14 @@ export default class SettingsHandler extends WuhuBase {
|
||||
isTornBtn: true,
|
||||
clickFunc: () => UpdateTranslateDict.getInstance().handle()
|
||||
});
|
||||
// 收集数据以改进翻译质量
|
||||
list.push({
|
||||
domType: 'checkbox',
|
||||
domId: '',
|
||||
domText: ' 收集数据以改进翻译质量',
|
||||
dictName: 'CollectPlayerData',
|
||||
tip: '未实现功能<br/>收集玩家基础信息与页面上(未翻译)的内容上传以改进翻译'
|
||||
});
|
||||
|
||||
// 战斗
|
||||
list.push({
|
||||
@ -414,6 +422,14 @@ export default class SettingsHandler extends WuhuBase {
|
||||
dictName: 'HideSidebarBtn',
|
||||
tip: '仅PC'
|
||||
});
|
||||
// 现金变动提醒
|
||||
list.push({
|
||||
domType: 'checkbox',
|
||||
domId: '',
|
||||
domText: ' 现金变动提醒',
|
||||
dictName: 'CashChangeAlert',
|
||||
tip: '插件图标下方显示现金、现金变动时通知提醒<br/>注: 刷新页面生效、系统级通知需要浏览器权限'
|
||||
});
|
||||
|
||||
// 其他
|
||||
list.push({
|
||||
|
||||
@ -87,6 +87,15 @@ div#effectiveness-wrap {
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
#wh-cash-monitor {
|
||||
margin: 4px 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.wh-icon-expanded #wh-cash-monitor {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#wh-latest-version {
|
||||
display: inline-block;
|
||||
background-image: url("https://jjins.github.io/t2i/version.png?{{}}");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user