xiaoshuai / PithyBaidu

// ==UserScript==
// @namespace      https://openuserjs.org/users/xiaoshuai
// @name           PithyBaidu
// @description    精简百度搜索结果页 Pithy Baidu Search Result Page
// @copyright      2018, xiaoshuai (https://openuserjs.org/users/xiaoshuai)
// @license        MIT
// @icon           http://www.baidu.com/favicon.ico
// @version        1.0.0
// @include        /www\.baidu\.com\/(s\?|#wd|(index.*)?$)/
// ==/UserScript==

// ==OpenUserJS==
// @author         xiaoshuai
// @name           PithyBaidu
// ==/OpenUserJS==

/**
 * Pithy Baidu Search Result Page
 */
(function () {
  const xs = {};
  xs.iterateClassElements = function (cn, fn) {
    let es = document.getElementsByClassName(cn);
    for (let i = 0; i < es.length; ++i) {
      fn(es[i]);
    }
  }
  xs.iterateClassElementsDeep = function (cnp, cnc, fn) {
    let esp = document.getElementsByClassName(cnp);
    for (let i = 0; i < esp.length; ++i) {
      let esc = esp[i].getElementsByClassName(cnc);
      for (let i = 0; i < esc.length; ++i) {
        fn(esc[i]);
      }
    }
  }
  xs.expandElementWidth = function (e) {
    var w = e.clientWidth;
    if (w > 360 && w < 620) {
      e.style.width = (w + 500) + 'px'
    }
  }
  xs.removeById = function (id) {
    var e = document.getElementById('content_right');
    e && e.remove();
  }
  xs.removeByClassName = function (cn) {
    xs.iterateClassElements(cn, function (e) {
      e.remove();
    });
  }
  xs.baiduSearchPage = function () {
    xs.removeById('content_right')
    xs.removeByClassName('AlCtMw')
    xs.expandElementWidth(document.getElementById('content_left'))
    xs.iterateClassElements('c-container', xs.expandElementWidth)
    xs.iterateClassElementsDeep('c-container', 'c-abstract', xs.expandElementWidth)
    xs.iterateClassElementsDeep('c-container', 'c-span18 c-span-last', xs.expandElementWidth)
  }
  xs.baiduSearchPage()
})();