您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
hello world
当前为
// ==UserScript== // @name gitlab_code_reviewer_helper // @namespace http://tampermonkey.net/ // @version 0.5.5 // @description hello world // @author You // @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js // @match https://code.byted.org/*/*/merge_requests/* // @match https://codebase.byted.org/standalone-page/repository/* // @icon https://www.google.com/s2/favicons?sz=64&domain=byted.org // @grant none // @license no // ==/UserScript== const optionsStrList = [ '风格问题-lint可修复', '风格问题-lint无法自动修复', '风格问题-未确定规范', '单测问题', '逻辑问题(bug)', 'debug代码未还原', '存在性能隐患', '存在安全隐患' ] const reg = /(\[风格问题-lint可修复\].+|\[风格问题-lint无法自动修复\].+|\[风格问题-未确定规范\].+|\[单测问题\].+|\[逻辑问题\(bug\)\].+|\[debug代码未还原\].+|\[存在性能隐患\].+|\[存在安全隐患\].+)/g const replaceReg = /(\[风格问题-lint可修复\]|\[风格问题-lint无法自动修复\]|\[风格问题-未确定规范\]|\[单测问题\]|\[逻辑问题\(bug\)\]|\[debug代码未还原\]|\[存在性能隐患\]|\[存在安全隐患\])/g const disabledStyle = `background-color:#eee!important; cursor:not-allowed!important; color:#b2b2b2!important; border: 1px solid #e5e6e8!important; margin-left: 8px; ` const cancelDisableStyle = `background-color:#fafbfc!important; cursor:pointer!important; margin-left: 8px!important;` function addCateBtn() { const btnContainer = $('.codebase-dv-thread') btnContainer.each((index,item)=>{ if($(item).find('.xbw-select-wrap')?.length){ $(item).find('textarea').trigger('input') return } let ele = $(`<span class=xbw-select-wrap><select style="width:100px;height:20px;font-size:10px;"><option value="">请选择分类</option>${optionsStrList.map((item,index)=>{ return `<option value=${item}>${item}</option>` }).join('\n')}</select></span>`); let selectedValue = "" ele.on('input', function (e) { setTimeout(()=>{ let val = $($(item).find('textarea')[0]).val() selectedValue = $(item).find('option:selected').val() if (selectedValue) { replaceReg.lastIndex = 0 if(replaceReg.test(val)){ const str = val.replace(replaceReg, `[${selectedValue}]`) $($(item).find('textarea')[0]).val(str) }else{ val = `[${selectedValue}]${val}` $($(item).find('textarea')[0]).val(val) } $(item).find('textarea').trigger('input') } }) }) $(item).find('textarea').on('input', function (e) { setTimeout(()=>{ const isCancel = $($(item).find('button')[1]).html() === 'Cancel' const blueBg = ['Start a review', 'Submit', 'Add review comment'] const isStartAReview = blueBg.includes($($(item).find('button')[0]).html()) reg.lastIndex = 0 const hasSelect = $(item).find('.xbw-select-wrap').length if (hasSelect && reg.test(e.target.value)) { $($(item).find('button')[0]).attr('disabled',false) $($(item).find('button')[1]).attr('disabled',false) } else if (!hasSelect) { } else { $($(item).find('button')[0]).attr({disabled:'disabled'}) $($(item).find('button')[1]).attr('disabled',!isCancel) } if($($(item).find('button')[0]).attr('disabled')){ // 禁用状态 样式修改 $($(item).find('button')[0]).css("cssText", disabledStyle); $($(item).find('button')[0]).attr({title:"w请选择分类"}) if(!isCancel){ $($(item).find('button')[1]).css("cssText", disabledStyle); $($(item).find('button')[1]).attr({title:"请选择分类"}) } }else{ $($(item).find('button')[0]).css("cssText",cancelDisableStyle); $($(item).find('button')[0]).attr({title:''}) if(!isCancel){ $($(item).find('button')[1]).css("cssText",cancelDisableStyle); $($(item).find('button')[1]).attr({title:''}) } if (isStartAReview) { $($(item).find('button')[0]).css("cssText",`border: 1px solid #3f51b5!important;background-color: #3f51b5!important;margin-left: 8px!important;`); } } }) }) $(item).find('textarea').trigger('input') setTimeout(()=>{ const value = $($(item).find('textarea')[0]).val() replaceReg.lastIndex = 0 if($(item).find('.md-preview').length && replaceReg.test(value)){ $($(item).find("[data-name='Preview']").parent()[0]).after(ele) }else if($(item).find('.md-preview').length){ }else{ $($(item).find("[data-name='Preview']").parent()[0]).after(ele) } }) }) } (function() { 'use strict'; window.setInterval(() => { $('.codebase-dv-tr').filter((index, item) => { return !$(item).attr('data-cr-marked') }).attr('data-cr-marked', true) addCateBtn() }, 1000); })();