-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.js
More file actions
57 lines (49 loc) · 1.77 KB
/
Copy pathdata.js
File metadata and controls
57 lines (49 loc) · 1.77 KB
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
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const createScriptReader = html => {
return id => {
const str = `id="${id}">`;
const s1 = html.indexOf(str);
const e1 = html.indexOf('</script>', s1);
const script = html.substring(s1 + str.length, e1);
return script;
};
};
const getData = text => {
const p1 = text.indexOf('=');
return JSON.parse(text.slice(p1 + 2, -11))
};
/**
* Fetch and log a request
* @param {Request} request
*/
async function handleRequest(request) {
const response = await fetch(`https://3g.dxy.cn/newh5/view/pneumonia`)
const html = await response.text();
const getScript = createScriptReader(html);
const getAreaStat = getScript('getAreaStat');
const getWikiList = getScript('getWikiList');
const getIndexRumorList = getScript('getIndexRumorList');
const getTimelineService = getScript('getTimelineService');
const getStatisticsService = getScript('getStatisticsService');
const getIndexRecommendList = getScript('getIndexRecommendList');
const getListByCountryTypeService1 = getScript('getListByCountryTypeService1');
const body = {
AreaStat: getData(getAreaStat),
WikiList: getData(getWikiList),
IndexRumorList: getData(getIndexRumorList),
TimelineService: getData(getTimelineService),
StatisticsService: getData(getStatisticsService),
IndexRecommendList: getData(getIndexRecommendList),
ListByCountryTypeService1: getData(getListByCountryTypeService1),
};
const headers = {
'content-type': 'application/json',
'Access-Control-Allow-Origin': '*'
};
return new Response(JSON.stringify(body), {
status: 200,
headers
});
}