-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
50 lines (48 loc) · 1.69 KB
/
content.js
File metadata and controls
50 lines (48 loc) · 1.69 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
const observer = new MutationObserver((mutations) => {
var related = document.getElementById("related");
if(related) {
related.parentNode.removeChild(related);
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "http://localhost:5000/api/v1/recommendations", false);
xhttp.send({"videos": window.location.href});
console.log(xhttp.responseText);
var response = JSON.parse(xhttp.responseText);
console.log(response);
var main = document.getElementById("container");
var rec = document.createElement("div");
rec.style.cssFloat = "right";
rec.style.position = "relative";
rec.style.top = "300px";
rec.style.clear = "right";
var list = document.createElement("div");
list.style.display = "block";
for(vid of response) {
var item = document.createElement("div");
item.style.display = "block";
item.style.backgroundColor = "#DCDCDC";
item.style.font = "bold 15px arial";
item.style.margin = "10px";
item.style.width = "400px";
var link = document.createElement("a");
link.href = vid.video_url;
var thumbnail = document.createElement("img");
thumbnail.src = vid.thumbnail_url;
thumbnail.style.height = "64px";
thumbnail.style.verticalAlign = "top";
var titleDiv = document.createElement("div");
var title = document.createTextNode(vid.title);
titleDiv.appendChild(title);
link.appendChild(thumbnail);
link.appendChild(titleDiv);
item.appendChild(link);
console.log("item added");
list.appendChild(item);
}
rec.appendChild(list);
main.appendChild(rec);
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});