Greasy Fork

Greasy Fork is available in English.

Reddit 伪装成 百度贴吧

中国人就用百度贴吧

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Reddit 伪装成 百度贴吧
// @namespace https://github.com/userElaina/this-is-the-China-website
// @version 2025.03.20.01
// @description 中国人就用百度贴吧
// @author userElaina
// @license MIT
// @match *://*.reddit.com/*
// @grant none
// ==/UserScript==

function sleep(time) {
    return new Promise((resolve) => setTimeout(resolve, time));
}

async function f_succ(f, msSleep = 500, maxCount = 10) {
    let count = 0;
    while (true) {
        try {
            if (f()) {
                return true;
            }
        } catch (e) {
            console.log(e);
        }
        count++;
        if (count > maxCount) {
            return false;
        }
        await sleep(msSleep);
    }
}

(async function () {

    // change title
    await f_succ(() => {
        let urls = window.location.href.split('/');
        if (urls.length <= 4) {
            document.title = '百度贴吧——全球领先的中文社区';
            return true;
        }

        if (urls.length <= 6 && urls[3] == 'r') {
            document.title = urls[4] + '吧-百度贴吧--' + document.title + '--全球领先的中文社区';
            return true;
        }

        if (urls[3] == 'user') {
            document.title = urls[4] + '的贴吧-百度贴吧--全球领先的中文社区';
            return true;
        }

        if (urls[3] == 'r') {
            document.title = document.title.split(' : r/')[0] + '【' + urls[4] + '吧】_百度贴吧';
            return true;
        }

        document.title = '百度贴吧——全球领先的中文社区';
        return true;
    });

    // change icon
    await f_succ(() => {
        let icon = document.head.querySelector('[rel="icon shortcut"]');
        if (icon === null) {
            return false;
        }
        icon.type = 'image/x-icon';
        icon.href = 'https://raw.githubusercontent.com/userElaina/this-is-the-China-website/main/reddit/baidu.ico';
        // document.getElementsByTagName('head')[0].appendChild(icon);
        return true;
    });

    // change logo
    f_succ(() => {
        let logo = document.getElementById('reddit-logo');
        if (logo === null) {
            return false;
        }
        document.getElementById('reddit-logo').innerHTML = '<img src="https://raw.githubusercontent.com/userElaina/this-is-the-China-website/main/reddit/teiba_big.png" style="background:none" height="45" width="135" data-atf="1" data-frt="0"></img>';
        return true;
    });

    // change placeholder
    f_succ(() => {
        let p = document.querySelector('[class="nd:visible w-[inherit] translate-x-0 max-w-[750px] w-full"]');
        if (p === null) {
            return false;
        }
        p = p.shadowRoot;
        p = p.childNodes[2];
        if (p === null) {
            return false;
        }
        p = p.childNodes[1];
        if (p === null) {
            return false;
        }
        p = p.childNodes[1];
        if (p === null) {
            return false;
        }
        p = p.childNodes[3];
        if (p === null) {
            return false;
        }
        p.placeholder = '全吧搜索:搜索贴吧、帖子或用户';
        return true;
    });

})();