Greasy Fork is available in English.

Micoua_jenkins

jenkins页面小工具

// ==UserScript==
// @name         Micoua_jenkins
// @version      1.0.0
// @author       micoua
// @namespace    https://greasyfork.org/zh-CN/users/162781
// @description  jenkins页面小工具

// @include      *

//               ↓ jQuery核心文件 ↓
// @require      https://greasyfork.org/scripts/39025-micoua-jquery-min-js/code/Micoua_jQuery_min_js.js?version=255336
//               ↓ jQueryUI核心文件 ↓
// @require      https://greasyfork.org/scripts/40306-micoua-jqueryui-min-js/code/Micoua_jQueryUI_min_js.js?version=267377

// @grant        unsafeWindow
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// ==/UserScript==

(function () {
    function main() {
        if (currentURL.indexOf("jenkins.duibar.com") != -1 && currentURL.indexOf("/job") != -1) {
            /** 项目构建页面调整 */
            var options = {}; // 定义分支列表数组
            var tag = true; // 定义分支初始化标签
            if (currentURL.indexOf("/build") != -1) {
                // 移除原文字
                $(".setting-name").remove();
                // 添加搜索框
                $(".setting-main").prepend("<input type='text' id='search' placeholder=' 搜索分支' onKeypress='javascript:if(event.keyCode === 32)event.returnValue = false;'>");
                // 搜索框监听
                $("#search").bind("input propertychange change", function () {
                    var text = $(this).val().replace(/\s/gi, ''); // 获取搜索框内容
                    addBranchDatas(text); // 添加分支数据
                    $(this).val("").focus().val(text); // 自动聚焦搜索框
                });
                // 搜索框样式
                $("#search").css({ "width": "300px", "margin-bottom": "2px" });
                // 分支列表样式
                $("#select").css({ "height": "200px", "width": "300px", "min-width": "" });
            }

            /** 控制台输出页面调整 */
            if (currentURL.indexOf("/console") != -1) {
                var progressNum = 0;
                var reloadTag = $(".console-output").html().indexOf("Finished: SUCCESS") != -1 || $(".console-output").html().indexOf("Finished: FAILED") != -1;
                var autoRefash = GM_getValue("autoRefash_Jenkins") === undefined ? false : GM_getValue("autoRefash_Jenkins");
                // 添加进度百分比显示
                if (!reloadTag) {
                    // 获取实时进度
                    $.ajax({
                        url: currentURL,
                        async: false,
                        success: function (data) {
                            // 清除原有tempDiv
                            $("#tempDiv").remove();
                            $("#menuSelector").remove();
                            var tempDiv = document.createElement("div");
                            tempDiv.id = "tempDiv";
                            tempDiv.style = "display: none";
                            tempDiv.innerHTML = data;
                            $("#page-head").append(tempDiv);
                            progressNum = tools().getIntNum($("#tempDiv .progress-bar-done").css("width"));
                        }
                    });

                    // 清除原有进度百分比
                    $("#progressBar").remove();
                    $(".middle-align > tbody > tr").append("<td id='progressBar'>已完成: " + progressNum + "%</td>");
                    $(".progress-bar-done").css({ "width": progressNum + "%" });
                    $(".progress-bar-left").css({ "width": 100 - progressNum + "%" });

                    // 自动更新页面信息
                    $("head title").text(currentURL.split("/")[currentURL.split("/").length - 3] + " #" + progressNum + "%"); // 修改标签标题
                    setTimeout(function () { modifyStyle_jenkins(); }, 1000); // 定时刷新
                    GM_setValue("autoRefash_Jenkins", true);
                } else if (autoRefash) {
                    GM_setValue("autoRefash_Jenkins", false);
                    window.location.href = currentURL;
                }

                // 控制台悬停事件
                $(".build-caption.page-headline").hover(function () { $(this).css("cursor", "pointer"); }, function () { $(this).css("cursor", ""); });
                // 刷新页面
                $(".build-caption.page-headline").click(function () { window.location.href = currentURL; });
                // 控制台指示灯样式
                $(".build-caption.page-headline").css({ "position": "fixed", "right": "50px", "top": "70px" });
                // 进度条位置
                $(".build-caption-progress-container").css({ "padding": "22px 0px 0px 5px", "float": "" });
                // 进度条样式
                $(".progress-bar-done").css({ "height": "10px" });
            }

            /** 添加分支数据 */
            // text:实时获取的搜索框的内容
            addBranchDatas = function (text) {
                // 获取所有原分支列表
                if (tag) {
                    options = $("#select option").map(function () { return $(this).val(); }).get().join(",").split(",");
                    tag = false;
                }
                // 初始化分支列表
                var option = "";
                // 添加分支列表数据
                for (var i = 0; i < options.length; i++) { if (options[i].toLowerCase().indexOf(text.toLowerCase()) != -1 || text === "") { option += "<option value='" + options[i] + "'>" + options[i] + "</option>"; } }
                // 没有分支提示
                if (option === "") { option += "<option value='null'>暂无此分支</option>"; }
                // 定义分支列表
                var select = $("<select fillurl='/view/dev-qiho-all/job/qiho-center/descriptorByName/net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition/fillValueItems?param=ChooseBranch' size='5' name='value' style='width: 300px; height: 200px' id='select' class='select'>" + option + "</select>");
                // 移除原有分支列表
                $("#select").remove();
                // 添加新分支列表
                $("div[name='parameter']").append(select);
            };
        }
    }

    /** 加载完所有数据后进入主函数 **/
    if (true) main();
})();