Greasy Fork

Greasy Fork is available in English.

Audio Tab Title

Change the tab title on YouTube based on the channel name and video title, and append "- Spotify" to the title on Spotify pages.

当前为 2025-02-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Audio Tab Title
// @description  Change the tab title on YouTube based on the channel name and video title, and append "- Spotify" to the title on Spotify pages.
// @version      0.2
// @namespace    itsafeature.org
// @author       Geoffrey De Belie (Smile4ever)
// @license      Unlicense
// @match        https://www.youtube.com/watch?v=*
// @match        https://open.spotify.com/*
// @grant        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 channelName = channelElement.innerText.split(' - ')[0];
            const videoTitle = videoTitleElement.innerText;
            // Set the window title for YouTube
            document.title = `${channelName} - ${videoTitle} - YouTube`;
        }
    }

    // Function to update the title on Spotify
    function updateSpotifyTitle() {
        const titleElement = document.querySelector('title'); // Get the <title> element
        if (titleElement.innerText.includes(" - Spotify") == false) {
            titleElement.innerText = `${titleElement.innerText} - Spotify`; // Set the title's innerText for Spotify
        }
    }

    // Function to check for the current platform (YouTube or Spotify)
    function updateTitle() {
        if (window.location.hostname.includes('youtube.com')) {
            updateYouTubeTitle();
        } else if (window.location.hostname.includes('spotify.com')) {
            updateSpotifyTitle();
        }
    }

    // Wait for the page content to load before running the updateTitle function
    window.addEventListener('load', updateTitle);

    // Set an interval to check the title every second on Spotify pages only
    if (window.location.hostname.includes('spotify.com')) {
        setInterval(() => {
            updateSpotifyTitle(); // Update the title every second on Spotify
        }, 1000); // 1 second interval
    }
})();