-
Notifications
You must be signed in to change notification settings - Fork 0
/
content2.js
61 lines (48 loc) · 1.57 KB
/
content2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var episodes = document.getElementsByClassName("oce_list list")[0].children;
const Unis =["tu-braunschweig.de",
"uni-bremen.de"];
var UniId = 0;
var url = document.location.href;
for (i=0; i<Unis.length; i++){
if(url.includes(Unis[i])){
UniId = i;
break;
}
}
console.log("UniId: "+UniId+" as "+Unis[UniId]);
createBtn();
function createBtn(){
for(i = 0; i < episodes.length; i++) {
var button = document.createElement("button");
button.title="Download";
button.id ="LinkBtn_"+i;
button.setAttribute('type', 'button');
button.style ='font-size: 20px; cursor: pointer; display: block;';
button.innerText = ("Download");
episodes[i].children[1].appendChild(button);
button.onclick = function click(clicked){
var id = clicked.target.id.split("_")[1];
var videoID = episodes[id].id;
download(videoID);
}
}
}
function download(id){
console.log("download video id: "+id);
chrome.runtime.sendMessage({UniId: UniId, vidId: id, vidForm: null, download: "true"}, function(response) {
console.log(response.videoName);
});
}
var buttonA = document.createElement("button");
buttonA.title="Download all";
buttonA.id ="LinkBtn_All";
buttonA.setAttribute('type', 'button');
buttonA.style ='font-size: 17px; cursor: pointer; display: inline;';
buttonA.innerText = ("Download all videos");
document.getElementsByTagName("form")[2].appendChild(buttonA);
buttonA.onclick = function clickAll(clicked){
for (i=0; i<episodes.length; i++){
var videoID = episodes[i].id;
download(videoID);
}
}