大家好,我在使用油猴脚本制作一个网页游戏“卡片战斗先导者OD”的汉化
https://dulst.com/overdulst/cards/31853506/Vairina-Valiente
如上↑,我要汉化这个网站的UI、卡名、效果等信息,现在在大段的效果文本上遇到了一个问题,举个例子↓
请看,这是一整句效果,但是却被加粗的给隔开了,如果分多段汉化,根本没法阅读
【下面是我抄来的代码,求帮忙改改,使其能将被加粗、斜体等格式分开的当做一整句话,谢谢!Q3Q
(中间的翻译太长了,所以节选了一段)
(代码是我抄来的,我只学过用DW画网页,完全看不懂JS,推到重写也行啦,哭唧唧~)
(如果需要把加粗和斜体的<strong <i 啥的放到【const i18n = new Map([】也可以哒!)
// ==UserScript==
// @name dulst.com的CardFighit Vanguard OverDulst文本替换汉化
// @namespace http://tampermonkey.net/
// @version 0.6
// @description 通过将英文替换为中文的方法,汉化卡片战斗先导者OD的网页游戏
// @author 库X崔羊羊
// @match https://dulst.com/overdulst/*
// @icon https://www.google.com/s2/favicons?domain=dulst.com
// ==/UserScript==
(function() {
'use strict';
const i18n = new Map([
['when this unit would be retired for your card\'s cost', '由于你的卡片的费用要将这个单位退场之际'],
['you may retire it as two rear-guards', '这个单位可以当做2张的份量'],
['Put this unit into your damage zone', '将这张卡放置到伤害区'],
['choose a face up grade 3 card from your damage zone', '选择你的伤害区中的1张正面表示的等级3的卡'],
['increase of the trigger effects revealed by your drive check gets', '因你的攻击判定判出的触发效果增加时再'],
['Blaster Dark', '暗黑狂风'],
['Blaster', '狂风'],
['At the end of that turn', '这个回合结束时'],
['retire that called unit', '将被CALL出场的那个单位退场'],
['Put it on the top of the deck if you did not call', '没有CALL出场的话放置回牌堆顶'],
['When this unit boosts a vanguard', '这个单位支援先导者时'],
['Triple Drive', '三判'],
['Drive check three times', '能够进行3次攻击判定'],
['choose three of your front row units', '选择前列的你的3个单位'],
['The \\[Power\\] gained from this unit\'s boost will be lost', '通过这个单位支援给予的力量增加会不再有效'],
['When this unit boosts a rear-guard', '这个单位支援后防者时'],
['if you persona rode this turn', '这个回合中你进行了人格RIDE的话'],
['and your opponent cannot call grade 1 or greater cards from their hand to \\(GC\\) until end of that battle', '这次战斗中,对手不能将等级1以上的卡从手牌CALL到G上'],
['if you have five or more cards in your soul', '你的灵魂里的卡有5张以上的话'],
['This card cannot be ridden', '这张卡不能RIDE'],
['called or moved to the front row', 'CALL或移动将这张卡放置到前列'],
['When you would move or swap rear-guards during your main phase', '你在主要阶段中将后防者移动或交换位置之际'],
['you can also move it within the same row', '也可以在横列间移动或交换位置'],
['Your units in front of this unit cannot be chosen by your opponent\'s effects', '这个单位前方的你的单位不会被对手的效果选择'],
['Note:', '注意:'],
['Currently lets units move anywhere on the board instead of allowing movement by row.', '目前允许单位在圆阵上任意移动,而不是纵横移动'],
['the next time you would', '你下一次通过'],
['an order and play it this turn', '将指令卡使用之际'],
['reduce that cost by', '那个费用减少'],
['Reduce from the total cost', '在合计的费用中减少'],
['Does not Counter Charge even if it becomes negative', '但是即使减到负数也不能计数回充'],
['bind this unit', '将这个单位封锁'],
['choose an order card from your bind zone', '选择你的封锁区中的1张指令卡'],
['you may put all cards from your bind zone into the drop', '你可以将你的封锁区中所有的卡放置到弃牌区'],
['until end of turn for each card put', '←放置的卡每有1张,直到回合结束'],
['you may discard the top five cards of your deck', '你可以将你的牌堆顶的5张卡舍弃'],
['until end of that battle for each of your rear-guards', '←你的后防者每有1张,在这次战斗中'],
['Beta Promo', '内测奖励'],
['Granted to the top 2 players of the first overDulst tournament!!', '授予第1届overDulst锦标赛的前两名选手!!'],
['if you have another unit with', '如果你有其他的单位含有'],
['Toushirou', '藤四郎'],
['When this unit boosts a', '当这个单位支援'],
['you may have this unit get', '你可以使这个单位获得'],
['at the end of that battle', '这次战斗结束时'],
['retire all of your rear-guards in the same column as this unit', '将与这个单位同纵列的你所有的后防者退场'],
['Discard a set order card from your hand', '将手牌中的1张设置指令卡舍弃'],
['retire a Shadow Army token', '将1张夜影兵衍生物退场'],
['If one or less of your opponent\'s cards are imprisoned in your Prison', '被收容在你的监狱的对手的卡在1张以下的话'],
['choose a unit card from your opponent\'s drop', '选择对手的弃牌区中的1张单位卡'],
['During the battle this unit boosted a vanguard', '这个单位支援先导者的战斗中'],
['During the battle this unit boosted a grade 0', '这个单位支援等级0的单位的战斗中'],
['During the battle this unit boosted', '这个单位支援的战斗中'],
])
replaceText(document.body)
const bodyObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(addedNode => replaceText(addedNode))
})
})
bodyObserver.observe(document.body, { childList: true, subtree: true })
function replaceText(node) {
nodeForEach(node).forEach(htmlnode => {
i18n.forEach((value, index) => {
const textReg = new RegExp(index, 'g')
if (htmlnode instanceof Text ) {
htmlnode.nodeValue = htmlnode.nodeValue.replace(textReg, value)
}
else if (htmlnode instanceof HTMLInputElement ) {
htmlnode.value = htmlnode.value.replace(textReg, value)
}
})
})
}
function nodeForEach(node) {
const list = []
if (node.childNodes.length === 0) list.push(node)
else {
node.childNodes.forEach(child => {
if (child.childNodes.length === 0) list.push(child)
else list.push(...nodeForEach(child))
})
}
return list
}
})();