From 222e84b2ea48cabba8a9de006d9070ead140684d Mon Sep 17 00:00:00 2001 From: woohoo Date: Thu, 18 Nov 2021 12:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 8213619..2a3e8e5 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,8 +1,8 @@ // ==UserScript== // @name Torn翻译 // @namespace WOOH -// @version 0.1.1117a -// @description UI翻译 +// @version 0.1.1118a +// @description Torn UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* // @grant none @@ -961,6 +961,19 @@ .replace('second', '秒钟'); }; + /** + * regexp test + */ + String.prototype.contains = function contains(keywords) { + if (typeof keywords === 'string') { + if (keywords.contains(/\*/)) + keywords = keywords.replace("*", '.+'); + return new RegExp(keywords).test(this); + } + if (keywords.test) + return keywords.test(this); + }; + /** * 边栏 * 目前默认所有页面调用边栏翻译 @@ -2705,9 +2718,9 @@ * You have successfully purchased membership in Deep Burn. * 你已成功购买Deep Burn的健身房会员卡。 */ - if ($(e).text().indexOf('membership') >= 0) { - const gymName = e.firstChild.nodeValue.slice(46, -2); - e.firstChild.nodeValue = '你已成功购买 ' + gymName + ' 的健身房会员卡。'; + if ($(e).text().contains('You have successfully purchased membership in')) { + const gymName = e.firstChild.nodeValue.trim().slice(46, -1); + e.firstChild.nodeValue = '你已成功购买 ' + gymList[gymName] + ' 的健身房会员卡。'; return; }