forked from gaodeng/fuzhuo.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
199 lines (194 loc) · 6.12 KB
/
home.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
var media_data = {
"data": [
{
"title":"youku",
"subtitle":"",
"show": true,
"index": 0,
"img":`${baseURL}/icons/youku.png`
},
{
"title":"Tumblr",
"subtitle":"",
"show": true,
"index": 1,
"img":`${baseURL}/icons/tumblr.png`
},
{
"title":"lava",
"subtitle":"",
"show": true,
"index": 2,
"img":`${baseURL}/icons/lava.png`
},
{
"title":"NetEaseMusic",
"subtitle":"",
"show": true,
"index": 3,
"img":`${baseURL}/icons/netease_music.png`
},
{
"title":"Ximalaya",
"subtitle":"",
"show": true,
"index": 4,
"img":`${baseURL}/icons/ximalaya.png`
},
{
"title":"直播",
"subtitle":"",
"show": true,
"index": 5,
"img":`${baseURL}/icons/tv.png`
},
{
"title":"PPTV",
"subtitle":"",
"show": true,
"index": 6,
"img":`${baseURL}/icons/pptv.png`
},
{
"title":"Ero",
"subtitle":"Don't Click",
"show": false,
"index": 7,
"img":`${baseURL}/icons/ero.png`
}
]
};
var currentHomeDoc;
var getHomeDoc = function(callback) {
loadHomeHistory();
var docText = `
<document>
<stackTemplate>
<identityBanner>
<banner>
<title>LazyCat</title>
</banner>
<row>
<buttonLockup onselect="showHide()">
<badge src="resource://button-rate" />
<title>切换项目</title>
</buttonLockup>
</row>
</identityBanner>
<collectionList>
<grid>
<section>`;
for (var i in media_data['data']) {
console.log("media_data["+i+"].show="+media_data['data'][i]['show']);
if (media_data['data'][i]['show']==true) {
docText += `
<lockup index="${media_data['data'][i]['index']}">
<img src="${media_data['data'][i]['img']}" width="400" height="240" />
<title>${media_data['data'][i]['title']}</title>
<subtitle>${media_data['data'][i]['subtitle']}</subtitle>
</lockup>`;
}
}
docText += `
</section>
</grid>
</collectionList>
</stackTemplate>
</document>`;
console.log("getHomeDoc: "+docText);
currentHomeDoc = (new DOMParser).parseFromString(docText, "application/xml");
callback(currentHomeDoc);
}
function loadHomeHistory() {
var history = localStorage.getItem('homehistory');
console.log("load history:"+history);
if (typeof history === 'undefined') {
var data = {};
} else {
data = JSON.parse(history);
}
for (var i in media_data['data']) {
var title = media_data['data'][i]['title'];
//console.log("title: " + title + " show: " + data[title]);
if (data[title]!=null) {
if (data[title]==false) media_data['data'][i]['show']=false;
else if (data[title]==true) media_data['data'][i]['show']=true;
}
}
}
function saveHomeHistory() {
var string = localStorage.getItem('homehistory');
if (typeof history === 'undefined') {
var data = {};
} else {
data = JSON.parse(history);
}
for (var md of media_data['data']) {
var title = md['title'];
data[title] = md['show'];
}
console.log("save home history: " + JSON.stringify(data));
localStorage.setItem('homehistory', JSON.stringify(data));
}
function switchItem(index) {
console.log("switch Item at index: " + index);
media_data['data'][index]['show'] = !media_data['data'][index]['show'];
navigationDocument.removeDocument(getActiveDocument());
saveHomeHistory();
showHomePage();
}
function showHide() {
var docText = `<?xml version="1.0" encoding="UTF-8"?>
<document>
<alertTemplate>
<title>请选择项目切换显示或隐藏</title>`;
for (var i in media_data['data']) {
if (media_data['data'][i]['show']) {
docText += `
<button onselect="switchItem(${i})">
<text>${media_data['data'][i]['title']}</text>
<badge src="resource://button-checkmark" style="margin:0 -20 0 20;" />
</button>`;
} else {
docText += `
<button onselect="switchItem(${i})">
<text>${media_data['data'][i]['title']}</text>
</button>`;
}
}
docText += `
</alertTemplate>
</document>`;
console.log("docText:" + docText);
var doc = (new DOMParser).parseFromString(docText, "application/xml");
navigationDocument.pushDocument(doc);
}
var showHomePage = function() {
getHomeDoc(function(doc) {
doc.addEventListener("select", (event)=> {
const target = event.target;
const index = parseInt(target.getAttribute("index"));
console.log("index: " + index);
if (index==0) {
showMainMenu();
} else if (index == 1) {
showTumblrMainPage();
} else if (index == 2) {
showLavaHome();
} else if (index == 3) {
showNetEaseMusicMainPage();
} else if (index == 4) {
showXimalayaMainMenuDoc();
} else if (index == 5) {
showTVHome();
} else if (index == 6) {
showPPTVMainMenu();
} else if (index == 7) {
showEroHome(1, "", false);
} else {
return;
}
});
navigationDocument.replaceDocument(doc, getActiveDocument());
});
}