Reddit 伪装成 百度贴吧

中国人就用百度贴吧

  1. // ==UserScript==
  2. // @name Reddit 伪装成 百度贴吧
  3. // @namespace https://github.com/userElaina/this-is-the-China-website
  4. // @version 2025.03.20.01
  5. // @description 中国人就用百度贴吧
  6. // @author userElaina
  7. // @license MIT
  8. // @match *://*.reddit.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. function sleep(time) {
  13. return new Promise((resolve) => setTimeout(resolve, time));
  14. }
  15.  
  16. async function f_succ(f, msSleep = 500, maxCount = 10) {
  17. let count = 0;
  18. while (true) {
  19. try {
  20. if (f()) {
  21. return true;
  22. }
  23. } catch (e) {
  24. console.log(e);
  25. }
  26. count++;
  27. if (count > maxCount) {
  28. return false;
  29. }
  30. await sleep(msSleep);
  31. }
  32. }
  33.  
  34. (async function () {
  35.  
  36. // change title
  37. await f_succ(() => {
  38. let urls = window.location.href.split('/');
  39. if (urls.length <= 4) {
  40. document.title = '百度贴吧——全球领先的中文社区';
  41. return true;
  42. }
  43.  
  44. if (urls.length <= 6 && urls[3] == 'r') {
  45. document.title = urls[4] + '吧-百度贴吧--' + document.title + '--全球领先的中文社区';
  46. return true;
  47. }
  48.  
  49. if (urls[3] == 'user') {
  50. document.title = urls[4] + '的贴吧-百度贴吧--全球领先的中文社区';
  51. return true;
  52. }
  53.  
  54. if (urls[3] == 'r') {
  55. document.title = document.title.split(' : r/')[0] + '【' + urls[4] + '吧】_百度贴吧';
  56. return true;
  57. }
  58.  
  59. document.title = '百度贴吧——全球领先的中文社区';
  60. return true;
  61. });
  62.  
  63. // change icon
  64. await f_succ(() => {
  65. let icon = document.head.querySelector('[rel="icon shortcut"]');
  66. if (icon === null) {
  67. return false;
  68. }
  69. icon.type = 'image/x-icon';
  70. icon.href = 'https://raw.githubusercontent.com/userElaina/this-is-the-China-website/main/reddit/baidu.ico';
  71. // document.getElementsByTagName('head')[0].appendChild(icon);
  72. return true;
  73. });
  74.  
  75. // change logo
  76. f_succ(() => {
  77. let logo = document.getElementById('reddit-logo');
  78. if (logo === null) {
  79. return false;
  80. }
  81. 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>';
  82. return true;
  83. });
  84.  
  85. // change placeholder
  86. f_succ(() => {
  87. let p = document.querySelector('[class="nd:visible w-[inherit] translate-x-0 max-w-[750px] w-full"]');
  88. if (p === null) {
  89. return false;
  90. }
  91. p = p.shadowRoot;
  92. p = p.childNodes[2];
  93. if (p === null) {
  94. return false;
  95. }
  96. p = p.childNodes[1];
  97. if (p === null) {
  98. return false;
  99. }
  100. p = p.childNodes[1];
  101. if (p === null) {
  102. return false;
  103. }
  104. p = p.childNodes[3];
  105. if (p === null) {
  106. return false;
  107. }
  108. p.placeholder = '全吧搜索:搜索贴吧、帖子或用户';
  109. return true;
  110. });
  111.  
  112. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址