Greasy Fork

Greasy Fork is available in English.

阿里云效伴侣&WorkTile

让工作更高效,让生活更美好!

当前为 2022-05-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         阿里云效伴侣&WorkTile
// @version      0.0.7
// @description  让工作更高效,让生活更美好!
// @author       Jack.Chan ([email protected])
// @namespace    http://fulicat.com
// @url          http://greasyfork.icu/zh-CN/scripts/444697-%E9%98%BF%E9%87%8C%E4%BA%91%E6%95%88%E4%BC%B4%E4%BE%A3-worktile
// @license MIT
// @match        https://flow.aliyun.com/pipelines/*/*
// @icon         https://www.google.com/s2/favicons?domain=aliyun.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function run() {
        var pipelinesId = 0;
        var paths = window.location.pathname.split('/');
        if (paths.length > 3 && !isNaN(paths[2])) {
            pipelinesId = paths[2];

            var $Branch = document.querySelector('.yx-input>input[value="Branch"]');
            var $WorktileTask = document.querySelector('.yx-input>input[id="WorktileTask"]');
            var $BtnCancel = document.querySelector('.yx-dialog-footer>button:nth-child(1)');
            var $BtnRun = document.querySelector('.yx-dialog-footer>button:nth-child(2)');
            var isReady = $Branch && $WorktileTask && $BtnRun && $BtnRun?.innerText === '运行' && $BtnCancel;
            if (pipelinesId && isReady) {
                var hasBind = !!$BtnRun.hasBind;
                if (!hasBind) {
                    $Branch.addEventListener('input', function(event) {
                        var branch = this.value.trim();
                        var key = 'pipelinesId:'+ pipelinesId +':'+ branch;
                        if (branch) {
                            var task = window.localStorage.getItem(key);
                            if (task) {
                                console.log('@hasTask', key, task);
                                setTimeout(() => {
                                    $WorktileTask.value = task;
                                }, 10);
                            }
                        }
                    }, false);
                    $BtnCancel.addEventListener('click', function(event) {
                        var branch = $Branch.value.trim();
                        var key = 'pipelinesId:'+ pipelinesId +':'+ branch;
                        if (branch) {
                            window.localStorage.removeItem(key);
                            console.log('@removed', key);
                        }
                    }, false);
                    $BtnRun.addEventListener('click', function(event) {
                        event.stopPropagation();
                        event.preventDefault();
                        var branch = $Branch.value.trim();
                        var task = $WorktileTask.value.trim();
                        var key = 'pipelinesId:'+ pipelinesId +':'+ branch;
                        if (branch && task) {
                            window.localStorage.setItem(key, task);
                            console.log('@saved', key, task);
                        }
                    }, false);
                    $BtnRun.hasBind = true;
                }
                console.log('hasBind:'+ hasBind);
            }
            console.log('isReady:pipelinesId:'+ pipelinesId);
        }

    }

    function init() {
        document.body.addEventListener('mousedown', function(e) {
            var $yxdialog = document.querySelector('.yx-dialog');
            var delay = $yxdialog ? 300 : 2000;
            setTimeout(() => {
                run();
            }, delay);
        }, false);
    }

    if (document.contentType.startsWith('text/html')) {
        init();
    }
})();