paxt001/video/ard_download_button.user.js

79 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-06-22 01:29:19 +02:00
// ==UserScript==
// @name ARD download button
// @description Adds a download-button for every video on ardmediathek.de.
// @description:de Fügt einen download-button für jedes video auf ardmediathek.de hinzu.
2020-05-26 01:14:44 +02:00
// @version 2020.05.26.1
2019-06-22 01:29:19 +02:00
// @author tastytea
2020-05-26 01:14:44 +02:00
// @copyright 2019-2020, tastytea (https://tastytea.de/)
2019-06-22 01:29:19 +02:00
// @license GPL-3.0-only
// @namespace tastytea.de
// @homepageURL https://schlomp.space/tastytea/userscripts
// @supportURL https://schlomp.space/tastytea/userscripts/issues
// @downloadURL https://schlomp.space/tastytea/userscripts/raw/branch/main/video/ard_download_button.user.js
// @grant none
// @match https://*.ardmediathek.de/*
// @run-at document-end
// @inject-into content
// ==/UserScript==
function main()
{
2019-06-22 05:15:58 +02:00
// Stop if button is already there.
if (document.getElementById("tastytea_downloadbutton") !== null)
2019-06-22 01:29:19 +02:00
{
return;
}
const url = get_url();
if (url === null)
{
console.warn("Could not get video URL.");
return;
}
add_button(url);
}
function get_url() // Extract URL from HTML.
2019-06-22 01:29:19 +02:00
{
2019-07-06 05:15:35 +02:00
const html = document.documentElement.innerHTML;
const re_mp4 = new RegExp('"(https:)?(//[^",]+\.mp4)"', 'g');
2019-07-06 05:15:35 +02:00
const result = [...html.matchAll(re_mp4)];
if (result !== null)
2019-06-22 05:11:18 +02:00
{ // Return the last match.
return "https:" + result[result.length - 1][2];
}
2019-06-22 01:29:19 +02:00
return null;
}
function add_button(url)
{
// Last time I looked, there was only 1 element with that class.
2020-05-26 01:14:44 +02:00
const root = document.getElementsByClassName("src__Box-sc-1sbtrzs-0 src__Flex-sc-1sbtrzs-1 Row-wbrv0h-0 rWQeG")[0];
if (root === undefined)
2019-06-22 01:29:19 +02:00
{
console.warn("Could not find root element.");
return;
}
const button = document.createElement("a");
button.setAttribute("id", "tastytea_downloadbutton");
button.setAttribute("href", url);
button.style.fontSize = "120%";
button.style.fontWeight = "bold";
button.style.textDecoration = "underline";
button.style.backgroundColor = "#00000040";
button.style.padding = "0.5em";
button.appendChild(document.createTextNode("Download"));
const div = document.createElement("div");
div.setAttribute("class", "col");
div.appendChild(button);
root.appendChild(div);
}
2019-06-22 05:15:58 +02:00
setInterval(main, 2000); // The script is not restarted when clicking on a link.