CommonsUtil

utility methods

Pada tanggal 02 Desember 2019. Lihat %(latest_version_link).

Skrip ini tidak untuk dipasang secara langsung. Ini adalah pustaka skrip lain untuk disertakan dengan direktif meta // @require https://update.greasyfork.org/scripts/393085/754478/CommonsUtil.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @author gaojr
// @namespace https://github.com/gaojr/tampermonkey-scripts
// @name:CN-zh_cn 工具类
// @name CommonsUtil
// @version 0.2
// @description utility methods
// @grant none
// ==/UserScript==

/**
 * 输出错误
 * @param functionName 方法名
 * @param error 错误
 */
const error = function (functionName, error) {
  console.error('function name: ' + functionName + "\nerror: " + error);
};

/**
 * 循环移除元素
 * @param ele 元素
 */
const removeRecursively = function (ele) {
  try {
    let parent = ele.parentElement;
    ele.remove();
    if (!!parent && !parent.innerHTML) {
      removeRecursively(parent);
    }
  } catch (e) {
    error('removeRecursively', e);
  }
};

/**
 * 移除选择器对象
 * @param selector 选择器
 */
const removeIt = function (selector) {
  try {
    removeRecursively(document.querySelector(selector));
  } catch (e) {
    error('removeIt', e);
  }
};

/**
 * 移除选择器所有对象
 * @param selector 选择器
 */
const removeAll = function (selector) {
  try {
    document.querySelectorAll(selector).forEach(function (ele) {
      removeRecursively(ele);
    });
  } catch (e) {
    error('removeAll', e);
  }
};

/**
 * 点击选择器对象
 * @param selector 选择器
 */
const clickIt = function (selector) {
  try {
    document.querySelector(selector).click();
  } catch (e) {
    error('clickIt', e);
  }
};