CircleFTP Fix Tab And Movie Titles

Update tab and movie titles correctly on CircleFTP

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         CircleFTP Fix Tab And Movie Titles
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Update tab and movie titles correctly on CircleFTP
// @author       BlazeFTL
// @license      MIT
// @match        *://new.circleftp.net/*
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    // --- Style Fix ---
    const styleFix = `
    .SinglePost_singlePost_text__TQn9G {
        position: static !important;
        opacity: 1 !important;
        visibility: visible !important;
        background: transparent !important;
        display: block !important;
        pointer-events: auto !important;
        margin-top: 10px !important;
    }

    .SinglePost_singlePost_card__MLfCk .overflow-hidden {
        flex-direction: column !important;
        align-items: center !important;
    }
    `;
    if (typeof GM_addStyle !== "undefined") GM_addStyle(styleFix);
    else document.head.appendChild(Object.assign(document.createElement('style'), { textContent: styleFix }));

    // --- Update Titles ---
    function updateTitles() {
        // --- Tab title ---
        let pageTitle = '';
        const h2 = document.querySelector('h2.text-white.text-bolder'); // single movie page
        if (h2 && h2.textContent.trim()) pageTitle = h2.textContent.trim();

        const searchH1 = document.querySelector('main h1.text-light.text-center.my-3.bg-dark.py-1'); // search page
        if (searchH1 && searchH1.textContent.trim()) pageTitle = searchH1.textContent.trim();

        if (pageTitle && document.title !== pageTitle) document.title = pageTitle;

        // --- Replace all visible card titles with full title attribute ---
        document.querySelectorAll('.SinglePost_singlePost_card__MLfCk').forEach(card => {
            if (card.dataset.titleUpdated) return;
            const fullTitle = card.getAttribute('title');
            if (!fullTitle) return;
            const textDiv = card.querySelector('.SinglePost_singlePost_text__TQn9G h3');
            if (textDiv) textDiv.textContent = fullTitle.trim();
            card.dataset.titleUpdated = 'true';
        });
    }

    // --- Run after load and on DOM changes (debounced) ---
    window.addEventListener('load', updateTitles);

    let debounceTimer;
    const observer = new MutationObserver(() => {
        clearTimeout(debounceTimer);
        debounceTimer = setTimeout(updateTitles, 250);
    });
    observer.observe(document.body, { childList: true, subtree: true });
})();