-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_example.html
More file actions
89 lines (83 loc) · 2.61 KB
/
query_example.html
File metadata and controls
89 lines (83 loc) · 2.61 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
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
<!DOCTYPE html>
<html>
<head>
<title>数据获取 DEMO</title>
</head>
<body>
<span>获取用户视频观看历史</span>
<pre id="show_script_visited_videos"></pre>
<button onclick="click_visited_videos()">执行</button>
<pre id="visited_videos">null</pre>
<span>获取用户视频观看历史</span>
<pre id="show_script_viewed_ads"></pre>
<button onclick="click_viewed_ads()">执行</button>
<pre id="viewed_ads"></pre>
</body>
<script>
async function click_visited_videos () {
let result = await getVisitedVideos("test")
string = ""
result.forEach(element => {
string +=
element.time.split('.')[0].replace('T',' ')
+ "\t" + element.title + "\n"
});
document.getElementById("visited_videos")
.innerHTML = string
}
async function click_viewed_ads () {
let result = await getViewedAds("test")
string = ""
result.forEach(element => {
string += element.ad_id + " "
+ element.brand + " "
+ element.product + "\n"
});
document.getElementById("viewed_ads")
.innerHTML = string
}
// Show scripts on screen
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("show_script_visited_videos").textContent = document.getElementById("script_visited_videos").innerHTML
document.getElementById("show_script_viewed_ads").textContent = document.getElementById("script_viewed_ads").innerHTML
});
</script>
</html>
<script id="script_visited_videos">
// Fetch visited videos as a list from server
async function getVisitedVideos (pid) {
let res = await fetch(
"https://midroll.funtubevideo.cn/api/research/history?pid="+pid)
let data = await res.json()
return data.result
}
</script>
<script id="script_viewed_ads">
// Fetch viewed ads from server
async function getViewedAds (pid) {
let response = await fetch(
"https://midroll.funtubevideo.cn/api/research/ads?pid="+pid)
let data = await response.json()
return data.result
}
</script>
<style>
body{
padding-top: 1em;
}
pre{
background-color: #eee;
padding-left: 1em;
padding-bottom: 1em;
}
#visited_videos{
padding-top: 1em;
}
#viewed_ads{
padding-top: 1em;
}
button{
padding: 5px;
width: 100px;
}
</style>