common.js

common filter

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/463829/1174761/commonjs.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 or Violentmonkey 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!)

/**
 * 过滤的通用模板
 * @param targets 选择对象
 * @param forFunction (target) => 遍历选择对象的元素
 */
 function filterTemplate(targets, forFunction) {
    let indexs = [];
    targets.each((index, element) => {
        if (forFunction($(element))) {
            indexs.push(index);
        }
    });
    if (indexs.length == 0) {
        return;
    }
    for (const i of indexs) {
        targets[i].remove();
    }
}
 
/**
 * 文本模糊匹配的过滤模板
 * @param targets 选择对象
 * @param textSelector 文本对象的选择器
 * @param texts 文本过滤关键词
 */
function textFilter(target, textSelector, textKeys) {
    let text = target.find(textSelector).text();
    for (const textKey of textKeys) {
        if (text.indexOf(textKey) != -1) {
            return true;
        }
    }
    return false;
}
 
/**
 * 文本精准相等过滤模板
 * @param target 选择对象
 * @param textSelector 文本对象的选择器
 * @param keySet 过滤关键词
 */
function keyFilter(target, textSelector, keySet) {
    if (null == keySet || 0 == keySet.length) {
        return;
    }
    let title = target.find(textSelector).text();
    return keySet.has(title);
}
 
/**
 * 设置,如果第一次失败则开启一个定时任务设置直到成功
 * @param selector 位置的文本
 * @param func 具体设置的方法
 */
function doWithInterval(selector, func) {
    let position = $(selector);
    if (position.length != 0) {
        func(position);
        return;
    }
    let timerTask = setInterval(function () {
        position = $(selector);
        if (position.length != 0) {
            func(position);
            clearInterval(timerTask);
        }
    }, 500);
}