摸鱼时去除话题的大标题(尤其是某些佬的骚标题)

大家没事的时候老是会来L站摸鱼,刷帖子

奈何有的话题标题是在是太骚,想看但是看的时候title处老是显示着那骚气的标题,非常不利于摸鱼人和i人 :tieba_006:

ps:因为同事没事会路过,万一不小心看到了,那我的名声算是毁于一旦了。所以配合着chagpt弄了个油猴脚本去除了观看具体话题时候的标题

(本人主后端,前端一坨屎,求各位前端大佬放过)脚本可能会有bug,有前端大佬可以的话可以帮忙优化一下

js脚本已修正,刚开始拷贝错版本了,match有问题 :tieba_091:

end:我最终用的是上面这个脚本(最开始发帖时候粘错代码了,尴尬,第二个刚开始有问题,目前应该也行,我这边没有实验过,如果不行就请使用上面这个js脚本)

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      2024-07-17
// @description  try to take over the world!
// @author       You
// @match        https://linux.do/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM.xmlHttpRequest
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // 选择器可以根据实际情况调整
    const selector = '.header-title';

    // 创建一个 MutationObserver 实例
    const observer = new MutationObserver(function(mutationsList, observer) {
        for (let mutation of mutationsList) {
            if (mutation.type === 'childList' || mutation.type === 'subtree') {
                const element = document.querySelector(selector);
                if (element) {
                    element.style.display = 'none'; // 隐藏元素
                }
            }
        }
    });

    // 配置 MutationObserver 监听的目标节点及选项
    const config = { childList: true, subtree: true };

    // 监听整个文档的变化
    observer.observe(document.body, config);

    // 初始检查一次
    const initialElement = document.querySelector(selector);
    if (initialElement) {
        initialElement.style.display = 'none';
    }

})();
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      2024-07-17
// @description  try to take over the world!
// @author       You
// @match        https://linux.do/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const scriptContent = `
        (function() {
            const selector = '.header-title';

            const observer = new MutationObserver(function(mutationsList, observer) {
                for (let mutation of mutationsList) {
                    if (mutation.type === 'childList' || mutation.type === 'subtree') {
                        const element = document.querySelector(selector);
                        if (element) {
                            element.style.display = 'none';
                        }
                    }
                }
            });

            const config = { childList: true, subtree: true };

            observer.observe(document.body, config);

            const initialElement = document.querySelector(selector);
            if (initialElement) {
                initialElement.style.display = 'none';
            }
        })();
    `;

    const script = document.createElement('script');
    script.textContent = scriptContent;
    document.body.appendChild(script);
})();
6 个赞

哈哈哈你怎么知道我上次就被发现了

虽然显示脚本被调用了但是大标题并没有隐藏

摸鱼时候要眼观六路,耳听八方,来人的时候立马切换tab :tieba_025:
然后屏幕亮度调低,防止别人偷窥 :tieba_006:

这样显得心虚了,应该光明正大的放着,告诉老板你在学习

1 个赞

应该是有bug,我看回复比较多的话题可以隐藏,短的好像会有问题,我问问gpt继续改改,或者有前端大佬一起优化下

我这里报的错误是这个:
Refused to execute inline script because it violates the following Content Security Policy directive:
由于网站的内容安全策略(Content Security Policy, CSP)阻止了内联脚本的执行 :smiling_face_with_tear:

看起来.header-title在页面滚动到下面才会显示,加了个滚动事件订阅

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      2024-07-18
// @description  try to take over the world!
// @author       You
// @match        https://linux.do/t/topic/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=linux.do
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    addEventListener("scrollend", (event) => {
      let header = document.querySelector('.header-title')
      if (header !== null) {
        header.style.display = 'none'
      }
    });
})();

刚刚把这个行改成下面这个就可以生效了
// @match https://linux.do/*

1 个赞

如果是滚动的话,刚点进来的时候会显示吧

1 个赞

这个应该不太影响

更改了一次,match有问题,尴尬了 :tieba_091:

有道理哦,应该在进入页面也调用下

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      2024-07-18
// @description  try to take over the world!
// @author       You
// @match        https://linux.do/t/topic/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=linux.do
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function hideTitle() {
      let title = document.querySelector('.header-title')
      if (title !== null) {
          title.style.display = 'none'
      }
    }
    hideTitle();
    addEventListener("scrollend", hideTitle);
})();
1 个赞

突然发现发贴的时候粘错代码了 :tieba_091:,我就说我这边没问题,你们那边咋有问题

赞,正需要这个!

好东西

我就知道有人会有跟我一样的需求 :rofl:

相同需求+1

哈哈哈,我之前有些话题都不敢点进去,得等下班回家后再看 :tieba_025: 那标题挂那里太显眼了

然后肥家就忘了=。=
在我搜你这个之前,我是开着Chrome的浏览器提示,“linux.do想要显示通知”“允许or禁止” 但是好麻烦也不好用啊hhhh