Custom GitLab Style

Custom GitLab Style!

  1. // ==UserScript==
  2. // @name Custom GitLab Style
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.05
  5. // @description Custom GitLab Style!
  6. // @author Sean
  7. // @match http://192.168.0.200*
  8. // @match http://192.168.0.200/*
  9. // @match http://192.168.0.200/fe3project*
  10. // @icon http://192.168.0.200/assets/favicon-7901bd695fb93edb07975966062049829afb56cf11511236e61bcf425070e36e.png
  11. // @require https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js
  12. // @require https://unpkg.com/element-ui/lib/index.js
  13. // @resource ElementCSS https://unpkg.com/element-ui/lib/theme-chalk/index.css
  14. // @grant GM_addStyle
  15. // @grant GM_getResourceText
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. // 注入样式:改变容器宽度,项目描述多行展示
  22. let injectStyle = ".group-list-tree .group-row-contents .description p { white-space: normal; } .container-limited.limit-container-width { max-width: 1400px } .limit-container-width .info-well {max-width: none;}";
  23.  
  24. injectStyle += ".container-fluid.container-limited.limit-container-width .file-holder.readme-holder.limited-width-container .file-content {max-width: none;}"
  25. injectStyle += 'button:focus {outline-color: transparent !important;}'
  26. // 添加注入样式
  27. let extraStyleElement = document.createElement("style");
  28. extraStyleElement.innerHTML = injectStyle;
  29. document.head.appendChild(extraStyleElement);
  30.  
  31. const fontUrl = 'https://element.eleme.io/2.11/static/element-icons.535877f.woff';
  32.  
  33. // 添加样式规则,将字体应用到指定元素上
  34. GM_addStyle(`
  35. @font-face {
  36. font-family: element-icons;
  37. src: url(${fontUrl}) format("woff");
  38. }
  39. `);
  40.  
  41. GM_addStyle(GM_getResourceText('ElementCSS'));
  42.  
  43. // 改变列表打开链接方式,改为新窗口打开
  44. let change = false;
  45. let tryTimes = 3;
  46.  
  47. function changeOpenType() {
  48. if(!change){
  49. setTimeout(()=> {
  50. let links = document.querySelectorAll('.description a');
  51. if(links.length) {
  52. for(let i = 0, l = links.length; i < l; i++) {
  53. links[i].target = "_blank";
  54. if(i === l - 1) {
  55. change = true;
  56. }
  57. }
  58. } else {
  59. changeOpenType();
  60. }
  61. }, 1000);
  62. }
  63. }
  64.  
  65. function stopLinkProp() {
  66. setTimeout(()=> {
  67. const links = document.querySelectorAll('.description a');
  68. for(let i = 0, l = links.length; i < l; i++) {
  69. links[i].addEventListener('click', ()=> {
  70. event.stopPropagation();
  71. });
  72. }
  73. }, 1000);
  74. }
  75.  
  76. window.onload = ()=> {
  77.  
  78. var targetDiv = document.querySelector('section');
  79.  
  80. if(targetDiv) {
  81. // 创建一个 Mutation Observer 实例
  82. var observer = new MutationObserver(function(mutations) {
  83. // 在这里处理 div 子元素的变化
  84. mutations.forEach(function(mutation) {
  85. if(mutation.addedNodes && mutation.addedNodes.length) {
  86. change = false;
  87. changeOpenType();
  88.  
  89. stopLinkProp();
  90. }
  91. });
  92. });
  93.  
  94. // 配置 Mutation Observer
  95. var config = { childList: true, subtree: true };
  96.  
  97. // 开始观察目标 div 元素
  98. observer.observe(targetDiv, config);
  99. }
  100.  
  101. const placeholder = document.createElement('div');
  102.  
  103. // 创建 Vue 实例并挂载到页面
  104. const vueInstance = new Vue({
  105. el: placeholder,
  106. methods: {
  107. // 进入管理平台 code pipeline
  108. manage() {
  109. window.open('http://192.168.219.170/code-pipeline')
  110. }
  111. },
  112. template: `<div id="my-ext" style="margin-top:4px;">
  113. <el-tooltip content="进入 Code Pipeline 管理平台" placement="top" effect="light">
  114. <el-button type="primary" icon="el-icon-attract" size="small" circle @click="manage"></el-button>
  115. </el-tooltip>
  116. </div>`
  117. });
  118.  
  119. // 将占位元素追加到 body 元素中
  120. document.querySelector('.title-container').appendChild(vueInstance.$el);
  121.  
  122. // 修改 placehodler
  123. const listInput = document.getElementById('group-filter-form-field');
  124. const listInput2 = document.getElementById('project-filter-form-field');
  125.  
  126. if(listInput) {
  127. listInput.setAttribute("placeholder", "按项目名称、日期、开发者搜索,关键字≥3");
  128. listInput.style.width = '305px';
  129. }
  130. if(listInput2) {
  131. listInput2.setAttribute("placeholder", "按项目名称、日期、开发者搜索,关键字≥3");
  132. listInput2.style.width = '305px';
  133. }
  134. };
  135.  
  136. })();