Well that took a bit longer than I thought, but got there in the end. Inside this zip file...
...you will find three files.
youtube test.aslx: Demo file. Play this in Quest, and type TEST. It will play the THX theme from YouTube, and hide it after 20 seconds.
To use this yourself, copy the other two files (youtubehide.aslx and youtube.js) into the same folder as the game you're working on. Then load your game in the Editor.
Add the library by going to the Add menu, then Advanced, Library. Select "youtubehide.aslx" from the drop-down, then close and re-load your game in the Editor.
When you add a script command, you'll now have a new option at the bottom of the Output category - "Play YouTube video and hide".
It works much the same as the usual "Play YouTube video" function, but it lets you specify to hide it after a certain number of seconds. (I looked into making it automatically hide when playback was finished using the YouTube API, but couldn't get it to work)