使用 tamperonkey 脚本更改 vBulletin 论坛中帖子标题的背景颜色

问题描述 投票:0回答:1

我正在尝试创建一个 Tampermonkey 脚本来更改网站的主题:https://www.cfd-online.com/Forums/comsol/70028-shear-stress-velocity-profile.html 我认为是基于 vBulletin.

我试过以下脚本:

// ==UserScript==
// @name         vBulletin Forum Dark Mode
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Enable dark mode for vBulletin forum posts
// @author       Me
// @match        https://www.cfd-online.com/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Add custom CSS styles for dark mode
    GM_addStyle(`
        /* Dark mode styles */
        .alt1, .alt2, .aalt1, .aalt2, table, tbody, tr, .thead, .tborder, #posts, .smallfont td {
            background-color: #1e1e1e !important;
            color: #dcdcdc !important;
        }

        a, .smallfont {
            color: #81a2be !important;
        }

        a {
            color: #81a2be !important;
        }

        /* Change the background color of the post title section in each reply */
        .tborder tbody tr, #posts{
            background-color: #1e1e1e !important;
        }

        /* Add more styles here as needed */
    `);

})();

但是我无法更改标题的背景颜色,如上图所示,红色矩形。我找不到相应的元素来改变它的属性:

总结:如何将屏幕截图中高亮元素的背景颜色更改为黑色?

任何帮助表示赞赏。

css themes tampermonkey darkmode vbulletin
1个回答
0
投票

这是一个 CSS 选择器问题。

首先,每个帖子都在一个表中 - 所以你必须选择正确的表 -

all tables with an ID that begins with the characters "post"

table[id^="post"]

然后您需要选择该表中的第一个 TR...并为其每个 TD 设置样式。

尝试将此添加到您的代码中:

table[id^="post"] > tbody > tr:first-of-type td {
   background: black;
   color: white;
}

© www.soinside.com 2019 - 2024. All rights reserved.