-
Notifications
You must be signed in to change notification settings - Fork 5
/
AppHtmlWeb.js
531 lines (463 loc) · 18.2 KB
/
AppHtmlWeb.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
/*
* ApphtmlWeb.js
* @version 2.1
* @author Toshiya NISHIO(http://www.toshiya240.com)
*/
////////////////////////////////////////////////////////////////////////////////
// 設定値の永続化
var storage = {
set: function(key, obj) {
this.remove(key);
window.localStorage.setItem(key, JSON.stringify(obj));
},
get: function(key) {
var val = window.localStorage.getItem(key);
if (val == null || val == "undefined") {
return "";
} else {
return JSON.parse(val);
}
},
remove: function(key) {
window.localStorage.removeItem(key);
},
clear: function() {
window.localStorage.clear();
}
};
function loadConfig() {
var conf_aff = storage.get("apphtml_conf_aff");
var conf_count = storage.get("apphtml_conf_count");
if (conf_count == "") conf_count = 8;
var conf_iphone_scs = storage.get("apphtml_conf_iphone_scs");
if (conf_iphone_scs == "") conf_iphone_scs = 288;
var conf_iphone_ipd = storage.get("apphtml_conf_iphone_ipd");
if (conf_iphone_ipd == "") conf_iphone_ipd = 1.5;
var conf_ipad_scs = storage.get("apphtml_conf_ipad_scs");
if (conf_ipad_scs == "") conf_ipad_scs = 432;
var conf_ipad_ipd = storage.get("apphtml_conf_ipad_ipd");
if (conf_ipad_ipd == "") conf_ipad_ipd = 0.67;
var conf_mac_scs = storage.get("apphtml_conf_mac_scs");
if (conf_mac_scs == "") conf_mac_scs = 480;
$("#conf_aff").val(conf_aff);
$("#conf_count").val(conf_count);
$("#conf_iphone_scs").val(conf_iphone_scs);
$("#conf_iphone_ipd").val(conf_iphone_ipd);
$("#conf_ipad_scs").val(conf_ipad_scs);
$("#conf_ipad_ipd").val(conf_ipad_ipd);
$("#conf_mac_scs").val(conf_mac_scs);
};
function reloadConfig() {
loadConfig();
conf_template = storage.get("apphtml_conf_template");
if (conf_template == "") conf_template = preset();
setOutSelection();
$("#conf_out").selectmenu("refresh");
}
function saveConfig() {
storage.set("apphtml_conf_aff", $("#conf_aff").val());
storage.set("apphtml_conf_count", $("#conf_count").val());
storage.set("apphtml_conf_out", $("#conf_out option:selected").val());
storage.set("apphtml_conf_iphone_scs", $("#conf_iphone_scs").val());
storage.set("apphtml_conf_iphone_ipd", $("#conf_iphone_ipd").val());
storage.set("apphtml_conf_ipad_scs", $("#conf_ipad_scs").val());
storage.set("apphtml_conf_ipad_ipd", $("#conf_ipad_ipd").val());
storage.set("apphtml_conf_mac_scs", $("#conf_mac_scs").val());
storage.set("apphtml_conf_template", conf_template);
setTemplateSelection();
$("#template").selectmenu("refresh");
return true;
}
function showStringifiedConf() {
var conf_aff = storage.get("apphtml_conf_aff");
var conf_count = storage.get("apphtml_conf_count");
if (conf_count == "") conf_count = 8;
var conf_iphone_scs = storage.get("apphtml_conf_iphone_scs");
if (conf_iphone_scs == "") conf_iphone_scs = 288;
var conf_iphone_ipd = storage.get("apphtml_conf_iphone_ipd");
if (conf_iphone_ipd == "") conf_iphone_ipd = 1.5;
var conf_ipad_scs = storage.get("apphtml_conf_ipad_scs");
if (conf_ipad_scs == "") conf_ipad_scs = 432;
var conf_ipad_ipd = storage.get("apphtml_conf_ipad_ipd");
if (conf_ipad_ipd == "") conf_ipad_ipd = 0.67;
var conf_mac_scs = storage.get("apphtml_conf_mac_scs");
if (conf_mac_scs == "") conf_mac_scs = 480;
var conf_out = storage.get("apphtml_conf_out");
if (conf_out == "") conf_out = "popup";
conf_template = storage.get("apphtml_conf_template");
if (conf_template == "") conf_template = preset();
var conf = {};
conf.conf_aff = conf_aff;
conf.conf_count = conf_count;
conf.conf_iphone_scs = conf_iphone_scs;
conf.conf_iphone_ipd = conf_iphone_ipd;
conf.conf_ipad_scs = conf_ipad_scs;
conf.conf_ipad_ipd = conf_ipad_ipd;
conf.conf_mac_scs = conf_mac_scs;
conf.conf_out = conf_out;
conf.conf_template = conf_template;
$("#stringified-data").val(JSON.stringify(conf));
$.mobile.changePage('#stringified-conf', {transition:'pop'});
}
function closeStringifiedConf() {
$.mobile.changePage('#conf', {transition:'pop', reverse:true});
}
function importConf() {
var stringifiedConf = "";
try {
stringifiedConf = JSON.parse($("#stringified-data").val());
} catch (e) {
showMessage("パースに失敗しました。(" + e + ")");
return;
}
storage.set("apphtml_conf_aff", stringifiedConf.conf_aff);
storage.set("apphtml_conf_count", stringifiedConf.conf_count);
storage.set("apphtml_conf_out", stringifiedConf.conf_out);
storage.set("apphtml_conf_iphone_scs", stringifiedConf.conf_iphone_scs);
storage.set("apphtml_conf_iphone_ipd", stringifiedConf.conf_iphone_ipd);
storage.set("apphtml_conf_ipad_scs", stringifiedConf.conf_ipad_scs);
storage.set("apphtml_conf_ipad_ipd", stringifiedConf.conf_ipad_ipd);
storage.set("apphtml_conf_mac_scs", stringifiedConf.conf_mac_scs);
storage.set("apphtml_conf_template", stringifiedConf.conf_template);
reloadConfig();
setTemplateSelection();
$("#template").selectmenu("refresh");
showMessage("インポートに成功しました。");
}
////////////////////////////////////////////////////////////////////////////////
// テンプレート定義
var conf_template = {};
function Template(name, content) {
this.name = name;
this.content = content;
}
function defaultTemplate() {
return [
new Template('小さいボタン', '${badgeS}'),
new Template('大きいボタン', '${badgeL}'),
new Template('テキストのみ', '${textonly}'),
new Template('アイコン付き(小)', '<span class="appIcon"><img class="appIconImg" height="60" src="${icon60url}" style="float:left;margin: 0px 15px 15px 5px;"></span><span class="appName"><strong><a href="${url}" target="itunes_store">${name}</a></strong></span><br><span class="appCategory">カテゴリ: ${category}</span><br><span class="badgeS" style="display:inline-block; margin:6px">${badgeS}</span><br style="clear:both;">'),
new Template('アイコン付き(大)', '<span class="appIcon"><img class="appIconImg" height="100" src="${icon100url}" style="float:left;margin: 0px 15px 15px 5px;"></span><span class="appName"><strong><a href="${url}" target="itunes_store">${name}</a></strong></span><br><span class="appCategory">カテゴリ: ${category}</span><br><span class="badgeL" style="display:inline-block; margin:4px">${badgeL}</span><br style="clear:both;">')
];
};
function preset() {
return {
'software': defaultTemplate(),
'iPadSoftware': defaultTemplate(),
'macSoftware': defaultTemplate(),
'song': defaultTemplate(),
'album': defaultTemplate(),
'movie': defaultTemplate(),
'ebook': defaultTemplate()
};
};
var selectedTemplateIndex = undefined;
function saveTemplate() {
var addmode = (selectedTemplateIndex == -1);
var name = $("#template-editor-name").val();
var content = $("#template-editor-content").val();
if (!name || !content) {
showMessage("名前と内容を入力してください。");
return false;
}
var title = $("#template-list-title").text();
var kind = entity[title];
if (addmode) {
conf_template[kind].push(new Template(name, content));
} else {
var selectedTemplate = conf_template[kind][selectedTemplateIndex];
selectedTemplate.name = name;
selectedTemplate.content = content;
}
var title = $("#template-list-title").text();
showTemplateList(title, {transition:"slideup", reverse:true});
return true;
}
function deleteTemplate() {
// TODO: 確認ダイアログを表示した方がよいか?
var title = $("#template-list-title").text();
var kind = entity[title];
conf_template[kind].splice(selectedTemplateIndex, 1);
var title = $("#template-list-title").text();
showTemplateList(title, {transition:"slideup", reverse:true});
}
function addTemplate() {
showTemplateEditor(-1);
}
////////////////////////////////////////////////////////////////////////////////
// 画面共通
var entity = {
'iPhone App': 'software',
'iPad App': 'iPadSoftware',
'Mac App': 'macSoftware',
'Song': 'song',
'Album': 'album',
'Movie': 'movie',
'Book': 'ebook',
};
////////////////////////////////////////////////////////////////////////////////
// 検索画面
function setKindSelection() {
$kind = $("#kind");
$kind.empty();
for (var label in entity) {
$kind.append($("<option>").text(label).val(entity[label]));
}
$("#kind option").eq(0).attr("selected", true);
}
function setTemplateSelection() {
var $templateSelection = $("#template");
$templateSelection.empty();
var kind = $("#kind option:selected").val();
var selectedTemplate = conf_template[kind];
for (var i = 0; i < selectedTemplate.length; i++) {
var text = selectedTemplate[i].name;
var val = selectedTemplate[i].content;
$templateSelection.append($("<option>").text(text).val(val));
}
$("#template option").eq(0).attr("selected", true);
};
$(document).on("change", "#kind", function() {
setTemplateSelection();
$("#template").selectmenu("refresh");
});
function search() {
var kind = $("#kind option:selected").val();
var fmt = $("#template option:selected").val();
var d = document,
e = d.createElement('script');
var url = "apphtml.js";
if (!url.match(/\?/)) url += '?t=' + (new Date()).getTime();
e.out = $("#conf_out").val();
e.cnt = $("#conf_count").val();
e.knd = kind;
e.phg = $("#conf_aff").val();
e.scs = getScs(kind);
e.ipd = getIpd(kind);
e.fmt = encodeURIComponent(fmt);
e.charset = 'utf-8';
e.src = url;
e.id = 'bmlt';
d.body.appendChild(e);
};
function getScs(kind) {
switch (kind) {
case 'software':
return $("#conf_iphone_scs").val();
case 'iPadSoftware':
return $("#conf_ipad_scs").val();
case 'macSoftware':
return $("#conf_mac_scs").val();
}
}
function getIpd(kind) {
switch (kind) {
case 'software':
return $("#conf_iphone_ipd").val();
case 'iPadSoftware':
return $("#conf_ipad_ipd").val();
case 'macSoftware':
return 0;
}
}
////////////////////////////////////////////////////////////////////////////////
// 設定画面
var outParams = {
"ポップアップ": "popup",
"ポップアップ→Textforce": "pop-textforce",
"Textforce": "textforce",
"Textforce→Safari": "safari-textforce",
"DraftPad": "draftpad",
"するぷろ": "slpro",
"Moblogger": "moblogger",
"Moblogger(追記)": "moblogger-app",
"Moblogger(コピー)": "moblogger-pb",
"MyEditor": "myeditor",
"MyEditor(カーソル)": "myeditor-cursor",
"Rowline": "rowline",
"TextHandler": "msth",
"ThumbEdit(送信)": "thumbedit",
"ThumbEdit(追記)": "thumbedit-insert",
"PressSync Pro": "presssync",
"Textwell": "textwell",
"はてなブログ(新規投稿)": "hatenablog",
"Drafts": "drafts",
"Drafts 4": "drafts4",
"AmeEditor": "ameeditor",
"SLPRO X": "slpro-x"
};
function setOutSelection() {
var conf_out = storage.get("apphtml_conf_out");
if (conf_out == "") conf_out = "popup";
var $conf_out = $("#conf_out");
$conf_out.empty();
for (var label in outParams) {
$conf_out.append($("<option>").text(label).val(outParams[label]));
}
$conf_out.find("option[value="+conf_out+"]").attr("selected", true);
}
function showTemplateList(title, option) {
if (!option) {
option = {};
option.transition = 'slide';
}
$("#template-list-title").text(title);
var $templateListView = $("#template-list-view");
$templateListView.empty();
var kind = entity[title];
var selectedTemplate = conf_template[kind];
for (var i = 0; i < selectedTemplate.length; i++) {
var text = selectedTemplate[i].name;
var val = selectedTemplate[i].content;
var $li = $("<li>");
$li.append($("<a>").text(text).attr(
'href', 'javascript:showTemplateEditor("'+i+'");'));
$templateListView.append($li);
}
$.mobile.changePage("#template-list", option);
$templateListView.listview("refresh");
}
function showTemplateEditor(index) {
var addmode = (index == -1);
selectedTemplateIndex = index;
var title = $("#template-list-title").text();
$("#template-editor-title").text(title);
var kind = entity[title];
if (!addmode) {
var selectedTemplate = conf_template[kind][index];
$("#template-editor-name").val(selectedTemplate.name);
$("#template-editor-content").val(selectedTemplate.content);
} else {
$("#template-editor-name").val("");
$("#template-editor-content").val("");
}
var $placeholderList = $("#placeholder-list");
$placeholderList.empty();
for (var i = 0; i < placeholderList.length; ++i) {
var ph = placeholderList[i];
if (kind in ph.avail) {
var $li = $("<li>");
$li.append(
$("<a>").text(ph.name).attr(
'href', 'javascript:insertPlaceholder("'+i+'");'));
$placeholderList.append($li);
}
}
if (addmode) {
$("#template-editor-delete-btn-area").hide();
} else {
$("#template-editor-delete-btn-area").show();
}
$.mobile.changePage("#template-editor", {transition: "slideup"});
$placeholderList.listview("refresh");
}
$(document).on("swipeleft", "#template-editor", function() {
$("#template-editor-panel").panel("open");
});
////////////////////////////////////////////////////////////////////////////////
// 予約語入力支援
var allEntity = {
software:"",
iPadSoftware:"",
macSoftware:"",
song:"",
album:"",
movie:"",
ebook:""
};
var appEntity = {
software:"",
iPadSoftware:"",
macSoftware:"",
};
var iOSEntity = {
software:"",
iPadSoftware:"",
};
var appAndEbookEntity = {
software:"",
iPadSoftware:"",
macSoftware:"",
ebook:""
};
function Placeholder(name, kwd, avail) {
this.name = name;
this.kwd = kwd;
this.avail = avail;
};
var placeholderList = [
new Placeholder('小さいボタン', '${badgeS}', allEntity),
new Placeholder('大きいボタン', '${badgeL}', allEntity),
new Placeholder('テキストのみ', '${textonly}', allEntity),
new Placeholder('名前', '${name}', allEntity),
new Placeholder('ストアへのリンク', '${url}', allEntity),
new Placeholder('プレビューURL', '${preview}', {song:"", movie:""}),
new Placeholder('価格', '${price}', allEntity),
new Placeholder('カテゴリ', '${category}', allEntity),
new Placeholder('再生時間', '${playtime}', {movie:""}),
new Placeholder('トラック数', '${trackcnt}', {song:"", album:""}),
new Placeholder('リリース日', '${pubdate}', allEntity),
new Placeholder('アイコン100', '${icon100url}', allEntity),
new Placeholder('アイコン60', '${icon60url}', allEntity),
new Placeholder('アーティスト名', '${artist}', allEntity),
new Placeholder('アーティストURL', '${artisturl}', allEntity),
new Placeholder('販売元', '${seller}', appEntity),
new Placeholder('販売元サイトURL', '${sellerurl}', appEntity),
new Placeholder('コピーライト', '${copyr}', {album:""}),
new Placeholder('説明', '${desc}', {software:"", iPadSoftware:"", macSoftware:"", movie:"", ebook:""}),
new Placeholder('What\'s New', '${descnew}', appEntity),
new Placeholder('短い説明', '${shortdesc}', {movie:""}),
new Placeholder('バージョン', '${version}', appEntity),
new Placeholder('レーティング', '${rating}', appEntity),
new Placeholder('評価★', '${userrating}', appAndEbookEntity),
new Placeholder('レビュー件数', '${userratingcnt}', appAndEbookEntity),
new Placeholder('評価★(現)', '${curuserrating}', appEntity),
new Placeholder('レビュー件数(現)', '${curuserratingcnt}', appEntity),
new Placeholder('サイズ', '${appsize}', appEntity),
new Placeholder('サポートデバイス', '${moveos}', iOSEntity),
new Placeholder('言語', '${lang}', appEntity),
new Placeholder('GameCenter対応', '${gamecenter}', iOSEntity),
new Placeholder('ユニバーサル対応', '${univ}', iOSEntity),
new Placeholder('スクリーンショット1', '${image1}', appEntity),
new Placeholder('スクリーンショット2', '${image2}', appEntity),
new Placeholder('スクリーンショット3', '${image3}', appEntity),
new Placeholder('スクリーンショット4', '${image4}', appEntity),
new Placeholder('スクリーンショット5', '${image5}', appEntity),
new Placeholder('スクリーンショット(univ)1', '${univimage1}', iOSEntity),
new Placeholder('スクリーンショット(univ)2', '${univimage2}', iOSEntity),
new Placeholder('スクリーンショット(univ)3', '${univimage3}', iOSEntity),
new Placeholder('スクリーンショット(univ)4', '${univimage4}', iOSEntity),
new Placeholder('スクリーンショット(univ)5', '${univimage5}', iOSEntity),
new Placeholder('実行日', '${today}', allEntity)
];
function insertPlaceholder(index) {
var ph = placeholderList[index];
var content = $("#template-editor-content").get(0);
var orig = content.value;
var pos = content.selectionStart;
var npos = pos + ph.kwd.length;
content.value = orig.substr(0, pos) + ph.kwd + orig.substr(pos);
content.setSelectionRange(npos, npos);
$("#template-editor-panel").panel("close");
content.focus();
}
////////////////////////////////////////////////////////////////////////////////
// その他
function showMessage(msg) {
$("#error_msg").text(msg);
$dialog = $("<a href='#error_page' data-rel='dialog'></a>");
$dialog.get(0).click();
$dialog.remove();
}
////////////////////////////////////////////////////////////////////////////////
// 初期化
$(function() {
loadConfig();
});
$(document).on("pagebeforecreate", "#main", function() {
conf_template = storage.get("apphtml_conf_template");
if (conf_template == "") conf_template = preset();
setKindSelection();
setOutSelection();
setTemplateSelection();
});