forked from KLVN/MediasiteDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSBookmarklet.js
136 lines (133 loc) · 5 KB
/
MSBookmarklet.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
javascript: (function () {
$.ajax({
url: window.location.origin + document.getElementById('ServicePath').innerHTML + '/GetPlayerOptions',
type: 'POST',
data: JSON.stringify({
'getPlayerOptionsRequest': {
'ResourceId': document.getElementById('ResourceId').innerHTML,
'QueryString': '',
'UseScreenReader': 'false',
'UrlReferrer': ''
}
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (playerOpts) {
$('head').append('<style type=\'text/css\'>\
.modal-window {\
position: fixed;\
display: flex;\
justify-content: center;\
align-items: center;\
background-color: rgba(0, 0, 0, 0.75);\
top: 0;\
right: 0;\
bottom: 0;\
left: 0;\
z-index: 999;\
opacity: 0;\
pointer-events: none;\
}\
.modal-window:target {\
opacity: 1;\
pointer-events: auto;\
}\
.modal-window > div {\
width: 450px;\
position: absolute;\
padding: 3em;\
background: #ffffff;\
color: #333333;\
border-radius: 5px;\
}\
.modal-window header {\
font-weight: bold;\
}\
.modal-window h1 {\
font-size: 150%;\
margin: 0 0 15px;\
color: #333333;\
}\
.modal-close {\
color: #4c4c4c;\
line-height: 35px;\
position: absolute;\
right: 5px;\
text-align: center;\
top: 5px;\
width: 70px;\
text-decoration: none;\
border: #4c4c4c;\
border-style: solid;\
border-radius: 5px;\
border-width: 1px;\
}\
.modal-window > div > ul > li {\
margin: 10px 0;\
}\
.MSDLthumbnail {\
width: 350px;\
vertical-align: middle;\
margin-bottom: 4px;\
}\
div#MSDLinfo {\
max-height: 70vh;\
min-height: 5vh;\
overflow-y: auto;\
}\
</style>');
if (document.contains(document.getElementById("open-modal"))) {
document.getElementById("open-modal").remove();
}
if (playerOpts.d.Presentation.PlayStatus != "OnDemand") {
$('body').append(
'<div id="open-modal" class="modal-window"> \
<div>\
<a href="#" title="Close" class="modal-close">Close</a>\
<p style="font-size: 20px;">Lecture is currently not available on-demand and therefore cannot be downloaded.<br>Try again later.</p>\
</div>\
</div>');
} else {
$('body').append(
'<div id="open-modal" class="modal-window">\
<div>\
<div style="font-size: 20px;line-height: 45px;position: absolute;left: 20px;top: 5px;">MediasiteDownloader (<a href="https://github.com/KLVN/MediasiteDownloader" target="_blank">GitHub</a>)</div>\
<a href="#" title="Close" class="modal-close">Close</a>\
<div id="MSDLinfo">\
<ul style="list-style: outside; !important">\
<li>Copy the title: <input type="text" onClick="this.select();" value="' + document.title + '"></li>\
<li>Right-click on the thumbnail(s) and choose "Save <span style="font-weight: bold;">link</span> as..."</li>\
<div id="MSDLvideos"></div>\
<li>Paste in to rename file correctly and save it</li>\
<li>Click <a href="https://klvn.github.io/MediasiteDownloader/" target="_blank">here</a> for more detailed instructions</li>\
</ul>\
</div>\
</div>\
</div>');
var allPresentations = playerOpts.d.Presentation.Streams;
var videoAvailable = false;
for (var i = 0; i < allPresentations.length; i++) {
if (allPresentations[i].VideoUrls.length) {
for (var j = 0; j < allPresentations[i].VideoUrls.length; j++) {
if (allPresentations[i].VideoUrls[j].MimeType == "video/mp4") {
videoAvailable = true;
var thumbnail = window.location.origin + allPresentations[i].ThumbnailUrl;
var videoUrl = allPresentations[i].VideoUrls[j].Location;
document.getElementById("MSDLvideos").innerHTML += "<li><a href='" + videoUrl + "' target='_blank'><img class='MSDLthumbnail' src='" + thumbnail + "'></a></li>";
}
}
}
}
if (playerOpts.d.Presentation.VodcastUrl != null) {
videoAvailable = true;
var thumbnail = window.location.origin + playerOpts.d.Presentation.ThumbnailUrl;
var videoUrl = playerOpts.d.Presentation.VodcastUrl;
document.getElementById("MSDLvideos").innerHTML += "<li>Vodcast:<br><a href='" + videoUrl + "' target='_blank'><img class='MSDLthumbnail' src='" + thumbnail + "'></a></li>";
}
if (!videoAvailable) document.getElementById("MSDLinfo").innerHTML = "<li>Sorry, no video(s) available.</li>";
}
Mediasite.Player.API.pause();
location.href = "#open-modal";
}
})
})()