-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
169 lines (138 loc) · 4.62 KB
/
index.html
File metadata and controls
169 lines (138 loc) · 4.62 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
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
<!DOCTYPE html>
<html lang="en">
<!-- Or Schweitzer -->
<head>
<title>Taboola</title>
<style>
body {
max-width: 900px;
margin: 0 auto;
font-family: "Open Sans", "Arial", sans-serif;
}
#widgetHeader {
display: flex;
}
#headerMayLike {
flex: 1;
text-align: left;
font-weight: bold;
}
#headerMiddle {
flex: 1;
}
#headerSponsoredBy {
flex: 1;
text-decoration: none;
color: black;
text-align: right;
}
#widget {
background-color: rgba(229, 229, 229, 0.881);
}
#taboolaItems {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 5px;
}
#taboolaItems a {
pointer-events: none;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.thumbnail {
pointer-events: auto;
width: 100%;
height: 70%;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
}
img:hover {
opacity: 0.8;
filter: alpha(opacity=100);
}
.title {
pointer-events: auto;
color: black;
font-weight: bold;
}
.branding {
pointer-events: auto;
font-size: 0.7em;
color: rgb(100, 100, 100);
font-weight: bold;
}
/*When the screen is small (like mobile devices)*/
@media only screen and (max-width: 768px) {
#taboolaItems {
display: grid;
grid-template-columns: 1fr;
gap: 10px;
}
}
</style>
</head>
<body>
<div id="widget">
<div id="widgetHeader">
<div id="headerMayLike">You May Like</div>
<div id="headerMiddle"></div>
<a id="headerSponsoredBy" href="https://www.taboola.com">Sponsored by Taboola</a>
</div>
<div id="taboolaItems"></div>
</div>
<script>
async function getTaboolaItems() {
try {
const response = await fetch('https://api.taboola.com/1.2/json/apitestaccount/recommendations.get?app.type=web&app.apikey=7be65fc78e52c11727793f68b06d782cff9ede3c&source.id=%2Fdigiday-publishing-summit%2F&source.url=https%3A%2F%2Fblog.taboola.com%2Fdigiday-publishing-summit%2F&source.type=text&placement.organic-type=mix&placement.visible=true&placement.available=true&placement.rec-count=6&placement.name=Below%20Article%20Thumbnails&placement.thumbnail.width=640&placement.thumbnail.height=480&user.session=init');
const resJson = await response.json();
const itemsToRender = resJson.list;
//The items container
const containerDiv = document.getElementById('taboolaItems');
//render each item
itemsToRender.forEach(item => {
//set url
const anchor = document.createElement('a');
anchor.href = item.url;
//set thumbnail
const thumbnail = document.createElement('div');
thumbnail.className = "thumbnail"
const img = document.createElement('img');
img.src = item.thumbnail[0].url;
thumbnail.appendChild(img);
//set title
const itemTitle = document.createElement('p');
itemTitle.className = 'title'
itemTitle.textContent = `${item.name}`;
//set branding
const branding = document.createElement('p');
branding.className = 'branding';
branding.textContent = `${item.branding}`;
// make thumbnail, title and branding clickable
anchor.appendChild(thumbnail);
anchor.appendChild(itemTitle);
anchor.appendChild(branding);
//add current item to view
containerDiv.appendChild(anchor);
});
} catch (err) {
console.error(err);
}
}
// fetch data from Taboola API
getTaboolaItems();
</script>
</body>
</html>