网站访问优化

[1]去掉iview文档页小广告

目前為 2020-03-24 提交的版本,檢視 最新版本

// ==UserScript==
// @name         网站访问优化
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  [1]去掉iview文档页小广告
// @author       smalle
// @match        https://*.iviewui.com/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict'

  // Your code here...

  window.onload = function() {
    main.run()
  }

  let main = {
    run: function() {
      // 隐藏iview官网友情提示
      if (location.host.match(/www.iviewui.com/ig)) {
          // sq.byClass('wrapper-container-tip-out')[0].style.display = 'none'
          var style = document.createElement('style')
          style.textContent = [
              '.wrapper-container-tip-out{display:none !important;}'
          ].join('')
          document.head.appendChild(style)
      }
    }
  }

  let sq = {}

  // =======
  // 元素获取
  // =======

  sq.byId = function(id) {
    return document.getElementById(id)
  }

  sq.byClass = function(cls, parent) {
    if (parent == null) parent = document

    if (parent.getElementsByClassName) {
      return parent.getElementsByClassName(cls)
    } else {
      var res = []
      var reg = new RegExp(' ' + cls + ' ', 'i')
      var ele = parent.getElementsByTagName('*')
      for (var i = 0; i < ele.length; i++) {
        if (reg.test(' ' + ele[i].className + ' ')) {
          res.push(ele[i])
        }
      }
      return res
    }
  }

  /**
  * var parent = sq.closest(this, '.box');
  * @param {Object} el
  * @param {Object} selector
  */
  sq.closest = function(el, selector) {
    var matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector

    while (el) {
      if (matchesSelector.call(el, selector)) {
        break
      }
      el = el.parentElement
    }
    return el
  }

  // =======
  // DOM操作
  // =======
  sq.hasClass = function(obj, cls) {
    return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
  }

  sq.addClass = function(obj, cls) {
    if (!sq.hasClass(obj, cls)) obj.className += ' ' + cls
  }

  sq.removeClass = function(obj, cls) {
    if (sq.hasClass(obj, cls)) {
      var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
      obj.className = obj.className.replace(reg, ' ')
    }
  }

  sq.toggleClass = function(obj, cls) {
    if (sq.hasClass(obj, cls)) {
      sq.removeClass(obj, cls)
    } else {
      sq.addClass(obj, cls)
    }
  }

  // =======
  // 校验
  // =======

  /**
  * 是否为空:可判断字符串/[]等
  * @param {Object} obj
  */
  sq.isEmpty = function(obj) {
    var name
    for (name in obj) {
      return false
    }
    return true
  }

  /**
  * 是否不为空
  * @param {Object} obj
  */
  sq.isNotEmpty = function(obj) {
    return !sq.isEmpty(obj)
  }
})()

QingJ © 2025

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