MEST Batch Delete

美尔斯通批量删除

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 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.

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==
// @name         MEST Batch Delete
// @namespace    joyings.com.cn
// @version      0.1
// @description  美尔斯通批量删除
// @author       zmz125000
// @match        http://*/mest/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=92.133
// @grant        none
// @license        MIT
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...
    function deleteNext() {
        if (document.querySelectorAll('[class="el-button table-operation el-button--default el-button--mini"]').length == 0) {
            alert("finished");
            return 1;
        }
        document.querySelectorAll('[class="el-button table-operation el-button--default el-button--mini"]')[1].click();
        setTimeout(function () {
            document.querySelectorAll('[class="el-button el-button--default el-button--small el-button--primary "]')[0].click();
        }, 100);
        window.setTimeout(deleteNext, 500);
    };

    function deleteOnce() {
        document.querySelectorAll('[class="el-button table-operation el-button--default el-button--mini"]')[1].click();
        setTimeout(function () {
            document.querySelectorAll('[class="el-button el-button--default el-button--small el-button--primary "]')[0].click();
        }, 100);
    };

    window.addEventListener('load', function () {
        var btn = document.createElement('button');
        btn.setAttribute('title', '批量删除表体项目,使用前请先筛选');
        btn.setAttribute('type', 'button')
        btn.appendChild(document.createTextNode('BatchDelete'));
        btn.onclick = deleteNext;
        document.querySelector('[class="ml15"]').appendChild(btn);
    });

    function waitForElm(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                return resolve(document.querySelector(selector));
            }
            const observer = new MutationObserver(mutations => {
                if (document.querySelector(selector)) {
                    resolve(document.querySelector(selector));
                    observer.disconnect();
                }
            });
            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    };
})();