From a866df68f757658a93ffde7c0249983ebab177df Mon Sep 17 00:00:00 2001 From: woohoo Date: Sun, 14 Nov 2021 17:48:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BF=B7=E4=BD=A0=E8=B5=84?= =?UTF-8?q?=E6=96=99=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 81 +++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index f3d58a8..1119cfe 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -940,32 +940,67 @@ }, 1000); /** - * 浮窗 todo - * 小型资料卡 全局 + * 迷你资料卡 全局 todo */ - let tooltip = $('div.ToolTipPortal')[0]; - let intervalID = setInterval(() => { - tooltip = $('div.ToolTipPortal')[0]; - if (tooltip) { - clearInterval(intervalID); - new MutationObserver(mutations => { - let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); - if (barDescr.length !== 0) { - barDescr[0].childNodes.forEach(i => { - if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; - }) + const miniProfile = function miniprof() { + const miniprofOB = new MutationObserver(_ => { + miniprofOB.disconnect(); + miniprofTrans(); + miniprofOB.observe($('div.profile-mini-root').get(0), {attributes: true, childList: true, subtree: true}); + }); + const miniprofTrans = function miniprofTrans(){ + // let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); + // if (barDescr.length !== 0) { + // barDescr[0].childNodes.forEach(i => { + // if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; + // }) + // } + // let miniprof_tooltip = $("#body > div.ToolTipPortal > div > div:nth-child(2)"); + // if (miniprof_tooltip.length !== 0) { + // if (tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]) { + // miniprof_tooltip[0].firstChild.nodeValue = tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]; + // } + // } else { + // //todo 通配符匹配 + // } + }; + if($('div.profile-mini-root').length>0) + miniprofTrans(); + else { + const intervalInit = setInterval(() => { + const miniProfileFirst = $('div.profile-mini-root').get(0); + if(miniProfileFirst){ + clearInterval(intervalInit); + miniprofTrans(); + miniprofOB.observe(miniProfileFirst, {attributes: true, childList: true, subtree: true}); } - let miniprof_tooltip = $("#body > div.ToolTipPortal > div > div:nth-child(2)"); - if (miniprof_tooltip.length !== 0) { - if (tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]) { - miniprof_tooltip[0].firstChild.nodeValue = tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]; - } - } else { - //todo 通配符匹配 - } - }).observe(tooltip, {attributes: true, childList: true, subtree: true}); + }, 1000); } - }, 1000); + // let tooltip = $('div.ToolTipPortal')[0]; + // let intervalID = setInterval(() => { + // tooltip = $('div.ToolTipPortal')[0]; + // if (tooltip) { + // clearInterval(intervalID); + // new MutationObserver(mutations => { + // let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); + // if (barDescr.length !== 0) { + // barDescr[0].childNodes.forEach(i => { + // if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; + // }) + // } + // let miniprof_tooltip = $("#body > div.ToolTipPortal > div > div:nth-child(2)"); + // if (miniprof_tooltip.length !== 0) { + // if (tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]) { + // miniprof_tooltip[0].firstChild.nodeValue = tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]; + // } + // } else { + // //todo 通配符匹配 + // } + // }).observe(tooltip, {attributes: true, childList: true, subtree: true}); + // } + // }, 1000); + }; + miniProfile(); /** * header