Micoua_Jenkins

Jenkins页面调整工具

目前为 2021-06-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Micoua_Jenkins
  3. // @version 1.0.0
  4. // @author micoua
  5. // @namespace https://greasyfork.org/zh-CN/users/162781
  6. // @description Jenkins页面调整工具
  7.  
  8. // @include *
  9.  
  10. // ↓ jQuery核心文件 ↓
  11. // @require https://greasyfork.org/scripts/39025-micoua-jquery-min-js/code/Micoua_jQuery_min_js.js?version=255336
  12. // ↓ jQueryUI核心文件 ↓
  13. // @require https://greasyfork.org/scripts/40306-micoua-jqueryui-min-js/code/Micoua_jQueryUI_min_js.js?version=267377
  14.  
  15. // @grant unsafeWindow
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_deleteValue
  19. // @grant GM_listValues
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. function main() {
  24. if (currentURL.indexOf("jenkins.duibar.com") != -1 && currentURL.indexOf("/job") != -1) {
  25. /** 项目构建页面调整 */
  26. var options = {}; // 定义分支列表数组
  27. var tag = true; // 定义分支初始化标签
  28. if (currentURL.indexOf("/build") != -1) {
  29. // 移除原文字
  30. $(".setting-name").remove();
  31. // 添加搜索框
  32. $(".setting-main").prepend("<input type='text' id='search' placeholder=' 搜索分支' onKeypress='javascript:if(event.keyCode === 32)event.returnValue = false;'>");
  33. // 搜索框监听
  34. $("#search").bind("input propertychange change", function () {
  35. var text = $(this).val().replace(/\s/gi, ''); // 获取搜索框内容
  36. addBranchDatas(text); // 添加分支数据
  37. $(this).val("").focus().val(text); // 自动聚焦搜索框
  38. });
  39. // 搜索框样式
  40. $("#search").css({ "width": "300px", "margin-bottom": "2px" });
  41. // 分支列表样式
  42. $("#select").css({ "height": "200px", "width": "300px", "min-width": "" });
  43. }
  44.  
  45. /** 控制台输出页面调整 */
  46. if (currentURL.indexOf("/console") != -1) {
  47. var progressNum = 0;
  48. var reloadTag = $(".console-output").html().indexOf("Finished: SUCCESS") != -1 || $(".console-output").html().indexOf("Finished: FAILED") != -1;
  49. var autoRefash = GM_getValue("autoRefash_Jenkins") === undefined ? false : GM_getValue("autoRefash_Jenkins");
  50. // 添加进度百分比显示
  51. if (!reloadTag) {
  52. // 获取实时进度
  53. $.ajax({
  54. url: currentURL,
  55. async: false,
  56. success: function (data) {
  57. // 清除原有tempDiv
  58. $("#tempDiv").remove();
  59. $("#menuSelector").remove();
  60. var tempDiv = document.createElement("div");
  61. tempDiv.id = "tempDiv";
  62. tempDiv.style = "display: none";
  63. tempDiv.innerHTML = data;
  64. $("#page-head").append(tempDiv);
  65. progressNum = tools().getIntNum($("#tempDiv .progress-bar-done").css("width"));
  66. }
  67. });
  68.  
  69. // 清除原有进度百分比
  70. $("#progressBar").remove();
  71. $(".middle-align > tbody > tr").append("<td id='progressBar'>已完成: " + progressNum + "%</td>");
  72. $(".progress-bar-done").css({ "width": progressNum + "%" });
  73. $(".progress-bar-left").css({ "width": 100 - progressNum + "%" });
  74.  
  75. // 自动更新页面信息
  76. $("head title").text(currentURL.split("/")[currentURL.split("/").length - 3] + " #" + progressNum + "%"); // 修改标签标题
  77. setTimeout(function () { modifyStyle_jenkins(); }, 1000); // 定时刷新
  78. GM_setValue("autoRefash_Jenkins", true);
  79. } else if (autoRefash) {
  80. GM_setValue("autoRefash_Jenkins", false);
  81. window.location.href = currentURL;
  82. }
  83.  
  84. // 控制台悬停事件
  85. $(".build-caption.page-headline").hover(function () { $(this).css("cursor", "pointer"); }, function () { $(this).css("cursor", ""); });
  86. // 刷新页面
  87. $(".build-caption.page-headline").click(function () { window.location.href = currentURL; });
  88. // 控制台指示灯样式
  89. $(".build-caption.page-headline").css({ "position": "fixed", "right": "50px", "top": "70px" });
  90. // 进度条位置
  91. $(".build-caption-progress-container").css({ "padding": "22px 0px 0px 5px", "float": "" });
  92. // 进度条样式
  93. $(".progress-bar-done").css({ "height": "10px" });
  94. }
  95.  
  96. /** 添加分支数据 */
  97. // text:实时获取的搜索框的内容
  98. addBranchDatas = function (text) {
  99. // 获取所有原分支列表
  100. if (tag) {
  101. options = $("#select option").map(function () { return $(this).val(); }).get().join(",").split(",");
  102. tag = false;
  103. }
  104. // 初始化分支列表
  105. var option = "";
  106. // 添加分支列表数据
  107. 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>"; } }
  108. // 没有分支提示
  109. if (option === "") { option += "<option value='null'>暂无此分支</option>"; }
  110. // 定义分支列表
  111. 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>");
  112. // 移除原有分支列表
  113. $("#select").remove();
  114. // 添加新分支列表
  115. $("div[name='parameter']").append(select);
  116. };
  117. }
  118. }
  119.  
  120. /** 加载完所有数据后进入主函数 **/
  121. if (true) main();
  122. })();