diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 2885af1..4a77234 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,8 +1,8 @@ // ==UserScript== -// @lastmodified 202112022039 +// @lastmodified 202112031724 // @name Torn翻译 // @namespace WOOH -// @version 0.1.1202a +// @version 0.1.1203a // @description Torn UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -2935,16 +2935,26 @@ * 搜索玩家的4个分类按钮 */ const playerSearchBoxTrans = function playerSearchBoxTrans() { - const psbtOB = new MutationObserver(_ => { - if ($('div.ac-wrapper').length === 0) return; + const opt = { + childList: true, + subtree: true, + // attributes: true, + // attributeFilter: ['class'] + }; + const psbtOB = new MutationObserver(mutation => { + const $people_cat = $('ul.ac-options li a'); psbtOB.disconnect(); - $('div.ac-wrapper li a').each((i, e) => { - if (chatDict[$(e).text().trim()]) - $(e).text(chatDict[$(e).text().trim()]); - }); - psbtOB.observe(document, {childList: false, subtree: true, attributes: true}); + mutation.forEach((e) => { + if (e.target.className === 'ac-wrapper') { + $people_cat.each((i, e) => { + if (chatDict[$(e).text().trim()]) + $(e).text(chatDict[$(e).text().trim()]); + }); + } + }) + psbtOB.observe(document.body, opt); }); - psbtOB.observe(document, {childList: false, subtree: true, attributes: true}); + psbtOB.observe(document.body, opt); } playerSearchBoxTrans(); @@ -3316,23 +3326,22 @@ const trans = () => { if ($('.wh-translate').length === 0 && $('div#tab-menu.captcha').length === 0) { $('div.content-title').before( - `