Bilibili旧版首页

阻止b站修改buvid3以退回旧版首页2023/08/26

当前为 2023-08-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bilibili旧版首页
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  阻止b站修改buvid3以退回旧版首页2023/08/26
// @author       飘过的风
// @license      MIT
// @match        *://*.bilibili.com/*
// @icon         https://www.bilibili.com/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    document.cookie = `i-wanna-go-back=1; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
    const blockedCookieNames = ['buvid3', 'otherCookieYouWantToBlock']; // Add or remove cookie names from this lista as needed

    // Delete the cookies if they're already set
    blockedCookieNames.forEach((cookieName) => {
        if (document.cookie.includes(cookieName + '=')) {
            document.cookie = `${cookieName}=; domain=.bilibili.com; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
        }
    });

    // Override document.cookie to prevent setting blocked cookies
    const originalDocumentCookie =
        Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
        Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');

    Object.defineProperty(document, 'cookie', {
        get: function () {
            return originalDocumentCookie.get.call(document);
        },
        set: function (value) {
            const cookieNameBeingSet = value.split('=')[0].trim();
            if (!blockedCookieNames.includes(cookieNameBeingSet)) {
                originalDocumentCookie.set.call(document, value);
            }
        },
    });
})();