Greasy Fork

Shined up real nice.

Youtube To Mp3

Support to download youtube videos in Mp3 format.

After trying this script, you can ask a question about it, review it, or report it.
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
// ==UserScript==
// @name         Youtube To Mp3
// @author       Pytness
// @namespace    http://tampermonkey.net/
// @version      1.1.5
// @description  Support to download youtube videos in Mp3 format.
// @match        https://www.youtube.com/*
// @match        https://www.youtubeinmp3.com/*
// @grant        none
// ==/UserScript==

(function() {
	'use strict';

	var iframe = null;
	var menuButton, menuSpan, downloadButton;
	var clickEvent = function() {
		if (iframe) {
			iframe.parentNode.removeChild(iframe);
		}
		iframe = document.createElement('iframe');
		iframe.setAttribute('src',
		'https://www.youtubeinmp3.com/download/?video=' + document.baseURI +
		'&autodwn=true');
		iframe.setAttribute('style', 'display: none');
		document.body.appendChild(iframe);

		// setTimeout(function() {
		// 	iframe.parentNode.removeChild(iframe);
		// 	console.log('Iframe Removed');
		// }, 10000);

		menuSpan.innerHTML = 'Downloaded';
		console.log('Downloading MP3');
	};


	function init() {
		if (window.location.host === "www.youtube.com") {
			initButton();
		} else if (window.location.host === "www.youtubeinmp3.com") {
			if (document.location.search.search('&autodwn=true') !== -1) {
				initDownload();
			}
		}
	}

	//===============================================================================
	//=================================-YouTube-=====================================

	function initButton() {
		setInterval(function() {
			var pathName = document.location.pathname == "/watch" ? true : false;
			downloadButton = document.getElementById('ytMp3Btn');
			if (pathName && !downloadButton) {
				var menuDiv = document.createElement('div');
				menuDiv.setAttribute('class', 'yt-uix-menu');

				menuButton = document.createElement('button');

				var buttonClass = '';
				buttonClass += 'yt-uix-button yt-uix-button-size-default ' +
				'yt-uix-button-opacity yt-uix-button-has-icon ' +
				'no-icon-markup pause-resume-autoplay ' +
				'yt-uix-menu-trigger yt-uix-tooltip';

				menuButton.setAttribute('class', buttonClass);
				menuButton.setAttribute('type', 'button');
				menuButton.setAttribute('id', 'ytMp3Btn');
				menuButton.setAttribute('onclick', ';return false;');
				menuButton.setAttribute('aria-pressed', 'false');
				menuButton.setAttribute('aria-haspopup', 'true');
				menuButton.setAttribute('title', 'MP3 Download');
				menuButton.setAttribute('role', 'button');
				menuButton.setAttribute('data-tooltip-text', 'MP3 Download');
				menuButton.setAttribute('aria-labelledby', 'yt-uix-tooltip25-arialabel');

				menuButton.addEventListener('click', clickEvent, false);

				menuSpan = document.createElement('span');
				menuSpan.setAttribute('class', 'yt-uix-button-content');
				var menuSpanText = document.createTextNode("Download");
				menuSpan.appendChild(menuSpanText);

				menuButton.appendChild(menuSpan);
				menuDiv.appendChild(menuButton);

				var wsa = document.getElementById('watch8-secondary-actions');
				wsa.appendChild(menuDiv);

				console.log("Download Button Created");
			} else {
				downloadButton.removeEventListener('click', clickEvent);
				downloadButton.addEventListener('click', clickEvent, false);
			}
		}, 1000);

	}



	//===============================================================================
	//==============================-Mp3 Converter-==================================



	function initDownload() {

		var idClick = 'download';

		var intv = setInterval(function() {
			if (document.getElementById(idClick)) {

				document.getElementById(idClick).click();
				clearInterval(intv);
			}
		}, 50);
	}

	//===============================================================================
	//==================================-Init-=======================================

	init();
})();