-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
45 lines (36 loc) · 8.87 KB
/
script.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
function addDownloadButton() {
// fetch element which holds buttons (like, dislike, share, etc.) so we can use that
// div to add our download button there
let buttons = document.getElementById('actions');
if (buttons) {
let downloadButton = document.createElement('a');
buttons.append(downloadButton);
downloadButton.outerHTML = '<a id="mp3-btn">' +
'<img width="36px" style="margin: 4px 10px" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PgoNPCEtLSBVcGxvYWRlZCB0bzogU1ZHIFJlcG8sIHd3dy5zdmdyZXBvLmNvbSwgR2VuZXJhdG9yOiBTVkcgUmVwbyBNaXhlciBUb29scyAtLT4KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCA2NCA2NCIgaWQ9InN2ZzUiIHZlcnNpb249IjEuMSIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KDTxkZWZzIGlkPSJkZWZzMiIvPgoNPGcgaWQ9ImxheWVyMSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTM4NCwtMzg0KSI+Cg08cGF0aCBkPSJtIDM5My45OTk5OSwzOTMgaCA0OSB2IDYgaCAtNDkgeiIgaWQ9InBhdGgyNzAxMSIgc3R5bGU9ImZpbGw6IzNlNGY1OTtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6ZXZlbm9kZDtzdHJva2Utd2lkdGg6MjtzdHJva2UtbGluZWNhcDpyb3VuZDtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6NC4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0NjEgYSAxLDEgMCAwIDAgMSwtMSAxLDEgMCAwIDAgLTEsLTEgaCAtMTMuOTc0NjEgdiAtMiBoIDAuOTY2OCBhIDEsMSAwIDAgMCAxLC0xIDEsMSAwIDAgMCAtMSwtMSB6IG0gNiwwIGEgMSwxIDAgMCAwIC0xLDEgMSwxIDAgMCAwIDEsMSBoIDE0IHYgMiBoIC0xLjAyMzQ0IGEgMSwxIDAgMCAwIC0xLDEgMSwxIDAgMCAwIDEsMSBoIDIuMDIzNDQgYSAxLjAwMDEsMS4wMDAxIDAgMCAwIDEsLTEgdiAtNCBhIDEuMDAwMSwxLjAwMDEgMCAwIDAgLTEsLTEgeiIgaWQ9InBhdGgyNTYzNyIgc3R5bGU9ImNvbG9yOiMwMDAwMDA7ZmlsbDojMDAwMDAwO2ZpbGwtcnVsZTpldmVub2RkO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2UtbWl0ZXJsaW1pdDo0LjE7LWlua3NjYXBlLXN0cm9rZTpub25lIi8+Cg08L2c+Cg08L2c+Cg08L3N2Zz4=">' +
'</a>'
let downloadUrl = 'yt2mp3app://' + document.URL
document.getElementById('mp3-btn').setAttribute('href', downloadUrl)
}
}
// since this script will be injected each time history state is updated in chrome
// it means it might have this script injected already, and the browser could have intervalId
// already initialized from before. If that is the case, just reuse that variable
if (typeof intervalId === 'undefined') {
var intervalId;
}
// if it doesn't do full redirect, it might have our previous button still there
if (document.getElementById('mp3-btn')) {
document.getElementById('mp3-btn').remove()
}
// have interval to try until our wanted div is finally rendered in there
intervalId = setInterval(function () {
if (!document.getElementById('mp3-btn'))
addDownloadButton()
else {
clearInterval(intervalId)
}
}, 1000)
// clear interval after 5 seconds just for case
setTimeout(function () {
clearInterval(intervalId);
}, 5000)