添加自动开打和结束战斗

This commit is contained in:
Liwanyi 2022-01-10 16:39:49 +08:00
parent 56852a1229
commit 9ec49b06d5

View File

@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @lastmodified 202201101539 // @lastmodified 202201101639
// @name Torn翻译 // @name Torn翻译
// @namespace WOOH // @namespace WOOH
// @version 0.2.0110a // @version 0.2.0110b
// @description Torn UI翻译 // @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209] // @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
@ -15,13 +15,18 @@
___window___.WHTRANS = true; ___window___.WHTRANS = true;
const CC_set = /[\u4e00-\u9fa5]/; const CC_set = /[\u4e00-\u9fa5]/;
const version = '0.2.0110a'; const version = '0.2.0110b';
const changelist = [ const changelist = [
{ {
todo: true, todo: true,
cont: `翻译baza npc商店、imarket、imarket搜索结果`, cont: `翻译baza npc商店、imarket、imarket搜索结果`,
}, },
{
ver: '0.2.0110b',
date: '20220110',
cont: `添加自动开打和结束战斗`,
},
{ {
ver: '0.2.0110a', ver: '0.2.0110a',
date: '20220110', date: '20220110',
@ -2938,12 +2943,14 @@
// 插件的设置 // 插件的设置
const settingsArr = [ const settingsArr = [
// 开启翻译
{ {
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-trans-enable', domId: 'wh-trans-enable',
domText: ' 开启翻译<span> (施工中)</span>', domText: ' 开启翻译<span> (施工中)</span>',
dictName: 'transEnable', dictName: 'transEnable',
}, },
// 更新词库按钮
{ {
domType: 'button', domType: 'button',
domId: 'wh-trans-data-update', domId: 'wh-trans-data-update',
@ -2981,30 +2988,35 @@
} }
}, },
}, },
// 快速crime
{ {
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-quick-crime', domId: 'wh-quick-crime',
domText: ' 快速犯罪', domText: ' 快速犯罪',
dictName: 'quickCrime', dictName: 'quickCrime',
}, },
// 任务助手
{ {
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-mission-lint', domId: 'wh-mission-lint',
domText: ' 任务助手', domText: ' 任务助手',
dictName: 'missionHint', dictName: 'missionHint',
}, },
// 起飞警告
{ {
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-energy-alert', domId: 'wh-energy-alert',
domText: ' 起飞爆E警告', domText: ' 起飞爆E警告',
dictName: 'energyAlert', dictName: 'energyAlert',
}, },
// 攻击链接转跳
{ {
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-attack-relocate', domId: 'wh-attack-relocate',
domText: ' 真·攻击界面转跳', domText: ' 真·攻击界面转跳',
dictName: 'attRelocate', dictName: 'attRelocate',
}, },
// 攻击界面自刷新
{ {
domType: 'select', domType: 'select',
domId: 'wh-attack-reload', domId: 'wh-attack-reload',
@ -3041,6 +3053,7 @@
}, },
], ],
}, },
// 光速拔刀
{ {
domType: 'select', domType: 'select',
domId: 'wh-quick-attack-index', domId: 'wh-quick-attack-index',
@ -3077,6 +3090,7 @@
], ],
dictName: 'quickAttIndex', dictName: 'quickAttIndex',
}, },
// 光速跑路
{ {
domType: 'select', domType: 'select',
domId: 'wh-quick-mug', domId: 'wh-quick-mug',
@ -3101,6 +3115,14 @@
], ],
dictName: 'quickFinishAtt', dictName: 'quickFinishAtt',
}, },
// 自动开打和结束
{
domType: 'checkbox',
domId: 'wh-auto-start-finish',
domText: ' 自动开打和结束 [慎!!!]',
dictName: 'autoStartFinish',
},
// 飞花库存
{ {
domType: 'button', domType: 'button',
domId: 'wh-foreign-stock-btn', domId: 'wh-foreign-stock-btn',
@ -3111,6 +3133,7 @@
popupMsg(insert, '飞花库存'); popupMsg(insert, '飞花库存');
}, },
}, },
// NPC LOOT
{ {
domType: 'button', domType: 'button',
domId: 'wh-npc-loot-btn', domId: 'wh-npc-loot-btn',
@ -3128,6 +3151,7 @@
popupMsg(insert, 'NPC LOOT'); popupMsg(insert, 'NPC LOOT');
}, },
}, },
// 生存手册
{ {
domType: 'button', domType: 'button',
domId: 'wh-link-shengcunshouce', domId: 'wh-link-shengcunshouce',
@ -3137,12 +3161,14 @@
window.open('https://docs.qq.com/doc/DTVpmV2ZaRnB0RG56'); window.open('https://docs.qq.com/doc/DTVpmV2ZaRnB0RG56');
}, },
}, },
// dev
{ {
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-dev-mode', domId: 'wh-dev-mode',
domText: ' 开发者模式', domText: ' 开发者模式',
dictName: 'isDev', dictName: 'isDev',
}, },
// 更新历史
{ {
domType: 'button', domType: 'button',
domId: 'wh-changeList', domId: 'wh-changeList',
@ -3192,6 +3218,8 @@
{key: 'quickAttIndex', val: 2}, {key: 'quickAttIndex', val: 2},
// 光速跑路 0-leave 1-mug 2-hos 3-关闭 // 光速跑路 0-leave 1-mug 2-hos 3-关闭
{key: 'quickFinishAtt', val: 3}, {key: 'quickFinishAtt', val: 3},
// 自动开打和结束
{key: 'autoStartFinish', val: false},
// 废弃 // 废弃
{key: 'attRelocate', val: true}, {key: 'attRelocate', val: true},
// 攻击自刷新 // 攻击自刷新
@ -3219,6 +3247,8 @@
quickAttIndex: undefined, quickAttIndex: undefined,
// 光速跑路 0-leave 1-mug 2-hos 3-关闭 // 光速跑路 0-leave 1-mug 2-hos 3-关闭
quickFinishAtt: undefined, quickFinishAtt: undefined,
// 自动开打和结束
autoStartFinish: undefined,
// 废弃 // 废弃
attRelocate: undefined, attRelocate: undefined,
// 攻击自刷新 // 攻击自刷新
@ -3803,10 +3833,9 @@ padding: 0.5em 0;
return; return;
} }
/** // 攻击页面
* 攻击页面
*/
if (window.location.href.contains(/loader\.php\?sid=attack/)) { if (window.location.href.contains(/loader\.php\?sid=attack/)) {
let stop_reload = false;
// 光速拔刀 // 光速拔刀
if (wh_trans_settings.quickAttIndex !== 6) { if (wh_trans_settings.quickAttIndex !== 6) {
const selectedId = ['weapon_main', 'weapon_second', 'weapon_melee', 'weapon_temp', 'weapon_fists', 'weapon_boots'] const selectedId = ['weapon_main', 'weapon_second', 'weapon_melee', 'weapon_temp', 'weapon_fists', 'weapon_boots']
@ -3858,6 +3887,8 @@ padding: 0.5em 0;
btn.onclick = () => { btn.onclick = () => {
if (wh_trans_settings.quickFinishAtt !== 3) { if (wh_trans_settings.quickFinishAtt !== 3) {
btn.remove(); btn.remove();
// 停止自动刷新
stop_reload = true;
} else { } else {
document.body.classList.toggle('wh-move-btn'); document.body.classList.toggle('wh-move-btn');
} }
@ -3934,6 +3965,8 @@ padding: 0.5em 0;
btn.onclick = () => { btn.onclick = () => {
if (wh_trans_settings.quickFinishAtt !== 3) { if (wh_trans_settings.quickFinishAtt !== 3) {
btn.remove(); btn.remove();
// 停止自动刷新
stop_reload = true;
} else { } else {
document.body.classList.toggle('wh-move-btn'); document.body.classList.toggle('wh-move-btn');
} }
@ -3944,9 +3977,26 @@ padding: 0.5em 0;
break; break;
} }
} }
// 自动开打
if (wh_trans_settings.autoStartFinish === true) {
if (btn.innerText.includes('(')) {
let interval_id = window.setInterval(() => {
if (!btn) {
clearInterval(interval_id);
return;
}
try {
btn.click();
} catch {
}
}, 100);
} else {
btn.click();
}
}
}); });
const CUR_DISABLED = false; const CUR_DISABLED = true;
if (CUR_DISABLED) { if (!CUR_DISABLED) {
const original_fetch = window.fetch; const original_fetch = window.fetch;
window.fetch = async (url, init) => { window.fetch = async (url, init) => {
let response = await original_fetch(url, init) let response = await original_fetch(url, init)
@ -3968,27 +4018,32 @@ padding: 0.5em 0;
if (isDev()) console.log('光速跑路选项选中:', user_btn_select); if (isDev()) console.log('光速跑路选项选中:', user_btn_select);
new MutationObserver(() => { new MutationObserver(() => {
const btn_arr = document.querySelectorAll('div[class^="dialogButtons___"] button'); const btn_arr = document.querySelectorAll('div[class^="dialogButtons___"] button');
if (btn_arr.length > 2) btn_arr.forEach(btn => { if (btn_arr.length > 1) btn_arr.forEach(btn => {
const flag = btn.innerText.toLowerCase().includes(user_btn_select); const flag = btn.innerText.toLowerCase().includes(user_btn_select);
if (isDev()) console.log('按钮内容:', btn.innerText, ',是否包含选中:', flag); if (isDev()) console.log('按钮内容:', btn.innerText, ',是否包含选中:', flag);
if (!flag) btn.style.display = 'none'; if (!flag) btn.style.display = 'none';
// 自动结束
else if (wh_trans_settings.autoStartFinish === true) {
try {
btn.click();
} catch {
}
}
}); });
}).observe(wrap, {subtree: true, attributes: true, childList: true}); }).observe(wrap, {subtree: true, attributes: true, childList: true});
} }
// 自刷新 // 自刷新
let audio_played_flag; let audio_played_flag;
if (wh_trans_settings.attReload !== 6) { if (wh_trans_settings.attReload !== 6 && stop_reload !== true) {
const selector_device_map = { const selector_device_map = {
'pc': '#defender div[class^="modal___"]', 'pc': '#defender div[class^="modal___"]',
'mobile': '#attacker div[class^="modal___"]', 'mobile': '#attacker div[class^="modal___"]',
'tablet': '', 'tablet': '',
}; };
const selector = selector_device_map[device]; const selector = selector_device_map[device];
// switch (device) {
// case 'pc': {
elementReady(selector).then(elem => { elementReady(selector).then(elem => {
if (!elem.querySelector('button')) { if (!elem.querySelector('button')) {
if (wh_trans_settings.attReload === 0) { if (wh_trans_settings.attReload === 0 && stop_reload !== true) {
window.location.reload(); window.location.reload();
} else { } else {
let reload_flag; let reload_flag;
@ -3997,7 +4052,7 @@ padding: 0.5em 0;
window.setInterval(() => { window.setInterval(() => {
if (reload_flag === undefined) { if (reload_flag === undefined) {
reload_flag = true; reload_flag = true;
} else { } else if (stop_reload !== true) {
window.location.reload(); window.location.reload();
} }
}, timeout); }, timeout);
@ -4014,41 +4069,6 @@ padding: 0.5em 0;
}, 600); }, 600);
} }
}); });
// break;
// }
// case 'mobile': {
// elementReady('#attacker div[class^="modal___"]').then(elem => {
// if (!elem.querySelector('button')) {
// if (wh_trans_settings.attReload === 0) {
// window.location.reload();
// } else {
// let reload_flag;
// const reload_intervalID = window.setInterval(() => {
// if (reload_flag === undefined) {
// reload_flag = true;
// } else {
// window.location.reload();
// }
// }, wh_trans_settings.attReload * 1000 + getRandomInt(-999, 999));
// }
// } else if (audio_played_flag === undefined) {
// audio_played_flag = true;
// let play_time = 0;
// const audio_play_id = window.setInterval(() => {
// const $audio = document.createElement('audio');
// $audio.src = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3';
// $audio.play().then();
// play_time++;
// if (play_time === 3) clearInterval(audio_play_id);
// }, 600);
// }
// });
// break;
// }
// case 'tablet': {
// break;
// }
// }
} }
return; return;
} }