-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.js
48 lines (28 loc) · 966 Bytes
/
widget.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
async function loadGifs() {
let api_key='replace_with_your_key';
let query = 'transparent-dancing';
let url = 'https://api.giphy.com/v1/gifs/search?api_key='+ api_key + '&q='+query;
const response = await fetch(url);
let gifs = await response.json();
return gifs;
}
function selectRandomGif(gifs) {
return gifs[Math.floor(Math.random()*gifs.length)];
}
function placeGifOnScreen(gif) {
let webp = gif.images.fixed_height.webp
let id = BWProperties['namespace'] + "_account_"+BWProperties['participant']['account']['id'];
let element = document.createElement('img')
element.src = webp;
let gif_container = document.getElementById(id);
if(gif_container) {
gif_container.innerHTML = ""
gif_container.appendChild(element);
}
}
async function load() {
let gifs = await loadGifs();
let gif = selectRandomGif(gifs.data);
placeGifOnScreen(gif);
}
load();