// ==UserScript== // @name Audio Tab Title // @description Change the window title on YouTube based on the channel name and video title, and append the website name on Spotify and SoundCloud pages. // @version 0.4.0 // @namespace itsafeature.org // @author Geoffrey De Belie (Smile4ever) // @license Unlicense // @match https://www.youtube.com/watch?v=* // @match https://music.youtube.com/* // @match https://open.spotify.com/* // @match https://soundcloud.com/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Function to update the title on YouTube function updateYouTubeTitle() { const channelElement = document.querySelector('a.yt-simple-endpoint.style-scope.yt-formatted-string'); const videoTitleElement = document.querySelector('#above-the-fold #title'); if (channelElement && videoTitleElement) { const channelNameClean = channelElement.innerText.split(' - ')[0].split('|')[0].replace(" Official", ""); console.log("channelNameClean: " + channelNameClean); const videoTitle = videoTitleElement.innerText; console.log("videoTitle: " + videoTitle); const spaceIndex = videoTitle.indexOf(' '); const dashIndex = videoTitle.indexOf('-'); // If there's no space, continue. If the first dash appears before the first space, get out if (spaceIndex != -1 && dashIndex != -1 && dashIndex < spaceIndex) return; // Set the window title for YouTube if needed if(dashIndex === -1){ document.title = `${channelNameClean} - ${videoTitle} - YouTube`; } } } // Function to update the title on YouTube Music function updateYouTubeMusicTitle() { const elements = document.querySelectorAll('.ytmusic-player-bar yt-formatted-string'); if (elements.length < 2) return; const artistElement = elements[1]; const audioTitleElement = elements[0]; if (artistElement && audioTitleElement) { const artistName = artistElement.childNodes[0].innerText; const audioTitle = audioTitleElement.innerText; // Set the window title for YouTube Music document.title = `${artistName} - ${audioTitle} - YouTube Music`; } } // Function to update the title on Spotify function updateSpotifyTitle() { const titleElement = document.querySelector('title'); // Get the