Search code examples
javascriptjqueryyoutubetampermonkey

Tampermonkey to run on YouTube load and inject code


I'm trying to inject code into YouTube that fixes a bug in Magic Actions for YouTube. I have the following code from Magic Actions for Youtube that fixes the placement of Action bar that comes under the video but after update to YouTube it shows up at the top.

javascript:(function(){var b=document.querySelector('#watch7-content span'),a=document.querySelector('ytd-video-primary-info-renderer'),c=a&&a.firstElementChild;b&&a&&c&&a.insertBefore(b,c)})();

The above code is used as a bookmark but I want to use Tampermonkey to insert and run this code anytime the YouTube video plays.


Solution

  • window.onload = function() {
       var b=document.querySelector('#watch7-content span'),a=document.querySelector('ytd-video-primary-info-renderer'),c=a&&a.firstElementChild;b&&a&&c&&a.insertBefore(b,c);
    };