-
Notifications
You must be signed in to change notification settings - Fork 3
/
edX Super Speed.user.js
89 lines (83 loc) · 3.73 KB
/
edX Super Speed.user.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
// ==UserScript==
// @name edX Super Speed
// @namespace http://ericpryzant.com/
// @version 0.5.1
// @description Try to take over the world!
// @author Eric Pryzant
// @match https://courses.edx.org/xblock/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
var item = document.getElementsByClassName("video-speeds")[0];
var new_speed = document.createElement("li");
var btn = document.createElement("button");
var speed_limit = "2.50";
btn.setAttribute("class", "control speed-option");
btn.setAttribute("tabindex", -1);
btn.setAttribute("aria-pressed", "false");
new_speed.appendChild(btn);
new_speed.setAttribute("data-speed", speed_limit);
new_speed.children[0].innerText = speed_limit + "x";
item.prepend(new_speed);
item = document.getElementsByClassName("video-speeds")[0];
new_speed = document.createElement("li");
btn = document.createElement("button");
speed_limit = "3.0";
btn.setAttribute("class", "control speed-option");
btn.setAttribute("tabindex", -1);
btn.setAttribute("aria-pressed", "false");
new_speed.appendChild(btn);
new_speed.setAttribute("data-speed", speed_limit);
new_speed.children[0].innerText = speed_limit + "x";
item.prepend(new_speed);
item = document.getElementsByClassName("video-speeds")[0];
new_speed = document.createElement("li");
btn = document.createElement("button");
speed_limit = "4.0";
btn.setAttribute("class", "control speed-option");
btn.setAttribute("tabindex", -1);
btn.setAttribute("aria-pressed", "false");
new_speed.appendChild(btn);
new_speed.setAttribute("data-speed", speed_limit);
new_speed.children[0].innerText = speed_limit + "x";
item.prepend(new_speed);
const keySpace = 32;
const keyLeft = 37;
const keyRight = 39;
document.addEventListener("keydown", function(event) {
const code = event.keyCode;
const alt = event.altKey;
//console.log("Key pressed " + code + " " + alt);
if (code == keySpace) {
var playPauseButton = document.getElementsByClassName("video_control");
playPauseButton[0].click()
event.preventDefault();
} else if (code == keyLeft) {
if (!alt) {
document.getElementsByClassName("current")[0].previousElementSibling.children[0].click()
event.preventDefault();
} else {
document.getElementsByClassName("current")[0].previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.children[0].click()
event.preventDefault();
}
} else if (code == keyRight) {
if (!alt) {
document.getElementsByClassName("current")[0].nextElementSibling.children[0].click()
event.preventDefault();
} else {
document.getElementsByClassName("current")[0].nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.children[0].click()
event.preventDefault();
}
}
})
var vid = document.getElementsByClassName("video")[0];
var vid_url = vid.attributes['data-metadata'].value.toString().match("https://[\\w\-\.\/]+.mp4")[0];
var vid_title = vid.previousElementSibling.innerText;
var zNode = document.createElement ('div');
zNode.innerHTML = '<button id="myButton" type="button"><a href=' + vid_url + '>Download ' + vid_title + ' lecture video</a></button>';
zNode.setAttribute ('id', 'myContainer');
zNode.style = "top:0;right:0;position:absolute;z-index:99999;padding:20px;";
document.body.appendChild (zNode);
})();