This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
105 lines (95 loc) · 4.09 KB
/
main.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
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
var intervalID = window.setInterval(checkPlayerStartup, 500);
var video;
function checkPlayerStartup(){
video = document.getElementsByClassName("rmp-video")[0]; // Get video
if (video !== undefined){
// Video player loaded
clearInterval(intervalID);
runEnhancements();
}
}
function runEnhancements(){
var containerOptions = document.getElementById("containerOptions");
// Slow down video
var slowDownButton = document.createElement("a");
slowDownButton.innerText = "ABRANDAR";
var slowDownButtonIcon = document.createElement("i");
slowDownButtonIcon.className = "fal fa-turtle";
slowDownButton.prepend(slowDownButtonIcon);
slowDownButton.onclick = function(event){
event.preventDefault();
video.playbackRate -= 0.25;
playbackRateIndicator.update();
};
containerOptions.append(slowDownButton);
// Video playback rate indicator
var playbackRateIndicator = document.createElement("a");
playbackRateIndicator.id = "playbackRateIndicator";
playbackRateIndicator.innerText = "1x";
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-average";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
playbackRateIndicator.onclick = function(event){
event.preventDefault();
video.playbackRate = 1;
playbackRateIndicator.update();
};
playbackRateIndicator.update = function(){
this.innerText = video.playbackRate + "x";
if (video.playbackRate < 0.5){
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-slowest";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
} else if (video.playbackRate < 1){
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-slow";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
} else if (video.playbackRate == 1){
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-average";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
} else if (video.playbackRate <= 1.5){
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-fast";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
} else if (video.playbackRate > 1.5){
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-fastest";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
} else {
var playbackRateIndicatorIcon = document.createElement("i");
playbackRateIndicatorIcon.className = "fal fa-tachometer-alt-average";
playbackRateIndicator.prepend(playbackRateIndicatorIcon);
}
};
containerOptions.append(playbackRateIndicator);
// Speed up video
var speedUpButton = document.createElement("a");
speedUpButton.innerText = "ACELERAR";
var speedUpButtonIcon = document.createElement("i");
speedUpButtonIcon.className = "fal fa-rabbit-fast";
speedUpButton.prepend(speedUpButtonIcon);
speedUpButton.onclick = function(event){
event.preventDefault();
video.playbackRate += 0.25;
playbackRateIndicator.update();
};
containerOptions.append(speedUpButton);
// Download Button
var downloadButton = document.createElement("a");
downloadButton.innerText = "DOWNLOAD";
var downloadButtonIcon = document.createElement("i");
downloadButtonIcon.className = "fal fa-file-download";
downloadButton.prepend(downloadButtonIcon);
downloadButton.href = "https://streaming-ondemand.rtp.pt" + window.wrappedJSObject.player1.fileKey;
downloadButton.target = "_blank";
containerOptions.append(downloadButton);
// Countdown
var countdownDisplay = document.getElementsByClassName("rmp-duration")[0];
countdownDisplay.innerText = "-00:00";
countdownDisplay.update = function(){ countdownDisplay.innerText = "-" + humanTime(video.duration - video.currentTime); };
video.addEventListener('timeupdate', countdownDisplay.update);
}
function humanTime(seconds){
return new Date(seconds * 1000).toISOString().substr(11, 8);
}