1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
// 注:デフォルトで読み込んでいるのは min 版です。
// =================================
// gMessageTester オブジェクトの簡単な定義
// =================================
window.gMessageTester = {
power: false
,currentCharNumber: 0
,currentTextNumber: 0
,currentChar: ""
,currentHtml: ""
,currentText: ""
,glyphUrl: "./tyrano/images/system/nextpage.gif"
,cssUrl: "./data/others/plugin/theme_kopanda_09_1/testMessagePlus/style.css"
,sampleUrl: "./data/others/plugin/theme_kopanda_09_1/testMessagePlus/sampletext.ks"
,className: "test_message_area"
,messageArea: function() {}
,timer: null
,isAutoMode: true
,shouldHarryUp: false
,sampleTexts: [""]
,style: {}
,toggle: function() {}
,getKidokuColor: function() {}
,checkEndText: function() {}
,getCurrentState: function() {}
,clearMessageArea: function() {}
,appendChar: function() {}
,appendGlyph: function() {}
,increaseCharNumber: function() {}
,increaseTextNumber: function() {}
,update: function() {}
,next: function() {}
};
// =================================
// gMessageTester オブジェクトの詳細な定義
// =================================
// TM が gMessageTester を指す名前空間で作業(長いので)
(function(TM) {
//
// スタイルの取得
//
$.get(TM.cssUrl, function(data){
var style = gMessageTester.style;
// コメントの削除(/*~*/)
data = data.replace(/\/\*[\s\S]*?\*\//g, "");
// 改行、空白、タブの削除
data = data.replace(/(\n|\s|\t)/g, "");
// { ~ } の間を取り出して更に ; で区切って配列にする
data = data.split("{")[ 1 ]
.split("}")[ 0 ]
.split(";");
for (var i = 0; i < data.length; i++) {
var arr = data[ i ].split(":");
if (arr[ 0 ] != "") {
style[ arr[ 0 ] ] = arr[ 1 ];
}
};
});
//
// サンプル文章の取得
//
$.get(TM.sampleUrl, function(data){
// コメント行の削除
data = data.replace(/;.*/g, "\n");
// 改行、空白、タブの削除
data = data.replace(/(\n|\s|\t)/g, "");
// [p] で区切る
var arr = data.split("[p]");
// 最後に何もなかったらポップ
if (arr[ arr.length - 1 ] == "") {
arr.pop();
}
// 代入
gMessageTester.sampleTexts = arr;
});
//
// 既読色の取得
//
TM.getKidokuColor = function() {
var cfg = tyrano.plugin.kag.config;
var flg = cfg.autoRecordLabel;
var col = cfg.alreadyReadTextColor;
if (flg == "true" && col != "default" && typeof col == "string") {
// $.convertColor(col) は libs.js で定義されているメソッド
// col に対して String プロトタイプオブジェクトのメソッドを使うので
// String 型じゃない col を引数にするとバグる
// (「未定義の関数を実行している」、と出る)
return $.convertColor(col);
}
return "";
};
//
// 現在の情報取得
//
TM.getCurrentState = function() {
// 現在の文章と文字を取得
var idx = this.currentCharNumber;
var str = this.sampleTexts[ this.currentTextNumber ];
var chr = str.charAt(idx);
if (chr == "[") {
var idx2 = str.indexOf("]", idx);
var len = idx2 - idx + 1;
var chr = str.substr(idx, len);
this.currentCharNumber += len;
this.getCurrentState();
}
this.currentText = str;
this.currentChar = chr + this.currentChar;
};
//
// 文末に達しているかどうかを返す
//
TM.checkEndText = function() {
if (this.currentCharNumber == 0) {
return true;
}
else {
return false;
};
};
//
// 文末に達しているならメッセージエリアをクリアする
//
TM.clearMessageArea = function() {
if (this.checkEndText()) {
this.messageArea.empty();
this.currentHtml = "";
};
};
//
// メッセージエリアに文字をひとつ足す
//
TM.appendChar = function() {
var chr = this.currentChar;
chr = chr.replace(/\[r\]/g, "<br />");
chr = chr.replace(/\[kidoku\]/g, "<span style='color:" + this.getKidokuColor() + "'>");
chr = chr.replace(/\[endkidoku\]/g, "</span>");
this.currentHtml += chr;
this.messageArea.html(this.currentHtml);
this.currentChar = "";
};
//
// メッセージエリアにクリックグリフを足す
//
TM.appendGlyph = function() {
var height = this.style["font-size"] || tyrano.plugin.kag.stat.default_font.size;
var color = this.style["color"] || tyrano.plugin.kag.stat.default_font.color;
//this.messageArea.append("<img src='" + this.glyphUrl + "' />");
this.messageArea.append('<span style="display: inline-block; width: 10px; height: 4px; background-color: ' + color + '; transform: translateY(3px);" class="img_next_test"> </span>')
};
//
// 文字番号の増加処理
//
TM.increaseCharNumber = function() {
// 文字番号増加
this.currentCharNumber++;
// 文章の長さを超えたら
if (this.currentCharNumber >= this.currentText.length) {
// 0にして
this.currentCharNumber = 0;
// 文章番号を増加
this.increaseTextNumber();
// ハリーアップ義務をなくす
this.shouldHarryUp = false;
};
};
//
// 文章番号の増加処理
//
TM.increaseTextNumber = function() {
// 文章番号を増加
this.currentTextNumber++;
// 文章番号が文章の数を超えたら
if (this.currentTextNumber >= this.sampleTexts.length) {
// 0にする
this.currentTextNumber = 0;
};
};
//
// アップデート処理
//
TM.update = function() {
//console.log("update.")
// 参照
var CO = tyrano.plugin.kag.config;
// 現在の文章と文字を取得
TM.getCurrentState();
// メッセージエリアの消去チェック
TM.clearMessageArea();
// 文字を足す
TM.appendChar();
// 文字番号の増加処理
TM.increaseCharNumber();
// 文末でなければ
if (!TM.checkEndText()) {
// ディレイを計算
var delay = parseInt(CO.chSpeed);
if (TM.shouldHarryUp) {
delay = 2;
};
// ディレイ≦1ならば即座にアップデート
if (delay <= 1) {
TM.update();
}
// ディレイ>0ならばアップデートの予約
else {
clearTimeout(TM.timer);
TM.timer = setTimeout(TM.update, delay);
};
}
// 文末ならば
else {
// デストロイチェック
if ($("." + TM.className).size() < 1) return TM.destroy();
// クリック待ちグリフを追加
TM.appendGlyph();
// オートモードならば
if (TM.isAutoMode) {
// ディレイを計算して
var delay = parseInt(CO.autoSpeed)
+ parseInt(CO.autoSpeedWithText)
* TM.currentText.length;
// アップデートの予約
clearTimeout(TM.timer);
TM.timer = setTimeout(TM.update, delay);
// アニメーション
$(".img_next_test").css("width", 10 * delay / 1000).animate({
"width": "0"
}, delay, "linear")
};
};
};
TM.next = function() {
// 文末に達していて待機中ならば次の文章の読み込み
if (TM.checkEndText()) {
clearTimeout(TM.timer);
TM.update();
}
// 文末に達していなければ表示を急がせる
else {
TM.shouldHarryUp = true;
};
};
//
// 駆動状態のON/OFFを行う
//
TM.create = function () {
//console.log("create.");
var that = this;
// フリーレイヤーの表示
$(".layer_free").show();
// 現在のデフォルトフォント設定の取得
var font = tyrano.plugin.kag.stat.default_font;
// スクロールイベント名
var scroll = "onwheel" in document ? "wheel" :
"onmousewheel" in document ? "mousewheel" :
"DOMMouseScroll";
// メッセージエリアの作成
var area = $("<div class='" + this.className + "'></div>")
// 挿入
.appendTo(".layer_free")
// エリアクリック/スクロール時の処理
.click(this.next)
.on(scroll, this.next);
// スタイルのセット
if (!this.style["font-weight"]) area.css("font-weight", font.bold);
if (!this.style["font-size" ]) area.css("font-size" , font.size + "px");
if (!this.style["font-family"]) area.css("font-family", font.face);
if (!this.style["color" ]) area.css("color" , font.color);
// 代入
this.messageArea = area;
// 起動する
clearTimeout(this.timer);
this.timer = setTimeout(this.update, 500);
};
TM.destroy = function () {
//console.log("destroy.");
// タイマーを切る
clearTimeout(this.timer);
// 初期化
this.currentCharNumber = 0;
this.currentTextNumber = 0;
// DOM 要素の削除
this.messageArea.remove();
};
}(window.gMessageTester));
|