CommonsUtil

utility methods

Version vom 02.12.2019. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/393085/754478/CommonsUtil.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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);
  }
};