gitlab-ci-batch

批量上线samza任务脚本

  1. // ==UserScript==
  2. // @name gitlab-ci-batch
  3. // @namespace undefined
  4. // @version 1.0
  5. // @description 批量上线samza任务脚本
  6. // @author songyang
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
  8. // @match https://git.yidian-inc.com:8021/cpp-streaming/cpp-samza-*-ci/pipelines/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Your code here...
  16.  
  17. function finalFunc() {
  18. // css
  19. $(".left-margin")[0].style.width="600px";
  20.  
  21. $.each( $(".left-margin .build"), function( key, value ) {
  22.  
  23. $(value).css("width", "auto");
  24. $(value).css("height", "40px");
  25.  
  26. });
  27.  
  28. $.each( $(".left-margin .ci-job-component"), function( key, value ) {
  29.  
  30. $(value).css("display", "inline-block");
  31. $(value).css("border", "1px solid #e5e5e5");
  32. $(value).css("background-color", " white");
  33. $(value).css("border-radius", "30px");
  34. $(value).css("height", "40px");
  35. $(value).css("padding", "8px 20px 10px 10px");
  36.  
  37. $(value).find(".build-content")[0].style.border="0px";
  38. $(value).find(".build-content")[0].style.borderRadius="0px";
  39. $(value).find(".build-content")[0].style.padding="0px";
  40. $(value).find(".build-content")[0].style.width="auto";
  41. $(value).find(".build-content")[0].style.backgroundColor="transparent";
  42.  
  43.  
  44. $(value).find(".ci-status-text")[0].style.maxWidth="10000px";
  45.  
  46. $(value).find(".ci-action-icon-container")[0].style.display="inline";
  47. $(value).find(".ci-action-icon-container")[0].style.position="static";
  48. $(value).find(".ci-action-icon-container")[0].style.right="";
  49. $(value).find(".ci-action-icon-container")[0].style.top="";
  50. $(value).find(".ci-action-icon-container")[0].style.border="0px";
  51. $(value).find(".ci-action-icon-container")[0].style.borderRadius="0px";
  52. $(value).find(".ci-action-icon-container")[0].style.marginLeft="8px";
  53. $(value).find(".ci-action-icon-container")[0].style.backgroundColor="transparent";
  54.  
  55. $(value).find(".ci-action-icon-container svg")[0].style.top="0px";
  56.  
  57. //console.log($(value).find(".ci-status-text"));
  58. });
  59.  
  60. // click logic
  61. var selects = []
  62. $("a[data-original-title*='manual']").click(function() {
  63. var link = this.href + "/play";
  64. console.log("you found one " + link);
  65. var index = $.inArray(link, selects);
  66. if (index == -1) {
  67. selects.push(link);
  68. $(this).parent("div").css("background-color", "yellow");
  69. } else {
  70. selects.splice(index, 1);
  71. $(this).parent("div").css("background-color", "white");
  72. }
  73. return false;
  74. });
  75.  
  76. $("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>');
  77. $("#submit-batch").click(function() {
  78. $.each(selects, function(index, val){
  79. console.log("index is " + index + ", val is " + val);
  80. var csrf_token = $('meta[name="csrf-token"]').attr('content');
  81. $.ajax({
  82. url: val,
  83. type: "post",
  84. headers: {
  85. 'x-csrf-token': csrf_token
  86. }
  87. });
  88. });
  89. })
  90. }
  91.  
  92. var waitForEl = function(selector, callback) {
  93. if (jQuery(selector).length) {
  94. callback();
  95. } else {
  96. console.log("wait 500ms");
  97. setTimeout(function() {
  98. waitForEl(selector, callback);
  99. }, 500);
  100. }
  101. };
  102.  
  103. waitForEl(".left-margin", finalFunc);
  104. })();