Bilibili旧版首页

阻止b站修改buvid3以退回旧版2023/09/14

  1. // ==UserScript==
  2. // @name Bilibili旧版首页
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.8
  5. // @description 阻止b站修改buvid3以退回旧版2023/09/14
  6. // @author 飘过的风
  7. // @license MIT
  8. // @match *://*.bilibili.com/*
  9. // @icon https://www.bilibili.com/favicon.ico
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. document.cookie = `go_back_dyn=1; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
  17. document.cookie = `go-back-dyn=1; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
  18. document.cookie = `go_old_video=1; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
  19. document.cookie = `nostalgia_conf=2; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
  20. document.cookie = `i-wanna-go-back=1; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
  21. document.cookie = `i-wanna-go-feeds=-1; domain=.bilibili.com; expires=Wed, 31 Dec 2025 00:00:00 GMT; path=/`;
  22. const blockedCookieNames = ['buvid3', 'buvid4', 'otherCookieYouWantToBlock']; // Add or remove cookie names from this lista as needed
  23.  
  24. // Delete the cookies if they're already set
  25. blockedCookieNames.forEach((cookieName) => {
  26. if (document.cookie.includes(cookieName + '=')) {
  27. document.cookie = `${cookieName}=; domain=.bilibili.com; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
  28. }
  29. });
  30.  
  31. // Override document.cookie to prevent setting blocked cookies
  32. const originalDocumentCookie =
  33. Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
  34. Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');
  35.  
  36. Object.defineProperty(document, 'cookie', {
  37. get: function () {
  38. return originalDocumentCookie.get.call(document);
  39. },
  40. set: function (value) {
  41. const cookieNameBeingSet = value.split('=')[0].trim();
  42. if (!blockedCookieNames.includes(cookieNameBeingSet)) {
  43. originalDocumentCookie.set.call(document, value);
  44. }
  45. },
  46. });
  47. })();