[rainbow] および [/rainbow] タグ内の特定のテキストをレインボー化するために、Flash ベースのチャットに追加した関数を次に示します。
ChatUI.prototype.rainbowParse = function(txt) {
txt = txt;
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
txt = txt.replace("'", "@").replace("'", "@");
var firstChar = txt.indexOf("[rainbow]") + 9;
var lastChar = txt.indexOf("[/rainbow]");
if (((lastChar - firstChar) > 100) || ((txt.split("[rainbow]").length - 1) > 3)) {
break;
}
while (lastChar <= txt.lastIndexOf("[/rainbow]")) {
var RAINBOWTEXT = '';
var i = firstChar;
while (i < lastChar) {
RAINBOWTEXT += txt.charAt(i);
i++
}
var text = RAINBOWTEXT;
var texty = '';
colors = new Array('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000','ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00','99ff00','66ff00','33ff00','00ff00','00ff33','00ff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff');
i = 0;
while (i <= text.length) {
var t = text.charAt(i);
if (t != undefined) {
texty += "<font color=\"#" + colors[i % colors.length] + "\">" + t + "</font>";
i++;
}
}
texty = texty.replace("> <", "> <");
var REPLACEME = "[rainbow]" + RAINBOWTEXT + "[/rainbow]";
txt = txt.replace(REPLACEME, texty);
if (lastChar == txt.lastIndexOf("[/rainbow]")) {
break;
}
nextChar = lastChar + 10;
firstChar = txt.indexOf("[rainbow]", lastChar) + 9;
lastChar = txt.indexOf("[/rainbow]", lastChar);
}
txt = txt.replace("@", "'");
}
return txt;
}
しかし、私はこれらの虹がこのように見えるのが好きではありません. テキストの色が繰り返されます。
私が言いたいことの例を見るには、http://www.tektek.org/color/にアクセスして "Rainbow" をクリックし、繰り返しを 1 に設定してプレビューします。次に、3 以上に設定してプレビューします。
コードに 1 の繰り返しを持たせたいのですが、虹のテキストの長さが非常に異なるため、これを行う方法がわかりません。コードを調べようとして、多数のレインボーテキストジェネレーターをグーグルで検索しました。最悪だ。これに関するアイデアや支援をお願いします。:(