Plex Dynamic Title

Change the title of Plex pages to reflect the current content being viewed

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Plex Dynamic Title
// @namespace    http://tampermonkey.net/
// @version      1.9
// @description  Change the title of Plex pages to reflect the current content being viewed
// @author       azizLIGHT
// @match        https://app.plex.tv/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function updateTitle() {
        const url = window.location.href;
        let newTitle = 'Plex';

        // Determine the title based on the current URL
        if (url.includes('/desktop/#!/')) {
            if (url === 'https://app.plex.tv/desktop/#!/') {
                newTitle = 'Plex: Home';
            } else if (url.includes('source=watchlist')) {
                newTitle = 'Plex: Watchlist';
            } else if (url.includes('source=home')) {
                newTitle = 'Plex: Discover';
            } else if (url.includes('/search?')) {
                const searchQueryMatch = url.match(/query=([^&]+)/);
                if (searchQueryMatch) {
                    const searchQuery = decodeURIComponent(searchQueryMatch[1]);
                    newTitle = `Plex: Top Results for "${searchQuery}"`;
                }
            } else if (url.includes('/settings/')) {
                // Handle settings pages
                const settingsHeader = document.querySelector('h2.SettingsPageHeader-header-Ra2WXw');
                if (settingsHeader) {
                    newTitle = `Plex: ${settingsHeader.innerText}`;
                }
            } else if (url.includes('/media/')) {
                // Handle library pages
                const libraryTitleElement = document.querySelector('div.PageHeaderTitle-title-W0yjas');
                if (libraryTitleElement) {
                    const libraryName = libraryTitleElement.innerText;
                    newTitle = `Plex: ${libraryName}`;
                }
            }

            // Check for active tab titles on non-library pages
            const selectedTab = document.querySelector('.TabButton-selected-wnNjlr');
            if (selectedTab) {
                const tabTitle = selectedTab.innerText;
                if (url.includes('source=home')) {
                    newTitle = `Plex: Home - ${tabTitle}`;
                } else if (url.includes('source=watchlist')) {
                    newTitle = `Plex: Watchlist - ${tabTitle}`;
                } else {
                    newTitle = `Plex: ${tabTitle}`;
                }
            }
        }

        // Check for movie/show titles
        const titleElement = document.querySelector('h1[data-testid="metadata-title"]');
        const libraryTitleElement = document.querySelector('div.PageHeaderTitle-title-W0yjas');

        if (titleElement && libraryTitleElement) {
            const movieName = titleElement.innerText;
            const libraryName = libraryTitleElement.innerText;

            // Check for subtitle
            const subtitleElement = document.querySelector('h2[data-testid="metadata-subtitle"]');
            if (subtitleElement) {
                const subtitleText = subtitleElement.innerText;

                // Check if the subtitle contains "Directed by"
                if (subtitleText.startsWith("Directed by")) {
                    // It's a movie, so exclude the director info
                    newTitle = `Plex: ${libraryName} - ${movieName}`;
                } else {
                    // It's likely a TV show with season info
                    newTitle = `Plex: ${libraryName} - ${movieName}: ${subtitleText}`;
                }
            } else {
                // No subtitle, just set the title
                newTitle = `Plex: ${libraryName} - ${movieName}`;
            }
        } else if (libraryTitleElement) {
            const libraryName = libraryTitleElement.innerText;
            if (url.includes('pivot=recommended')) {
                newTitle = `Plex: ${libraryName} - Recommended`;
            } else if (url.includes('pivot=library')) {
                newTitle = `Plex: ${libraryName} - Library`;
            } else if (url.includes('pivot=collections')) {
                newTitle = `Plex: ${libraryName} - Collections`;
            } else if (url.includes('pivot=playlists')) {
                newTitle = `Plex: ${libraryName} - Playlists`;
            } else if (url.includes('pivot=categories')) {
                newTitle = `Plex: ${libraryName} - Categories`;
            } else {
                newTitle = `Plex: ${libraryName}`;
            }
        }

        document.title = newTitle;
    }

    // Run the function on page load
    updateTitle();

    // Observe changes in the DOM to update the title dynamically
    const observer = new MutationObserver(updateTitle);
    observer.observe(document.body, { childList: true, subtree: true });
})();