You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写Userscript去除IMDb参考视图页面标题的冗余后缀?

Complete Userscript to Clean Up IMDb Reference View Titles

Here's the full, working userscript that will strip that annoying redundant suffix from IMDb's reference view page titles:

// ==UserScript==
// @name IMDb - strip garbage from reference view page titles
// @match *://www.imdb.com/title/tt*/reference
// @version 1.0
// @description Removes the "- Reference View - IMDb" suffix from IMDb reference view page titles
// @grant none
// ==/UserScript==

(function() {
    'use strict';

    // Function to trim the unwanted suffix from the title
    function cleanPageTitle() {
        const currentTitle = document.title;
        // Regex targets the exact suffix at the end of the string ($ ensures it's the end)
        const updatedTitle = currentTitle.replace(/ - Reference View - IMDb$/, '');
        
        // Only update if the title actually changed to avoid unnecessary DOM manipulations
        if (updatedTitle !== currentTitle) {
            document.title = updatedTitle;
        }
    }

    // Run the cleanup immediately when the script loads
    cleanPageTitle();

    // Set up a mutation observer to handle any dynamic title updates from IMDb
    const titleObserver = new MutationObserver((mutations) => {
        mutations.forEach(mutation => {
            // Check if the title element was modified
            if (mutation.target.nodeName === 'TITLE') {
                cleanPageTitle();
            }
        });
    });

    // Observe changes to the head element where the title lives
    titleObserver.observe(document.querySelector('head'), { childList: true });
})();

Key details about this script:

  • @grant none: We don't need any special permissions since we're just modifying the DOM directly.
  • Regex matching: The / - Reference View - IMDb$/ regex ensures we only remove the suffix if it's at the very end of the title, so we won't accidentally alter any part of the actual movie title itself.
  • Mutation Observer: Some sites (including IMDb) might update the title dynamically after page load. The observer watches for these changes and re-runs the cleanup to keep the title correct.
  • Safety check: We only update the title if the cleaned version is different from the original, which prevents unnecessary DOM updates.

Just install this script in your userscript manager (like Tampermonkey or Greasemonkey) and it will automatically work on all IMDb reference view pages.

内容的提问来源于stack exchange,提问作者Samuel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:58:13