gitlab-ci-batch

批量上线samza任务脚本

当前为 2018-06-23 提交的版本,查看 最新版本

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