-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmax-scraper.user.js
60 lines (45 loc) · 1.98 KB
/
dmax-scraper.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
// ==UserScript==
// @name DMAX Episode Scraper
// @version 0.3
// @author @bennyborn
// @namespace https://github.com/bennyborn
// @match https://www.dmax.de/programme/*
// @run-at document-end
// @grant none
// @updateURL https://raw.githubusercontent.com/bennyborn/tampermonkey-scripts/master/dmax-scraper.user.js
// @downloadURL https://raw.githubusercontent.com/bennyborn/tampermonkey-scripts/master/dmax-scraper.user.js
// ==/UserScript==
(function() {
'use strict';
const scrapeButton = document.createElement('BUTTON');
scrapeButton.innerHTML = 'Copy links';
scrapeButton.style = 'display: block;position: fixed;top: 10px;left: 10px;background: #dc5014;color: #fff;padding: 0.5em 2em;z-index: 10000;box-shadow: 0 0 4px rgba(0,0,0,0.5);';
scrapeButton.addEventListener('click', function(e){
const season = /Staffel ([0-9]+) \|/g.exec(document.querySelector('h2.section-title__title').innerText)[1].padStart(2,'0');
const episodes = document.querySelectorAll('li.vertical-list-item');
const cmds = [];
episodes.forEach((episode) => {
const link = episode.querySelector('a').href;
const headline = /F([0-9]+): (.*?)$/g.exec(episode.querySelector('h3').innerText);
const num = headline[1];
const name = headline[2];
let title = `S${season}E${num} - ${name}`;
title = title.replace('?','');
title = title.replace('!','');
cmds.push(`youtube-dl --format bestvideo+bestaudio/best --output "${title}.%(ext)s" "${link}"`);
});
copyStringToClipboard( cmds.join("\n") );
alert('copied');
});
document.body.appendChild(scrapeButton);
function copyStringToClipboard(str) {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
})();