I've been attempting to create a userscript that adds a download button to YouTube. I initially tried using Tampermonkey and Greasemonkey, but unfortunately, they were ineffective. Strangely enough, the script runs without any errors when manually executed in the console. The button is successfully added when I copy and paste the script directly into the console.
Here is the userscript:
// ==UserScript==
// @name Youtube Downloader
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Download Youtube Videos With One Click!
// @author qweren
// @match https://www.youtube.com/*
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/YouTube_full-color_icon_%282017%29.svg/1024px-YouTube_full-color_icon_%282017%29.svg.png
// ==/UserScript==
(function() {
'use strict';
// Check if the "actions" div exists
var actionsDiv = document.getElementById('actions');
// Create a new button element
var newButton = document.createElement('button');
newButton.textContent = 'Click Me';
// Add an event listener to the button
newButton.addEventListener('click', function() {
alert('Button clicked!');
});
// Append the button to the "actions" div
actionsDiv.appendChild(newButton);
console.log("adding button")
})();
I attempted switching between Greasemonkey and Tampermonkey extensions, both of which failed to work. Additionally, trying to implement an onload function for the actionsdiv also proved unsuccessful.