TS重构
This commit is contained in:
parent
e7bece004f
commit
44d6c283c7
7
package-lock.json
generated
7
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -25,6 +25,11 @@
|
||||
"integrity": "sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "4.8.3",
|
||||
"resolved": "https://registry.npmmirror.com/typescript/-/typescript-4.8.3.tgz",
|
||||
"integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig=="
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.16.1",
|
||||
"resolved": "https://registry.npmmirror.com/uglify-js/-/uglify-js-3.16.1.tgz",
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.5.1",
|
||||
"dependencies": {
|
||||
"uglify-js": "^3.16.1"
|
||||
"uglify-js": "^3.16.1",
|
||||
"typescript": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"release": "npm run minify && node build.js",
|
||||
|
||||
@ -179,7 +179,7 @@ z-index: 999999;}`);
|
||||
else {
|
||||
node_link.remove();
|
||||
node_link = null;
|
||||
log('已移除GT助手');
|
||||
log.info('已移除GT助手');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -24,11 +24,9 @@ export default async function travelHelper(glob: Global): Promise<null> {
|
||||
if (country === 'torn') {
|
||||
dest_cn = '回城';
|
||||
} else {
|
||||
dest_cn = {
|
||||
'uk': "英国", 'switzerland': "瑞士", 'mexico': '墨西哥', 'canada': '加拿大', 'cayman': '开曼',
|
||||
dest_cn = {'uk': "英国", 'switzerland': "瑞士", 'mexico': '墨西哥', 'canada': '加拿大', 'cayman': '开曼',
|
||||
'hawaii': '夏威夷', 'argentina': '阿根廷',
|
||||
'japan': '日本', 'china': '中国', 'uae': 'UAE', 'sa': '南非',
|
||||
}[country] || country;
|
||||
'japan': '日本', 'china': '中国', 'uae': 'UAE', 'sa': '南非',}[country] || country;
|
||||
}
|
||||
|
||||
// 剩余时间
|
||||
|
||||
@ -775,7 +775,7 @@ export default function eventsTrans(events: JQuery = $('span.mail-link')) {
|
||||
prePos = node3Spl[0].slice(14, node3Spl[0].length);
|
||||
curPos = node3Spl[1].slice(0, node3Spl[1].length - 2);
|
||||
} else {
|
||||
log('职位出现" to "');// todo
|
||||
log.info('职位出现" to "');// todo
|
||||
return;
|
||||
}
|
||||
e.firstChild.nodeValue = '你在 ';
|
||||
|
||||
@ -279,15 +279,8 @@ export default function translateMain(href: string): void {
|
||||
// 飞行页面
|
||||
if (href.includes('index.php') &&
|
||||
!!document.querySelector('div.travelling h4')) {
|
||||
const travelOB = new MutationObserver(travelOBInit);
|
||||
|
||||
function travelOBInit() {
|
||||
travelOB.disconnect();
|
||||
travelTrans();
|
||||
travelOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function travelTrans() {
|
||||
let travelTrans = function travelTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
|
||||
@ -308,7 +301,13 @@ export default function translateMain(href: string): void {
|
||||
node.text('于 ' + landingTime + ' 降落');
|
||||
}
|
||||
}
|
||||
let travelOBInit = function travelOBInit() {
|
||||
travelOB.disconnect();
|
||||
travelTrans();
|
||||
travelOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const travelOB = new MutationObserver(travelOBInit);
|
||||
travelTrans();
|
||||
travelOB.observe(document.querySelector('div.content-wrapper'), { childList: true, subtree: true });
|
||||
}
|
||||
@ -362,15 +361,8 @@ export default function translateMain(href: string): void {
|
||||
|
||||
// city
|
||||
if (href.includes('city.php')) {
|
||||
const cityOB = new MutationObserver(cityOBInit);
|
||||
|
||||
function cityOBInit() {
|
||||
cityOB.disconnect();
|
||||
cityTrans();
|
||||
cityOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function cityTrans() {
|
||||
let cityTrans = function cityTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
|
||||
@ -435,7 +427,13 @@ export default function translateMain(href: string): void {
|
||||
$(e).text(cityDict[$(e).text()]);
|
||||
});
|
||||
}
|
||||
let cityOBInit = function cityOBInit() {
|
||||
cityOB.disconnect();
|
||||
cityTrans();
|
||||
cityOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const cityOB = new MutationObserver(cityOBInit);
|
||||
cityTrans();
|
||||
cityOB.observe(document.querySelector('div.content-wrapper'), { childList: true, subtree: true });
|
||||
return;
|
||||
@ -443,15 +441,8 @@ export default function translateMain(href: string): void {
|
||||
|
||||
// gym健身房页面
|
||||
if (href.includes('gym.php')) {
|
||||
const gymOB = new MutationObserver(gymOBInit);
|
||||
|
||||
function gymOBInit() {
|
||||
gymOB.disconnect();
|
||||
gymTrans();
|
||||
gymOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true, attributes: true });
|
||||
}
|
||||
|
||||
function gymTrans() {
|
||||
let gymTrans = function gymTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
const gymName = $('div[class^="notificationText"] b').text();
|
||||
@ -550,7 +541,13 @@ export default function translateMain(href: string): void {
|
||||
$(e).text(gymDict[$(e).text().trim()]);
|
||||
});
|
||||
}
|
||||
let gymOBInit = function gymOBInit() {
|
||||
gymOB.disconnect();
|
||||
gymTrans();
|
||||
gymOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true, attributes: true });
|
||||
}
|
||||
|
||||
const gymOB = new MutationObserver(gymOBInit);
|
||||
gymTrans();
|
||||
gymOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true, attributes: true });
|
||||
return;
|
||||
@ -737,15 +734,16 @@ export default function translateMain(href: string): void {
|
||||
$title.forEach(el => {
|
||||
el.childNodes.forEach(e => {
|
||||
if (e.nodeType === 1) {
|
||||
if (npcShopDict[e.innerText.trim()]) {
|
||||
e.innerText = npcShopDict[e.innerText.trim()];
|
||||
let node = e as HTMLElement;
|
||||
if (npcShopDict[node.innerText.trim()]) {
|
||||
node.innerText = npcShopDict[node.innerText.trim()];
|
||||
return;
|
||||
}
|
||||
const spl = e.innerText.trim().split(' ');
|
||||
const spl = node.innerText.trim().split(' ');
|
||||
if (spl.length > 3) {
|
||||
const shop_name = spl[2] === 'the' ? spl.slice(3).join(' ') : spl.slice(2).join(' ');
|
||||
const shop_name_trans = npcShopDict[shop_name] || titleDict[shop_name] || cityDict[shop_name] || null;
|
||||
e.innerText = `物品给${ shop_name_trans || shop_name }`;
|
||||
node.innerText = `物品给${ shop_name_trans || shop_name }`;
|
||||
}
|
||||
} else {
|
||||
if (npcShopDict[e.nodeValue.trim()]) e.nodeValue = npcShopDict[e.nodeValue.trim()];
|
||||
@ -915,15 +913,8 @@ export default function translateMain(href: string): void {
|
||||
|
||||
// 教育页面
|
||||
if (href.indexOf('education.php') >= 0) {
|
||||
const eduOB = new MutationObserver(eduOBInit);
|
||||
|
||||
function eduOBInit() {
|
||||
eduOB.disconnect();
|
||||
eduTrans();
|
||||
eduOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function eduTrans() {
|
||||
let eduTrans = function eduTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
|
||||
@ -1003,7 +994,13 @@ export default function translateMain(href: string): void {
|
||||
}
|
||||
});
|
||||
}
|
||||
let eduOBInit = function eduOBInit() {
|
||||
eduOB.disconnect();
|
||||
eduTrans();
|
||||
eduOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const eduOB = new MutationObserver(eduOBInit);
|
||||
eduTrans();
|
||||
eduOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
return;
|
||||
@ -1096,7 +1093,7 @@ export default function translateMain(href: string): void {
|
||||
}
|
||||
} else {
|
||||
if ($('.wh-translated').length <= 0) {
|
||||
log(`未找到翻译: “${ action_desc.text().trim() }”`);
|
||||
log.info(`未找到翻译: “${ action_desc.text().trim() }”`);
|
||||
}
|
||||
}
|
||||
// 添加敌人或朋友的界面
|
||||
@ -1233,13 +1230,9 @@ export default function translateMain(href: string): void {
|
||||
|
||||
// 报纸
|
||||
if (href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) {
|
||||
const newspaperOB = new MutationObserver(() => {
|
||||
newspaperOB.disconnect();
|
||||
newspaperTrans();
|
||||
newspaperOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
});
|
||||
|
||||
function newspaperTrans() {
|
||||
|
||||
let newspaperTrans = function newspaperTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
if ($('a.newspaper-link').length === 0) return;
|
||||
@ -1413,7 +1406,11 @@ export default function translateMain(href: string): void {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const newspaperOB = new MutationObserver(() => {
|
||||
newspaperOB.disconnect();
|
||||
newspaperTrans();
|
||||
newspaperOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
});
|
||||
newspaperTrans();
|
||||
newspaperOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
return;
|
||||
@ -1838,7 +1835,7 @@ export default function translateMain(href: string): void {
|
||||
}
|
||||
});
|
||||
// 展开详细框
|
||||
const $show_item_info = $display_cabinet.querySelector('.show-item-info');
|
||||
const $show_item_info = $display_cabinet.querySelector('.show-item-info') as HTMLElement;
|
||||
showItemInfoTrans($show_item_info);
|
||||
}
|
||||
});
|
||||
@ -1851,15 +1848,8 @@ export default function translateMain(href: string): void {
|
||||
|
||||
// 医院页面
|
||||
if (href.includes("hospitalview.php")) {
|
||||
const hospitalOB = new MutationObserver(hosOBInit);
|
||||
|
||||
function hosOBInit() {
|
||||
hospitalOB.disconnect();
|
||||
hospTrans();
|
||||
hospitalOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function hospTrans() {
|
||||
let hospTrans = function hospTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
|
||||
@ -1901,7 +1891,13 @@ export default function translateMain(href: string): void {
|
||||
}
|
||||
})
|
||||
}
|
||||
let hosOBInit = function hosOBInit() {
|
||||
hospitalOB.disconnect();
|
||||
hospTrans();
|
||||
hospitalOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const hospitalOB = new MutationObserver(hosOBInit);
|
||||
hospTrans();
|
||||
hospitalOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
return;
|
||||
@ -1909,14 +1905,6 @@ export default function translateMain(href: string): void {
|
||||
|
||||
// 帮派页面
|
||||
if (href.includes("actions.php")) {
|
||||
const factionOB = new MutationObserver(factionOBInit);
|
||||
|
||||
function factionOBInit() {
|
||||
factionOB.disconnect();
|
||||
factionTrans();
|
||||
factionOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const factionDict = {
|
||||
"INFO": "信息",
|
||||
"TERRITORY": "地盘",
|
||||
@ -1951,8 +1939,7 @@ export default function translateMain(href: string): void {
|
||||
"Someone attacked": "有人攻击了 ",
|
||||
"Someone hospitalized": "有人暴打了 "
|
||||
}
|
||||
|
||||
function factionTrans() {
|
||||
let factionTrans = function factionTrans() {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
|
||||
@ -1987,7 +1974,7 @@ export default function translateMain(href: string): void {
|
||||
//帮派主要消息日志
|
||||
$('button[class^="tab"] ').each((i, e) => {
|
||||
if ($(e).attr('class').indexOf("active") >= 0) {
|
||||
log($(e).text());
|
||||
log.info($(e).text());
|
||||
switch ($(e).text().trim()) {
|
||||
case "主要消息":
|
||||
$('ul[class^="news-list"] span[class^="info"]').contents().each((i, u) => {
|
||||
@ -1998,7 +1985,7 @@ export default function translateMain(href: string): void {
|
||||
break;
|
||||
case "攻击":
|
||||
$('ul[class^="news-list"] span[class^="info"]').find('*').contents().each((i, u) => {
|
||||
log($(u).text().trim())
|
||||
log.info($(u).text().trim())
|
||||
if (factionDict[$(u).text().trim()]) {
|
||||
u.nodeValue = factionDict[$(u).text().trim()];
|
||||
}
|
||||
@ -2022,7 +2009,13 @@ export default function translateMain(href: string): void {
|
||||
// })
|
||||
|
||||
}
|
||||
let factionOBInit = function factionOBInit() {
|
||||
factionOB.disconnect();
|
||||
factionTrans();
|
||||
factionOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const factionOB = new MutationObserver(factionOBInit);
|
||||
factionTrans();
|
||||
factionOB.observe($('div.content-wrapper')[0], { childList: true, subtree: true });
|
||||
return;
|
||||
|
||||
@ -9,7 +9,7 @@ export default function audioPlay(url: string = 'https://www.torn.com/js/chat/so
|
||||
const audio = new Audio(url);
|
||||
audio.addEventListener("canplaythrough", () => {
|
||||
audio.play()
|
||||
.catch(err => log(err))
|
||||
.catch(err => log.error(err))
|
||||
.then();
|
||||
});
|
||||
}
|
||||
@ -9,7 +9,7 @@ function autoFetchJSON(dest, time = 30) {
|
||||
let obj;
|
||||
const res = COFetch(dest);
|
||||
setInterval(async () => {
|
||||
if (!isWindowActive()) return;
|
||||
if (!window.WHPARAMS.isWindowActive()) return;
|
||||
const res = await COFetch(dest);
|
||||
obj = JSON.parse(res);
|
||||
}, time * 1000);
|
||||
|
||||
@ -48,7 +48,7 @@ async function priceWatcherPt(apikey, lower_price) {
|
||||
}
|
||||
} else {
|
||||
// 查询出错了
|
||||
log('pt查询出错了')
|
||||
log.error('pt查询出错了')
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +72,6 @@ async function priceWatcherXan(apikey, lower_price) {
|
||||
}
|
||||
} else {
|
||||
// 查询出错了
|
||||
log('xan查询出错了')
|
||||
log.info('xan查询出错了')
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,9 @@ import urlMatch from "./urlMatch";
|
||||
(function main() {
|
||||
let started = new Date().getTime();
|
||||
|
||||
if (document.title.toLowerCase().includes('just a moment')) return;
|
||||
if (document.title.toLowerCase().includes('just a moment') ||
|
||||
document.querySelector('#skip-to-content').innerText.toLowerCase().includes('please validate')
|
||||
) return;
|
||||
|
||||
let glob = init();
|
||||
|
||||
|
||||
@ -158,19 +158,19 @@ function initIcon(settings: MenuItemConfig[]): MyHTMLElement {
|
||||
zhong_node.classList.toggle('wh-icon-expanded');
|
||||
const click_func = e => {
|
||||
// e.stopImmediatePropagation();
|
||||
log(e.target);
|
||||
log.info(e.target);
|
||||
if (e.target === zhong_node.querySelector('#wh-trans-icon-btn')) return;
|
||||
if (!zhong_node.contains(e.target)) {
|
||||
log('移除事件监听器');
|
||||
log.info('移除事件监听器');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
zhong_node.classList.remove('wh-icon-expanded');
|
||||
}
|
||||
};
|
||||
if (zhong_node.classList.contains('wh-icon-expanded')) {
|
||||
log('添加事件监听器');
|
||||
log.info('添加事件监听器');
|
||||
document.body.addEventListener('click', click_func);
|
||||
} else {
|
||||
log('移除事件监听器');
|
||||
log.info('移除事件监听器');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
}
|
||||
};
|
||||
@ -751,7 +751,7 @@ background-size: 100% auto !important;
|
||||
`;
|
||||
const popup = popupMsg(html, '价格监视设置');
|
||||
popup.querySelector('button').onclick = () => {
|
||||
const [pt_node, xan_node] = Array.from(popup.querySelectorAll('input[type="number"]'));
|
||||
const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.querySelectorAll('input[type="number"]'));
|
||||
watcher_conf.pt = (pt_node.value as any) | 0;
|
||||
watcher_conf.xan = (xan_node.value as any) | 0;
|
||||
if (JSON.stringify(watcher_conf) !== pre_str) setWhSetting('priceWatcher', watcher_conf);
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
"es2015",
|
||||
"ES2021.String"
|
||||
],
|
||||
"target": "es5"
|
||||
"target": "ES5",
|
||||
"removeComments": true,
|
||||
"sourceMap": false,
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user