-
Notifications
You must be signed in to change notification settings - Fork 5
/
apphtml.js
executable file
·675 lines (646 loc) · 32.3 KB
/
apphtml.js
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
(function () {
var step = 1,
d = document,
w = window;
var json = {},
ssMax = 0,
ssCtr = 0,
hitApp = 0,
appId = "",
tiffFlg = "false";
// 親JSからパラメータを取得
var script = d.getElementById("bmlt");
var cnt = script.cnt,
knd = script.knd,
out = script.out,
phg = script.phg,
scs = script.scs,
ipd = script.ipd,
fmt = decodeURIComponent(script.fmt);
// 見ているサイトがiTunesWebだった場合
appId = getAppIdFrom(location.href);
// 検索キーワードを取得(選択されたキーワードがある場合にはそっちを優先)
var kwd = '';
if (appId == "") {
if (d.selection) kwd = d.selection.createRange().text;
else if (w.selection) kwd = w.selection.createRange().text;
else if (w.getSelection) kwd = w.getSelection();
else if (d.getSelection) kwd = d.getSelection();
else kwd = '';
if (kwd == "") kwd = prompt("What do you want to search?", "");
if (kwd == "" || !kwd) {
prompt('Result', 'Not Found ...');
return;
}
// iTunesWeb の URL を入力された場合(そうでない場合 appId == "" となる)
appId = getAppIdFrom(kwd);
}
// bookmarkletの予約語(43個)
var bmAry = ['name', 'url', 'preview', 'price', 'category', 'playtime',
'trackcnt', 'pubdate', 'icon60url', 'icon100url', 'artist', 'artisturl',
'seller', 'sellerurl', 'copyr', 'desc', 'shortdesc', 'descnew',
'version', 'rating', 'userrating', 'userratingcnt', 'curuserrating', 'curuserratingcnt',
'appsize', 'moveos', 'os', 'gamecenter', 'univ', 'lang',
'image1', 'image2', 'image3', 'image4', 'image5',
'univimage1', 'univimage2', 'univimage3', 'univimage4', 'univimage5',
'badgeL', 'badgeS', 'textonly', 'today'];
// メイン処理(非同期実行を防ぐ為にTimerを利用)
var timerId = setInterval(function () {
try {
switch (step) {
case 1:
step = 0;
getWebApi();
break;
case 2:
step = 0;
getWidth();
break;
case 3:
step = 0;
dispData();
break;
case 4:
cleanup();
return 0;
}
} catch (e) {
alert("Something may be wrong.\n->" + e);
cleanup();
}
}, 100);
function cleanup() {
while (d.getElementById("bmlt"))
d.getElementById("bmlt").parentNode.removeChild(d.getElementById("bmlt"));
clearInterval(timerId);
timerId = null;
}
function getAppIdFrom(urlString) {
var appId = '';
if (urlString.indexOf("https://itunes.apple.com/") != -1) {
appId = urlString.split("/id")[1];
if (appId) {
appId = appId.split("?")[0];
}
if (!appId) {
appId = '';
}
}
return appId;
}
// iTunes Search API をコールしてJSON形式で値を取得
function getWebApi() {
var s = d.createElement("script"),
src = "";
if (appId != "") {
// iTunes Web の場合
src = "http://itunes.apple.com/jp/lookup?id=" + appId + "&lang=ja_jp&country=JP&entity=" + knd + "&limit=" + cnt;
} else {
src = "http://itunes.apple.com/jp/search?term=" + encodeURIComponent(kwd) + "&lang=ja_jp&country=JP&entity=" + knd + "&limit=" + cnt;
// Mac アプリが検索できない件の暫定対処(開発元での検索は不可となる)
// 2014.1.19時点で以下コード不要。次回の同事象に備えコメントアウトにとどめる。
// if (knd == "macSoftware") {
// src += "&attribute=allTrackTerm";
// }
}
/*********** iTunes Search APIの戻り値(ここから)***********
'kind', 'artistId', 'artistName', 'price', 'version', 'description', 'releaseDate',
'sellerName', 'currency', 'trackId', 'trackName', 'releaseNotes', 'primaryGenreName',
'primaryGenreId', 'isGameCenterEnabled', 'wrapperType', 'artworkUrl60',
'artworkUrl100', 'artistViewUrl', 'contentAdvisoryRating', 'trackCensoredName',
'trackViewUrl', 'fileSizeBytes', 'sellerUrl', 'averageUserRatingForCurrentVersion',
'userRatingCountForCurrentVersion', 'artworkUrl512', 'trackContentRating',
'averageUserRating', 'userRatingCount'
'genreIds', 'features', 'genres', 'supportedDevices', 'languageCodesISO2A',
'screenshotUrls', 'ipadScreenshotUrls'
*********** iTunes Search APIの戻り値(ここまで)***********/
s.charset = "utf-8";
s.src = src + "&callback=result";
s.id = "bmlt";
d.body.appendChild(s);
w.result = function (data) {
if (data.resultCount == 0) {
prompt('Result', 'Not Found ...');
step = 4;
return;
}
try {
//artworkUrl100がないものをresultsから削除
//2015/11/8 緊急パッチ。仕様変更の見極めが必要なためコメントアウトにとどめる。
//for (var i = 0; i < data.results.length; i++) {
// if (!data.results[i].artworkUrl100) {
// data.results.splice(i, 1);
// i = i - 1;
// }
//}
for (var i = 0; i < data.results.length; i++) {
json[i] = data.results[i];
if (knd == "software" || knd == "iPadSoftware" || knd == "macSoftware") {
json[i].description = json[i].description.replace(/\n/g, '<br>');
if (json[i].releaseNotes)
json[i].releaseNotes = json[i].releaseNotes.replace(/\n/g, '<br>');
if (!json[i].supportedDevices)
json[i].supportedDevices = "";
}
if (knd == "movie") {
if (json[i].shortDescription)
json[i].shortDescription = json[i].shortDescription.replace(/\n/g, '<br>');
if (json[i].longDescription)
json[i].longDescription = json[i].longDescription.replace(/\n/g, '<br>');
}
var z = json[i],
x = new Array(bmAry);
if (knd == "software" || knd == "iPadSoftware" || knd == "macSoftware") {
if (eval(z.price) == 0) x.price = '無料';
else x.price = '¥' + fmtNumber(z.price);
x.appname = z.trackCensoredName;
x.title = x.appname + '(' + x.price + ')';
}
if (knd == "song") {
x.title = z.trackCensoredName + ' (' + z.artistName + ')';
}
if (knd == "album") {
x.title = z.collectionCensoredName + ' (' + z.artistName + ')';
}
if (knd == "movie") {
x.title = z.trackCensoredName + ' (' + z.artistName + ')';
}
if (knd == "ebook") {
x.title = z.trackCensoredName + ' (' + z.artistName + ')';
}
var r = prompt('【' + (i + 1) + '/' + data.results.length + '】' + x.title, 'OK→次, キャンセル→決定');
if (!r) {
hitApp = i;
step = 2;
return;
}
}
} catch (e) {
alert("Something may be wrong. \n->" + e);
}
step = 4;
}
}
// スクショの縦横チェック(裏で画像をロード)
function getWidth() {
var i;
if (knd != "software" && knd != "iPadSoftware" && knd != "macSoftware") {
step = 3;
return;
}
ssMax = json[hitApp].screenshotUrls.length;
if (knd == 'software') {
ssMax = ssMax + json[hitApp].ipadScreenshotUrls.length;
for (i = 0; i < json[hitApp].screenshotUrls.length; i++) {
loadImg(i, "image", json[hitApp].screenshotUrls[i], eval(scs));
}
for (i = 0; i < json[hitApp].ipadScreenshotUrls.length; i++) {
loadImg(i, "univimage", json[hitApp].ipadScreenshotUrls[i], eval(scs) * eval(ipd));
}
}
if (knd == 'iPadSoftware') {
ssMax = ssMax + json[hitApp].ipadScreenshotUrls.length;
for (i = 0; i < json[hitApp].ipadScreenshotUrls.length; i++) {
loadImg(i, "image", json[hitApp].ipadScreenshotUrls[i], eval(scs));
}
for (i = 0; i < json[hitApp].screenshotUrls.length; i++) {
loadImg(i, "univimage", json[hitApp].screenshotUrls[i], eval(scs) * eval(ipd));
}
}
if (knd == 'macSoftware') {
for (i = 0; i < json[hitApp].screenshotUrls.length; i++) {
loadImg(i, "image", json[hitApp].screenshotUrls[i], eval(scs));
}
}
}
// 縦横判定の結果としてWidthを計算
function loadImg(i, type, src, x) {
var aw, ah, img = new Image(), ret;
// スクショが.tifの場合にはスキップ
if (src.indexOf(".tif") != -1) {
ssCtr = ssCtr + 1;
json[hitApp][type + (i + 1) + "width"] = 0;
if (ssCtr == ssMax) step = 3;
tiffFlg = "true";
return;
}
img.src = src;
img.onload = function () {
aw = img.width;
ah = img.height;
if (aw > ah) {
ret = Math.round(x);
} else {
ret = Math.round(x * (aw / ah));
}
img.onload = "";
img = void 0;
ssCtr = ssCtr + 1;
json[hitApp][type + (i + 1) + "width"] = ret;
if (ssCtr == ssMax) step = 3;
}
}
// 結果の整理と出力方法ごとの処理
function dispData() {
var x = '',
chk = '';
var z = json[hitApp],
pData = fmt;
// 結果をbookmarklet予約語に変換してfmtを置換
var bmData = handData(z);
for (var j = 0; j < bmAry.length; j++) {
var key = bmAry[j],
value = bmData[key],
reg = new RegExp('\\${' + key + '}', 'g');
pData = pData.replace(reg, value);
}
x = pData + '\n';
chk = pData;
if (tiffFlg == "true")
prompt("Screenshots cannot be displayed because of TIFF files.","Warning...");
if (chk != '') {
// 出力方法ごとの処理(プレビュー表示)
if (out == "preview" ) {
d.body.innerHTML =
'<div id="bkmlt_preview">' +
"<form><input type='button' value='プレビュー表示を消す' onclick='javascript:" +
'var a=document.getElementById("bkmlt_preview");a.parentNode.removeChild(a);' +
"'> <input type='button' value='HTMLを選択する' onclick='javascript:" +
'var a=document.getElementById("bkmklt_ret");a.focus();' +
"'> <input type='button' value='HTMLの内容でプレビューを書き直す' onclick='javascript:" +
'var a=document.getElementById("bkmklt_ret").value;' +
'document.getElementById("bkmklt_rewrite").innerHTML=a;' +
"'></form>" + '<textarea style="width:99%;font-size:80%;" rows="10" id="bkmklt_ret"' +
'onfocus="javascript:this.select();">' + x + '</textarea><br><br><div id="bkmklt_rewrite">' +
x + '</div></div>' + d.body.innerHTML;
}
// 出力方法ごとの処理(ポップアップ表示)
if (out == "popup") {
prompt("result", x);
}
// 出力方法ごとの処理(ポップアップ→Textforce連携)
if (out == "pop-textforce") {
prompt("result", x);
w.location = 'textforce://';
}
// 出力方法ごとの処理(Texeforce連携)
if (out == "textforce") {
w.location = 'textforce://file?path=/blog.html&method=write&after=quick_look&text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(Texeforce連携しSafariに戻る)
if (out == "safari-textforce") {
w.location = 'textforce://file?path=/blog.html&method=write&after=quick_look&text=' + encodeURIComponent(x) + '&callback=' + encodeURIComponent(location.href);
}
// 出力方法ごとの処理(DraftPad連携)
if (out == "draftpad") {
w.location = 'draftpad:///insert?after=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(するぷろ連携)
if (out == "slpro") {
w.location = 'slpro://' + encodeURIComponent(x);
}
// 出力方法ごとの処理(Moblogger連携)
if (out == "moblogger") {
prompt("result", x);
w.location = 'moblogger://';
}
// 出力方法ごとの処理(Mobloggerを起動して追記)
if (out == "moblogger-app") {
w.location = 'moblogger://append?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(Mobloggerを起動してクリップボードにコピー)
if (out == "moblogger-pb") {
w.location = 'moblogger://pboard?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(MyEditor連携)
if (out == "myeditor") {
prompt("result", x);
w.location = 'myeditor://';
}
// 出力方法ごとの処理(MyEditorを起動してカーソル位置にコピー)
if (out == "myeditor-cursor") {
w.location = 'myeditor://cursor?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(Rowlineを起動して文末に追加)
if (out == "rowline") {
w.location = 'rowline:///set?loc=bottom&view=lines&callback=seeq://&text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(@matubizさん作MyScripts用スクリプト、TextHandlerに送信)
if (out == "msth") {
w.location = 'myscripts://run?title=TextHandler&text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(ThumbEditに送る)
if (out == "thumbedit") {
w.location = 'thumbedit://?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(ThumbEditに追記)
if (out == "thumbedit-insert") {
w.location = 'thumbedit://?text=' + encodeURIComponent(x) + '&mode=insert';
}
// 出力方法ごとの処理(PressSync Proに送る)
if (out == "presssync") {
w.location = 'presssync:///message?' + encodeURIComponent(x);
}
// 出力方法ごとの処理(PressSync Proに送る)
if (out == "textwell") {
w.location = 'textwell:///insert?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(はてなブログで新規作成)
if (out == "hatenablog") {
w.location = 'hatenablog:///new?title=new%20post&body=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(Draftsで新規作成)
if (out == "drafts") {
w.location = 'drafts://x-callback-url/create?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(Drafts 4で新規作成)
if (out == "drafts4") {
w.location = 'drafts4://x-callback-url/create?text=' + encodeURIComponent(x);
}
// 出力方法ごとの処理(AmeEditorに送る)
if (out == "ameeditor") {
w.location = 'ameeditor://insert?text=' + encodeURIComponent(x);
} // 出力方法ごとの処理(SLPRO Xに送る)
if (out == "slpro-x") {
w.location = 'slpro-x://?q=' + encodeURIComponent(x);
}
}
step = 4;
}
// Bookmarklet予約語へのセット
function handData(data) {
var x = new Array(bmAry),
i, j, tmp, reg;
//Entity毎にセット
if (knd == "song") {
x.name = data.trackCensoredName;
if (phg != "") x.url = PHGUrl(data.trackViewUrl, phg);
else x.url = data.trackViewUrl;
x.preview = data.previewUrl;
if (eval(data.trackPrice) == 0) x.price = '無料';
else x.price = '¥' + fmtNumber(data.trackPrice);
x.category = data.primaryGenreName;
x.trackcnt = data.trackCount + '曲';
x.pubdate = data.releaseDate.replace(/-/g, '/');
x.pubdate = x.pubdate.replace(/T.*/g, '');
x.icon60url = data.artworkUrl60;
x.icon100url = data.artworkUrl100;
x.artist = data.artistName;
if (phg != "") x.artisturl = PHGUrl(data.artistViewUrl, phg);
else x.artisturl = data.artistViewUrl;
x.badgeL = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets/ja_jp//images/web/linkmaker/badge_itunes-lrg.png) no-repeat;width:110px;height:40px;"></a>';
x.badgeS = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets//images/web/linkmaker/badge_itunes-sm.png) no-repeat;width:45px;height:15px;"></a>';
x.textonly = '<a href="' + x.url + '" target="itunes_store">' + x.name + ' - ' + x.artist + '</a>';
}
if (knd == "album") {
x.name = data.collectionCensoredName;
if(phg != "") x.url = PHGUrl(data.collectionViewUrl, phg);
else x.url = data.collectionViewUrl;
if (eval(data.collectionPrice) == 0) x.price = '無料';
else x.price = '¥' + fmtNumber(data.collectionPrice);
x.category = data.primaryGenreName;
x.trackcnt = data.trackCount + '曲';
x.pubdate = data.releaseDate.replace(/-/g, '/');
x.pubdate = x.pubdate.replace(/T.*/g, '');
x.icon60url = data.artworkUrl60;
x.icon100url = data.artworkUrl100;
x.artist = data.artistName;
if (phg != "") x.artisturl = PHGUrl(data.artistViewUrl, phg);
else x.artisturl = data.artistViewUrl;
if (!data.copyright) x.copyr = '';
else x.copyr = data.copyright;
x.badgeL = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets/ja_jp//images/web/linkmaker/badge_itunes-lrg.png) no-repeat;width:110px;height:40px;"></a>';
x.badgeS = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets//images/web/linkmaker/badge_itunes-sm.png) no-repeat;width:45px;height:15px;"></a>';
x.textonly = '<a href="' + x.url + '" target="itunes_store">' + x.name + ' - ' + x.artist + '</a>';
}
if (knd == "movie") {
x.name = data.trackCensoredName;
if (phg != "") x.url = PHGUrl(data.trackViewUrl, phg);
else x.url = data.trackViewUrl;
x.preview = data.previewUrl;
if (eval(data.trackPrice) == 0) x.price = '無料';
else if (!data.trackPrice) {x.price = 'レンタルのみ';}
else x.price = '¥' + fmtNumber(data.trackPrice);
x.category = data.primaryGenreName;
if (!data.trackTimeMillis) x.playtime = 'データなし';
else x.playtime = sizeTime(data.trackTimeMillis);
x.pubdate = data.releaseDate.replace(/-/g, '/');
x.pubdate = x.pubdate.replace(/T.*/g, '');
x.icon60url = data.artworkUrl60;
x.icon100url = data.artworkUrl100;
x.artist = data.artistName;
if (!data.shortDescription) {
if (!data.longDescription) {
x.shortdesc = '';
} else {
x.shortdesc = data.longDescription;
}
} else {
x.shortdesc = data.shortDescription;
}
if (!data.longDescription) x.desc = '';
else x.desc = data.longDescription;
x.badgeL = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets/ja_jp//images/web/linkmaker/badge_itunes-lrg.png) no-repeat;width:110px;height:40px;"></a>';
x.badgeS = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets//images/web/linkmaker/badge_itunes-sm.png) no-repeat;width:45px;height:15px;"></a>';
x.textonly = '<a href="' + x.url + '" target="itunes_store">' + x.name + ' - ' + x.artist + '</a>';
}
if (knd == "ebook") {
x.name = data.trackCensoredName;
if (phg != "") x.url = PHGUrl(data.trackViewUrl, phg);
else x.url = data.trackViewUrl;
if (eval(data.price) == 0) x.price = '無料';
else x.price = '¥' + fmtNumber(data.price);
x.category = data.genres[0];
for (i = 1; i < data.genres.length; i++) x.category = x.category + '、 ' + data.genres[i];
x.pubdate = data.releaseDate.replace(/-/g, '/');
x.pubdate = x.pubdate.replace(/T.*/g, '');
x.icon60url = data.artworkUrl60;
x.icon100url = data.artworkUrl100;
x.artist = data.artistName;
if (phg != "") x.artisturl = PHGUrl(data.artistViewUrl, phg);
else x.artisturl = data.artistViewUrl;
x.desc = data.description;
if (!data.averageUserRating) x.userrating = '無し';
else x.userrating = data.averageUserRating;
if (!data.userRatingCount) x.userratingcnt = '0件の評価';
else x.userratingcnt = fmtNumber(data.userRatingCount) + '件の評価';
x.badgeL = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets/ja_jp//images/web/linkmaker/badge_bookstore-lrg.png) no-repeat;width:146px;height:40px;"></a>';
x.badgeS = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets//images/web/linkmaker/badge_bookstore-sm.png) no-repeat;width:65px;height:15px;"></a>';
x.textonly = '<a href="' + x.url + '" target="itunes_store">' + x.name + ' - ' + x.artist + '</a>';
}
if (knd == "software" || knd == "iPadSoftware" || knd == "macSoftware") {
x.name = data.trackCensoredName;
if (phg != "") x.url = PHGUrl(data.trackViewUrl, phg);
else x.url = data.trackViewUrl;
if (eval(data.price) == 0) x.price = '無料';
else x.price = '¥' + fmtNumber(data.price);
x.category = data.genres[0];
for (i = 1; i < data.genres.length; i++) x.category = x.category + ', ' + data.genres[i];
x.pubdate = data.releaseDate.replace(/-/g, '/');
x.pubdate = x.pubdate.replace(/T.*/g, '');
x.icon60url = data.artworkUrl60;
//2015/11/8緊急パッチ
if (data.artworkUrl100) {
x.icon100url = data.artworkUrl100;
} else if (data.artworkUrl512) {
x.icon100url = data.artworkUrl512;
} else {
x.icon100url = data.artworkUrl60;
}
//x.icon100url = data.artworkUrl100;
x.artist = data.artistName;
if (phg != "") x.artisturl = PHGUrl(data.artistViewUrl, phg);
else x.artisturl = data.artistViewUrl;
x.seller = data.sellerName;
x.sellerurl = data.sellerUrl;
x.desc = data.description;
x.descnew = data.releaseNotes;
x.version = data.version;
x.rating = data.trackContentRating;
if (!data.averageUserRatingForCurrentVersion) x.curuserrating = '無し';
else x.curuserrating = data.averageUserRatingForCurrentVersion;
if (!data.userRatingCountForCurrentVersion) {
x.curuserratingcnt = '0件の評価';
} else {
x.curuserratingcnt = fmtNumber(data.userRatingCountForCurrentVersion) + '件の評価';
}
x.curuserratingcnt = x.curuserratingcnt.replace('n,ull', '0');
if (!data.averageUserRating) x.userrating = '無し';
else x.userrating = data.averageUserRating;
if (!data.userRatingCount) {
x.userratingcnt = '0件の評価';
} else {
x.userratingcnt = fmtNumber(data.userRatingCount) + '件の評価';
}
x.userratingcnt = x.userratingcnt.replace('n,ull', '0');
x.appsize = sizeNumber(data.fileSizeBytes);
x.moveos = "";
x.os = "";
x.gamecenter = "";
x.univ = "";
if (knd != 'macSoftware') {
x.moveos = data.supportedDevices[0];
for (i = 1; i < data.supportedDevices.length; i++) x.moveos = x.moveos + ', ' + data.supportedDevices[i];
x.os = x.moveos.replace(/.*all.*/g, 'iPhone');
if (x.os == '') x.os = x.moveos.replace(/.*iPhone.*/g, 'iPhone');
if (x.os == '') x.os = x.moveos.replace(/.*iPad.*/g, 'iPad');
for (i = 0; i < data.features.length; i++) {
if (data.features[i] == 'gameCenter') {
x.gamecenter = 'GameCenter対応';
break;
}
}
for (i = 0; i < data.features.length; i++) {
if (data.features[i] == 'iosUniversal') {
x.univ = 'iPhone/iPadの両方に対応';
break;
}
}
}
x.lang = data.languageCodesISO2A[0];
for (i = 1; i < data.languageCodesISO2A.length; i++)
x.lang = x.lang + ', ' + data.languageCodesISO2A[i];
for (i = 1; i <= 5; i++) {
x['image' + i] = "";
x['univimage' + i] = "";
}
// iPhoneの場合は、UnivスクショにiPad画像をセット(image, univimage)
if (knd == 'software') {
for (i = 0; i < data.screenshotUrls.length; i++) {
if (data.screenshotUrls[i]) {
x['image' + (i + 1)] = '<img alt="ss' + (i + 1) + '" src="' +
data.screenshotUrls[i] + '" ' +
'width="' + data['image' + (i + 1) + 'width'] + 'px">';
}
}
for (i = 0; i < data.ipadScreenshotUrls.length; i++) {
if (data.ipadScreenshotUrls[i]) {
x['univimage' + (i + 1)] = '<img alt="univss' + (i + 1) + '" src="' +
data.ipadScreenshotUrls[i] + '" ' +
'width="' + data['univimage' + (i + 1) + 'width'] + 'px">';
}
}
}
// iPadの場合は、UnivスクショにiPhone画像をセット(image, univimage)
if (knd == 'iPadSoftware') {
for (i = 0; i < data.ipadScreenshotUrls.length; i++) {
if (data.ipadScreenshotUrls[i]) {
x['image' + (i + 1)] = '<img alt="ss' + (i + 1) + '" src="' +
data.ipadScreenshotUrls[i] + '" ' +
'width="' + data['image' + (i + 1) + 'width'] + 'px">';
}
}
for (i = 0; i < data.screenshotUrls.length; i++) {
if (data.screenshotUrls[i]) {
x['univimage' + (i + 1)] = '<img alt="univss' + (i + 1) + '" src="' +
data.screenshotUrls[i] + '" ' +
'width="' + data['univimage' + (i + 1) + 'width'] + 'px">';
}
}
}
// Macの場合は、スクショのみでUnivスクショは無し(image)
if (knd == 'macSoftware') {
for (i = 0; i < data.screenshotUrls.length; i++) {
if (data.screenshotUrls[i]) {
x['image' + (i + 1)] = '<img alt="ss' + (i + 1) + '" src="' +
data.screenshotUrls[i] + '" ' +
'width="' + data['image' + (i + 1) + 'width'] + 'px">';
}
}
}
if (knd == 'software' || knd == 'iPadSoftware'){
x.badgeL = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets/ja_jp//images/web/linkmaker/badge_appstore-lrg.png) no-repeat;width:135px;height:40px;"></a>';
x.badgeS = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets//images/web/linkmaker/badge_appstore-sm.png) no-repeat;width:61px;height:15px;"></a>';
x.textonly = '<a href="' + x.url + '" target="itunes_store">' + x.name + ' - ' + x.artist + '</a>';
}
if (knd == 'macSoftware'){
x.badgeL = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets/ja_jp//images/web/linkmaker/badge_macappstore-lrg.png) no-repeat;width:165px;height:40px;"></a>';
x.badgeS = '<a href="' + x.url + '" target="itunes_store" style="display:inline-block;overflow:hidden;background:url(http://linkmaker.itunes.apple.com/htmlResources/assets//images/web/linkmaker/badge_macappstore-sm.png) no-repeat;width:81px;height:15px;"></a>';
x.textonly = '<a href="' + x.url + '" target="itunes_store">' + x.name + ' - ' + x.artist + '</a>';
}
}
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var dd = now.getDate();
x.today = y + "." + m + "." + dd;
return x;
}
// 数字のカンマ編集
function fmtNumber(x) {
var s = '' + x,
p = s.indexOf('.');
if (p < 0) p = s.length;
var r = s.substring(p, s.length);
for (var i = 0; i < p; i++) {
var c = s.substring(p - 1 - i, p - 1 - i + 1);
if (i > 0 && i % 3 == 0) r = ',' + r;
r = c + r;
}
return r;
}
// サイズ換算
function sizeNumber(x) {
var r = Math.round((eval(x) / 1000000) * 10) / 10;
r = fmtNumber(r);
r = r + ' MB';
return r;
}
// 再生時間を変換
function sizeTime(x) {
var r = Math.round((eval(x) / 60000));
r = fmtNumber(r);
r = r + ' 分';
return r;
}
// PHGアフィリエイトリンクまたはLinkShareリンク生成
function PHGUrl(url, id) {
if (phg != "") {
var affId = '&at=' + id;
var appUrl = url + affId;
return appUrl;
} else
var appUrl = url;
return appUrl;
}
})();