gitlab-ci-batch

批量上线samza任务脚本

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         gitlab-ci-batch
// @namespace    undefined
// @version      1.0
// @description  批量上线samza任务脚本
// @author       songyang
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
// @match        https://git.yidian-inc.com:8021/cpp-streaming/cpp-samza-*-ci/pipelines/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...

    function finalFunc() {
        // css
        $(".left-margin")[0].style.width="600px";

        $.each( $(".left-margin .build"), function( key, value ) {

            $(value).css("width", "auto");
            $(value).css("height", "40px");

        });

        $.each( $(".left-margin .ci-job-component"), function( key, value ) {

            $(value).css("display", "inline-block");
            $(value).css("border", "1px solid #e5e5e5");
            $(value).css("background-color", " white");
            $(value).css("border-radius", "30px");
            $(value).css("height", "40px");
            $(value).css("padding", "8px 20px 10px 10px");

            $(value).find(".build-content")[0].style.border="0px";
            $(value).find(".build-content")[0].style.borderRadius="0px";
            $(value).find(".build-content")[0].style.padding="0px";
            $(value).find(".build-content")[0].style.width="auto";
            $(value).find(".build-content")[0].style.backgroundColor="transparent";


            $(value).find(".ci-status-text")[0].style.maxWidth="10000px";

            $(value).find(".ci-action-icon-container")[0].style.display="inline";
            $(value).find(".ci-action-icon-container")[0].style.position="static";
            $(value).find(".ci-action-icon-container")[0].style.right="";
            $(value).find(".ci-action-icon-container")[0].style.top="";
            $(value).find(".ci-action-icon-container")[0].style.border="0px";
            $(value).find(".ci-action-icon-container")[0].style.borderRadius="0px";
            $(value).find(".ci-action-icon-container")[0].style.marginLeft="8px";
            $(value).find(".ci-action-icon-container")[0].style.backgroundColor="transparent";

            $(value).find(".ci-action-icon-container svg")[0].style.top="0px";

            //console.log($(value).find(".ci-status-text"));
        });

        // click logic
        var selects = []
        $("a[data-original-title*='manual']").click(function() {
            var link = this.href + "/play";
            console.log("you found one " + link);
            var index = $.inArray(link, selects);
            if (index == -1) {
                selects.push(link);
                $(this).parent("div").css("background-color", "yellow");
            } else {
                selects.splice(index, 1);
                $(this).parent("div").css("background-color", "white");
            }
            return false;
        });

        $("div.content-wrapper").append('<div style="text-align: center"><button type="button" class="btn" id="submit-batch" style="width: 888px; background-color: green; height: 100px; border-radius: 30px">批量上线</button></div>');
        $("#submit-batch").click(function() {
            $.each(selects, function(index, val){
                console.log("index is " + index + ", val is " + val);
                var csrf_token = $('meta[name="csrf-token"]').attr('content');
                $.ajax({
                    url: val,
                    type: "post",
                    headers: {
                        'x-csrf-token': csrf_token
                    }
                });
            });
        })
    }

    var waitForEl = function(selector, callback) {
        if (jQuery(selector).length) {
            callback();
        } else {
            console.log("wait 500ms");
            setTimeout(function() {
                waitForEl(selector, callback);
            }, 500);
        }
    };

    waitForEl(".left-margin", finalFunc);
})();