diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 524cae7..a592439 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -405,11 +405,6 @@ } }, 500); - // const attackDict = { - // "mugged": "打劫了", - // "arrested": "逮捕了" - // } - /** * 主页 todo */ @@ -424,31 +419,31 @@ if (!homeDict[e.firstChild.nodeValue]) return; if (e.firstChild.nodeValue === 'Latest Events') { homeEvents = $(e).parent().next().find('span'); + } else if (e.firstChild.nodeValue === 'Latest Attacks') { + const attackDict = { + "mugged": "打劫了 ", + "arrested": "逮捕了 ", + "hospitalized": "暴力殴打了 " + } + $(e).parent().next().find('span').each(function () { + let nodes = $(this)[0].childNodes; + nodes.forEach((v, i) => { + if (v.nodeValue !== null) { + let waitToTsf = v.nodeValue.toString().indexOf(" "); + if (waitToTsf >= 0) { + switch (waitToTsf) { + case 0: + $(this)[0].childNodes[i].nodeValue = " " + attackDict[$(this)[0].childNodes[i].nodeValue.split(" ")[1]]; + break; + + default: + $(this)[0].childNodes[i].nodeValue = "有人" + attackDict[$(this)[0].childNodes[i].nodeValue.split(" ")[1]]; + } + } + } + }, this); + }); } - // else if (e.firstChild.nodeValue === 'Latest Attacks') { - // const attackDict = { - // "mugged": "打劫了", - // "arrested": "逮捕了" - // } - // $(e).parent().next().find('span').each(function () { - // var attackMsg = $(this).context.textContent; - // - // //Convert to an array for attacking ways determination - // var keyAtk = attackMsg.split(" "); - // var someone = keyAtk[0] === "Someone" ? "有人" : keyAtk[0]; - // var textTsf = ""; - // switch (keyAtk[1]) { - // - // case "hospitalized": - // textTsf = "攻击并送" + keyAtk[2] + "入院"; - // break; - // - // default: - // textTsf = attackDict[keyAtk[1]] + keyAtk[2]; - // } - // $(this).context.textContent = someone + textTsf; - // }); - // } e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue]; }); @@ -462,6 +457,7 @@ return; } + /** * city */