AutoTaskFramework

自动任务

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/462822/1368972/AutoTaskFramework.js

// ==UserScript==
// @name         AutoTaskFramework
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAFyklEQVR4nO2dS2hdRRiAv5vbSsREDK3FlagYDTSlYkVw0aK4lqpJtLZa0zR0W+1KLVhBqETQrQsfTVoffQgqdFuU6kYRpTVKHyiC0GLaxIpdVNPcuJh7Md6c3jv/nHmdnPng36Snc/4z353HmfOqUD5WAeuBfqAPuAvoAW4CuurbXAYuAX8Ap4FTwI/AceCC53yXJOuAN4AfgBowbxg14GS9rHu9HsESoBvYBUxiLqBdTALP81/LSmTQA+wBpnEnojkuAi+jur1EnQqwFfgdfyKaYxrYUc+l1NyOGnBDiWiOL4DbnB5xxGwEZggvoTn+BIYcHnd0VIAxwld8q6gBeylBF1YF3iF8hevGfmC5k5qIgOXAZ4SvZGl8Cixrd3BFa0oVYBw1m8rDX8CXqInAJHAWdQZ+uf7vXcDNQC+wBnVmvx51bpOHcWAEJWhJkGfMqAFHgQGg02DfncBgvYw8Z/uvGew7Sh7HvBIOAqst5tIPHDLMpQY8ajGXINyBWuiTHvxp4EGHeT1U34c0rxkKfJ5Sweykbz9+1pi6gAMG+X1O8cZwAIaRdwmvBMhzJ/KxZUuAPHPRA0yhf4BzwGiQTBU7kEk5D9wYJFND9iD7xW0Pk+b/eAFZzrvDpCmnG/kS+rtAR4hkm5CMKReAG8KkKWMX8oEyFildyGZfz4VJU8ZJzITMA+8RXsoG9MeTyUA5arMOcxkxtZTD6Od7T6ActXiT/EJikNKPfit5PVCOWuTprmKTcvQaeTXH96ESbMcq8i3exTamDGnmOAesDJRjSwawKyN0S+lELffr5PhY6EEvi35H5Y6grjL6PuYrwFea266OUcjdDsveBryNfynHNbfrc5qFId/ipssK2X09opnXNx5z0uZX3AvxL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wwL/Ag+tV8ginTZwAAAAAElFTkSuQmCC
// @namespace    https://github.com/giveme0101/
// @version      3.4
// @description  自动任务框架
// @author       Kevin [email protected]
// @match        *://*/*
// @run-at       document-idles
// @noframes
// ==/UserScript==

/** tool kit **/
const t2lKit = {
    clog: function(leftText, rightText, endText) {
        let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
        const opt = Object.assign({
            type: 'log',
            leftBGColor: '#555555',
            leftColor: '#ededed',
            rightBGColor: '#ffc107',
            rightColor: '#262318'
        }, options);
        console[opt.type]('%c' + leftText + '%c' + rightText + (endText ? '%c\n' + endText : ''), 'color: ' + opt.leftColor + ';background-color: ' + opt.leftBGColor + ';border-radius: 2px 0 0 2px;padding: 0 5px', 'color: ' + opt.rightColor + ';background-color: ' + opt.rightBGColor + ';border-radius: 0 2px 2px 0;padding: 0 5px;', '');
    },

    eleHide: function(ele, callback){
        let cnt = 1, scanInterval = setInterval(function(){
            const component = (typeof ele === "string" ? document.querySelector(ele) : ele);
            if (component || cnt++ >= 1000){
                clearInterval(scanInterval);
                component && (component.remove(), callback && callback());
            }
        }, 30);
    }
}

/** auto task framework **/
const autoTask = {

    taskExec: function(_config) {

        const urlHost = window.location.host;
        const cfgHosts = _config.host, cfgTest = _config.test;

        let hostMatch = cfgHosts instanceof Array ? cfgHosts.some(ele => urlHost.indexOf(ele) > -1) : urlHost.indexOf(cfgHosts) > -1;
        if (!hostMatch) return;

        let testMatch = (typeof cfgTest) === 'boolean' ? cfgTest : cfgTest();
        if (!testMatch) return;

        t2lKit.clog("Auto Task™", "3.4", "plugin active [" + _config.name + "]: " + _config.desc);
        _config.action(_config.param);
    },

    run: function(configs){
        for (const idx in configs){
            try {
                this.taskExec(configs[idx]);
            } catch(e){
                console.error("Auto Task™ plugin [" + configs[idx].name + "] throw exception: " + e);
            }
        }
    }
}

window.autoTask = autoTask;
window.t2lKit = t2lKit;