Better Baidu

Remove the 'right' contents. Add Bing and Google search buttons.

  1. // ==UserScript==
  2. // @name Better Baidu
  3. // @namespace feifeihang.info
  4. // @description Remove the 'right' contents. Add Bing and Google search buttons.
  5. // @include http://www.baidu.com/
  6. // @include https://www.baidu.com/
  7. // @include http://www.baidu.com/s*
  8. // @include https://www.baidu.com/s*
  9. // @include http://www.baidu.com/baidu*
  10. // @include https://www.baidu.com/baidu*
  11. // @version 1.2.3
  12. // @grant none
  13. // ==/UserScript==
  14. (function (window, document, undefined) {
  15. var hasAdded = false;
  16. // define search engines' urls.
  17. var URLS = {
  18. 'Bing': 'http://www.bing.com/search?q=',
  19. 'Google': 'http://www.google.com/#q='
  20. };
  21. // now, let's go implement keywords highlighting.
  22. var resultContainerQuery = '#content_left';
  23. var buffer = '';
  24. watch(resultContainerQuery, buffer);
  25. var COLORS = [
  26. '#FFFF00',
  27. '#FFCC00',
  28. '#CCCCFF',
  29. '#00CCFF',
  30. '#33CCCC',
  31. '#FF8080',
  32. '#008000',
  33. '#FFFF99',
  34. '#808000',
  35. '#FFFFCC'
  36. ];
  37. var counter = 0;
  38. var topBtn;
  39. window.addEventListener('scroll', function () {
  40. if (window.pageYOffset >= 20) {
  41. topBtn.style.display = 'block';
  42. }
  43. else {
  44. topBtn.style.display = 'none';
  45. }
  46. });
  47. function watch(resultContainerQuery, buffer) {
  48. setInterval(function () {
  49. // first, remove the annoying right contents.
  50. if (document.querySelector('#content_right *')) {
  51. var all = document.querySelectorAll('#content_right *:not(.better-baidu-reserve)');
  52. all = Array.prototype.slice.apply(all);
  53. all.map(function (element) {
  54. element.remove();
  55. });
  56. topBtn = document.createElement('div');
  57. // now, add go-to-top button.
  58. topBtn.appendChild(document.createTextNode('TOP'));
  59. var displayStr = window.pageYOffset >= 20 ? 'block' : 'none';
  60. topBtn.style = 'display: ' + displayStr + '; position: fixed; bottom: 10px; right: 10px; line-height: 50px;' +
  61. 'width: 50px; height: 50px; color: #fff; background: #ED614F; text-align: center;' +
  62. 'cursor: pointer; font-weight: bold; border-radius: 100%; z-index: 999999;' +
  63. 'box-shadow: 0 2px 5px grey;';
  64. topBtn.onclick = function () {
  65. window.scrollTo(0, 0);
  66. }
  67. document.body.appendChild(topBtn);
  68. }
  69. // if Bing and Google are not added yet, add them.
  70.  
  71. var isNotBaiduHomepage =
  72. window.location.href.toUpperCase() !== 'HTTP://WWW.BAIDU.COM' &&
  73. window.location.href.toUpperCase() !== 'HTTPS://WWW.BAIDU.COM' &&
  74. window.location.href.toUpperCase() !== 'HTTP://WWW.BAIDU.COM/' &&
  75. window.location.href.toUpperCase() !== 'HTTPS://WWW.BAIDU.COM/';
  76. if (!hasAdded && isNotBaiduHomepage) {
  77. // find container and Baidu button.
  78. var container = document.querySelector('#form');
  79. var baidu = document.querySelector('#su').parentElement;
  80. var current = baidu;
  81. // now, create and add new buttons.
  82. for (var item in URLS) {
  83. var anchor = document.createElement('a');
  84. anchor.textContent = item;
  85. anchor.setAttribute('data-url', URLS[item]);
  86. anchor.setAttribute('target', '_blank');
  87. anchor.onmouseenter = function () {
  88. var q = document.querySelector('#kw').value || '';
  89. this.setAttribute('href', this.getAttribute('data-url') + q);
  90. };
  91. anchor.style = 'cursor: pointer; color: rgb(255, 255, 255);font-weight: bold; display: inline-block;' +
  92. 'text-decoration: none;background: rgb(51, 133, 255) none repeat scroll 0% 0%; text-align: center; line-height: 33px;' +
  93. 'margin-left: 2px; width: 60px; height: 33px; border-bottom: 1px solid transparent;';
  94. container.insertBefore(anchor, current.nextSibling);
  95. current = anchor;
  96. }
  97. hasAdded = true;
  98. }
  99. var resultContainer = document.querySelector(resultContainerQuery);
  100. if (resultContainer && resultContainer.textContent !== buffer) {
  101. // update buffer.
  102. buffer = resultContainer.textContent;
  103. // first, find all 'em's.
  104. var ems = document.querySelectorAll('em');
  105. // if there is no 'em's, do nothing.
  106. if (ems.length === 0) {
  107. return false;
  108. }
  109. // convert ems into an array.
  110.  
  111. ems = Array.prototype.slice.apply(ems);
  112. var counter = 0;
  113. var styles = {
  114. };
  115. // iterate through all the keywords in search result,
  116. // and map the predefined color to them.
  117. ems.forEach(function (em) {
  118. var text = em.innerHTML.toUpperCase().trim();
  119. var bg = styles[text];
  120. if (!bg) {
  121. bg = COLORS[counter++];
  122. styles[text] = bg;
  123. if (counter === COLORS.length) {
  124. counter = 0;
  125. }
  126. }
  127. em.style.background = bg;
  128. em.style.color = '#000';
  129. em.style.fontWeight = 'bold';
  130. });
  131. }
  132. }, 200);
  133. }
  134. }) (this, document);

QingJ © 2025

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