-
Notifications
You must be signed in to change notification settings - Fork 5
/
peer-tube-download-button.user.js
68 lines (57 loc) · 2.23 KB
/
peer-tube-download-button.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
// ==UserScript==
// @name Re-enable TUpeerTube download button
// @namespace https://vowi.fsinf.at/
// @version 1.0
// @description Re-enables the download button for TUpeerTube videos, for videos where they were disabled.
// @author Fabian Scherer
// @match https://tube1.it.tuwien.ac.at/videos/watch/*
// @icon https://tube1.it.tuwien.ac.at/client/assets/images/favicon.png
// @grant GM_openInTab
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @downloadURL https://fsinf.at/userscripts/peer-tube-download-button.user.js
// @updateURL https://fsinf.at/userscripts/peer-tube-download-button.user.js
// ==/UserScript==
//====================================================
// MIT Licensed
// Author: jwilson8767
/**
* Waits for an element satisfying selector to exist, then resolves promise with the element.
* Useful for resolving race conditions.
*
* @param selector
* @returns {Promise}
*/
function elementReady(selector) {
return new Promise((resolve, reject) => {
const el = document.querySelector(selector);
if (el) {resolve(el);}
new MutationObserver((mutationRecords, observer) => {
// Query for elements matching the specified selector
Array.from(document.querySelectorAll(selector)).forEach((element) => {
resolve(element);
//Once we have resolved we don't need the observer anymore.
observer.disconnect();
});
})
.observe(document.documentElement, {
childList: true,
subtree: true
});
});
}
//=====================================================
function fs_download_url(id){return "https://tube1.it.tuwien.ac.at/download/videos/" + id + "-720.mp4"}
function fs_do_the_download(){
var id = window.location.href.split("/").pop()
var download_url = fs_download_url(id)
GM_openInTab(download_url)
}
(function() {
'use strict';
$(function() {
elementReady(".video-actions").then(() => {
$(".video-actions").append('<div id="fs_download" class="action-button action-button-like" placement="bottom auto" role="button" aria-pressed="false">*download*</div>');
$("#fs_download").click(fs_do_the_download);
})
});
})();