Wikipedia 伪装成 百度百科

中国人就用百度百科

  1. // ==UserScript==
  2. // @name Wikipedia 伪装成 百度百科
  3. // @namespace https://github.com/userElaina/this-is-the-China-website
  4. // @version 2023.09.22.01
  5. // @description 中国人就用百度百科
  6. // @author userElaina
  7. // @license MIT
  8. // @match *://*.wikipedia.org/*
  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. if (f()) {
  20. return true;
  21. }
  22. count++;
  23. if (count > maxCount) {
  24. return false;
  25. }
  26. await sleep(msSleep);
  27. }
  28. }
  29.  
  30. (async function () {
  31. // change title
  32. document.title = document.title.replace(/\s-[\s\S]*/g, " - 百度百科");
  33.  
  34. // change icon
  35. await f_succ(() => {
  36. let icon = document.querySelector('link[rel="icon"]');
  37. if (icon === null) {
  38. return false;
  39. }
  40. icon.href = 'https://raw.githubusercontent.com/userElaina/this-is-the-China-website/main/wikipedia/baidu.ico';
  41. return true;
  42. });
  43.  
  44. // change searchbox
  45. f_succ(() => {
  46. let searchBox = document.querySelector('input.vector-search-box-input');
  47. if (searchBox === null) {
  48. searchBox = document.querySelector('input.cdx-text-input__input')
  49. }
  50. if (searchBox === null) {
  51. return false;
  52. }
  53. searchBox.placeholder = '搜索百度百科';
  54. return true;
  55. });
  56.  
  57. // change sitesub
  58. f_succ(() => {
  59. let siteSub = document.getElementById("siteSub");
  60. if (siteSub === null) {
  61. return false;
  62. }
  63. siteSub.innerText = '百度百科, 全球领先的中文百科全书!';
  64. return true;
  65. });
  66.  
  67. // change logo
  68. f_succ(() => {
  69. let logo = document.querySelector('a.mw-wiki-logo');
  70. if (logo === null) {
  71. logo = document.querySelector('a.mw-logo');
  72. }
  73. if (logo === null) {
  74. return false;
  75. }
  76. logo.innerHTML = '<img src="https://raw.githubusercontent.com/userElaina/this-is-the-China-website/main/wikipedia/baidu_big.png" style="padding:10px;padding-top:40px;width:-webkit-fill-available;">';
  77. logo.className = '';
  78. return true;
  79. });
  80.  
  81. })();