// ==UserScript== // @name 快速查包 // @namespace fsh // @version 4.8 // @description 快速跳转至指定包或指定分支 // @author xxtest // @match *://ci.meitu.city/* // @match *://ios.meitu-int.com/ipa/* // @match *://jira.meitu.com/* // @match *://cf.meitu.com/* // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @require https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js // @homepage https://greasyfork.org/zh-CN/scripts/454567-%E5%BF%AB%E9%80%9F%E6%9F%A5%E5%8C%85 // @license MIT // @note 4.8 选择bug平台报错解决 // @note 4.7 优化branch自动填写&手动填写的时机 // @note 4.6 支持cf中一键复制Android、iOS进版需求 // @note 4.5 支持创建bug dialog,自动填写build号 // @note 4.4 最近版本日期格式变化,进行适配。屏蔽starii创建djalog无效ui // @note 4.3 优化跳转至指定build的逻辑 // @note 4.2 添加homepage地址 // @note 4.1 获取分支功能支持Starii // @note 4.0 一键选择平台、日期功能支持Starii // @note 3.9 搜索分支功能,支持starii项目 // @note 3.8 starii域名变更,重新适配 // @note 3.7 支持Android跳转starii // @note 3.6 优化获取未发布版本的方式,避免获取不到新版本 // @note 3.5 更新创建bug Dialog获取分支按钮添加的判断条件 // @note 3.4 支持在备注输入框获取上次分支 // @note 3.3 支持在备注输入框获取分支 // @note 3.2 优化填入分支流程,支持搜索框回车代替点击 // @note 3.1 修复跳转分支时,bug平台获取错误的问题 // @note 3.0 修复跳转分支时,bug平台获取错误的问题 // @note 2.9 获取分支新增异常判断 // @note 2.8 整合代码 // @note 2.7 测试脚本自动升级 // @note 2.6 完善jira页面跳转按钮逻辑 // @note 2.5 修复img节点高度被限制的问题 // @note 2.4 granary支持全项目 // @note 2.3 Bug模版支持一键切换web,删除UpdateUrl和DownloadUrl // @note 2.2 Cicity支持全项目搜索和跳转 // @note 2.1 添加UpdateUrl和DownloadUrl配置 // @note 2.0 修复无法正确获取版本的问题(参数类型由str转int),填写完毕后主动失去焦点 // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 设置刷新时间 const refreshTime = 1000; // 添加CSS $('head').append($(` `)); // 当是ci域名时,才触发后续的操作,如果不是则不触发 // CI // CI // CI if (location.href.indexOf('ci.meitu.city') > 0) { clearInterval(refreshTime); setInterval(function () { let input_find_build = document.getElementById('input_find_build'); let to_new_build = document.getElementById('to_new_build'); // 不存在输入框和跳转按钮则添加 if (!input_find_build) { addFindButtonCicity(); // 当用户按下键盘上的某个键时触发 document.addEventListener("keyup", function(event) { // 如果按下的是回车键 if (event.keyCode === 13) { // 触发按钮的点击事件 $('#btn_find_build').click(); } }); // 跳转按钮点击 $('#btn_find_build').unbind("click").click(function () { // 获取当前url, 用正则表达式获取项目名 let localUrl = window.location.href let project = '' let reg = /(?<=build\/)\w*/ project = localUrl.match(reg)[0] if(project != null){ let baseUrl = 'https://ci.meitu.city/build/' + project + '/' // 获取用户输入 let input_build_content = document.getElementById("input_find_build").value.trim() if(input_build_content===""){ return false; } let targetUrl = "" // 如果输入的是纯数字,视为build id if(/^\d+$/.test(input_build_content)){ targetUrl = baseUrl + 'number/' + input_build_content }else{// 否则按输入的是分支处理 input_build_content = input_build_content.replaceAll("/","%2F") targetUrl = baseUrl + 'branch/' + input_build_content } // 跳转到指定页面 window.location.href=targetUrl } else{ input_find_build.value = "未能正确获取项目名称" } }); } // 不存在跳转至最新按钮则添加 if(!to_new_build){ addToNewCicity(); $('.to_new_build').unbind("click").click(function(){ // 判断当前所处的页面, 用正则表达式获取项目名 let localUrl = window.location.href let project = '' let reg = /(?<=build\/)\w*/ project = localUrl.match(reg)[0] // 获取所要跳转的分支名 let full_build_name = this.parentNode.children[0].innerText.trim() let targetUrl = "" let baseUrl = 'https://ci.meitu.city/build/' + project + '/branch/' full_build_name = full_build_name.replaceAll("/","%2F") targetUrl = baseUrl + full_build_name // 跳转到指定页面 window.location.href=targetUrl }); } }, refreshTime); } var project_android = {"美图秀秀":"Meitu","美颜相机":"BeautyCam", "美拍":"Meipai","美妆相机":"MakeupPlus", "潮自拍":"SelfieCity","设计室":"HaiBaoPai", "wink":"WINK","BeautyPlus":"BeautyPlus", "AirBrush":"AirBrush","eve":"eve", "chic":"chic","美图宜肤V":"eveking", "EveNetAssist":"evenetassist","VChat":"vchatbeauty", "vcut":"vcut","Vmake":"beautyplusvideo", "PixEngine":"pixengine","智肤APP":"skinar", "美图秀秀Starii":"starii" } var project_ios = {"美图秀秀":"mtxx","美颜相机":"myxj", "BeautyPlus":"beautyplus","wink":"wink", "潮自拍":"czp","设计室":"hbp", "wink":"WINK","BeautyPlus":"BeautyPlus", "美图秀秀Starii":"starii" } // CI页面,添加输入框和跳转按钮 function addFindButtonCicity() { let span = $('') let input_find_build = $(''); let btn_find_build = $(''); span.append(input_find_build); span.append(btn_find_build); $(".project-label__name").after(span); } // CI页面,在分支名后方添加跳转至最新按钮 function addToNewCicity(){ let to_new_build = $(''); $(".message-card__subtitle").after(to_new_build); } // 当是granary域名时,才触发后续的操作,如果不是则不触发 // Granary // Granary // Granary if (location.href.indexOf('ios.meitu-int.com') > 0) { clearInterval(refreshTime); setInterval(function () { let input_find_build = document.getElementById('input_find_build'); let to_new_build = document.getElementById('to_new_build'); // 项目名 var project = '' var reg = /(?<=ipa\/)\w*/ // 当前页面Url, 用正则表达式获取项目名 var localUrl = window.location.href project = localUrl.match(reg)[0] // 不存在输入框和跳转按钮则添加 if (!input_find_build) { addFindButtonGranary(); // 当用户按下键盘上的某个键时触发 document.addEventListener("keyup", function(event) { // 如果按下的是回车键 if (event.keyCode === 13) { // 触发按钮的点击事件 $('#btn_find_build').click(); } }); // 按钮绑定点击事件 $('#btn_find_build').unbind("click").click(function () { if(project != null){ // 获取用户输入 let input_build_content = document.getElementById("input_find_build").value.trim() if(input_build_content===""){ return false; } let targetUrl = "" // 如果输入的是纯数字,视为build id if(/^\d+$/.test(input_build_content)){ let baseUrl = 'http://ios.meitu-int.com/ipa/'+ project + '/build/' targetUrl = baseUrl + input_build_content }else{// 否则按分支处理 let baseUrl = 'http://ios.meitu-int.com/ipa/'+ project + '/' input_build_content = input_build_content.replaceAll("/","%2F") targetUrl = baseUrl + input_build_content } // 跳转到指定页面 window.location.href=targetUrl } else{ input_build_content.value = "未能正确获取项目名称" } }); } //不存在跳转至最新按钮则添加 if(!to_new_build){ addToNewGranary(); // 跳转按钮点击 $('.to_new_build').unbind("click").click(function(event){ // 分支名,去掉首尾的字符串,“/”转为“%2F” let parentNode = event.target.parentNode; let branchName = parentNode.querySelector("span.branch-name").innerText.trim() branchName = branchName.substring(1, branchName.length - 1).replaceAll("/","%2F"); // 跳转链接 let baseUrl = 'http://ios.meitu-int.com/ipa/'+ project + '/' let targetUrl = baseUrl + branchName // 跳转 window.location.href=targetUrl }); } }, refreshTime); } // granary页面,添加输入框和跳转按钮 function addFindButtonGranary() { let span = $('') let input_find_build = $(''); let btn_find_build = $(''); span.append(input_find_build); span.append(btn_find_build); $("#myTab").append(span); } // granary页面,在分支名后方添加跳转至最新按钮 function addToNewGranary(){ let to_new_build = $(''); $("div#list-home span.branch-name").after(to_new_build); } // 当是jira域名时,才触发后续的操作,如果不是则不触发 // Jira // Jira // Jira if (location.href.indexOf('jira.meitu.com') > 0) { clearInterval(refreshTime); var counter = 0; // 定时器循环操作:页面元素添加等 setInterval(function () { var search_span = document.getElementById('search_span_create'); // 因为切至iOS按钮和切至Android按钮一般都会成对出现,所以这里只获取iOS按钮,用于判断按钮是否已存在 var change_side_button = document.getElementById('change_side_ios'); var create_input = document.getElementById('customfield_10303'); var create_issue_dialog = document.getElementById('create-issue-dialog'); var close_bug_dialog = document.getElementById('workflow-transition-21-dialog'); var reopen_bug_dialog = document.getElementById('workflow-transition-31-dialog'); var comment_bug_toolbar = document.getElementById('wiki-edit-wikiEdit0'); // 如果不存在bug跳转按钮则添加一个,需要判断url是bug页面而不是bug列表页,否则会报错 if (!search_span) { addButtonJira(); // 存储bug平台 GM_setValue('platform', $('#customfield_10301-val').text().trim()) } // 在创建问题dialog添加获取分支按钮组 if (create_issue_dialog){ // 加个计时避免按钮显示不出来 // Bug模版按钮 if(change_side_button == undefined || change_side_button.length == 0){ addChangeSideButton(); } // 获取分支按钮 if(create_input !== undefined || create_input.length !== 0){ var branch_span = $(''); $("#customfield_10303").after(branch_span) add_get_branch_btn($(branch_span)); } // 隐藏starii项目不必要的UI hideUI(); // 自动填充build号 fillBuildIdAuto(); } // 自动往指定的input组件中填build号 function fillBuildIdAuto(){ // 获取输入框内容 var inputContent = $("#customfield_10303").val(); // 使用正则表达式检查当前文本内容是否是纯数字 var isCurrentNumber = /^\d+$/.test(inputContent); if (isCurrentNumber) { counter++; console.log(counter) // 如果当前文本内容是纯数字 if (counter % 6 === 0) { // 往输入框内填写 set_branch('get_branch_btn','create-issue-dialog') counter = 0; } } } // 在关闭问题dialog 或 重新打开dialog 添加获取分支按钮组 if (close_bug_dialog || reopen_bug_dialog) { var pre_text_button = $(''); var pre_text_btn = document.getElementById('close-text'); var branch_span_close = $('输入id:'); var input_text_close = $(''); setTimeout(function () { if (!pre_text_btn) { $(".jira-dialog-content .form-footer").append(branch_span_close).append(input_text_close);// buildid输入框 add_get_branch_btn($(".jira-dialog-content").find(".form-footer"));//获取分支按钮 $(".jira-dialog-content .form-footer").append(pre_text_button);//上次填写按钮 } }, 500); } // 在备注窗口添加获取分支按钮组 if (comment_bug_toolbar) { var pre_text_span = $('输入id:'); var pre_text_span_element = document.getElementById('pre_text'); var input_text = $(''); setTimeout(function () { if (!pre_text_span_element && !close_bug_dialog) { var branch_span = $(''); branch_span.append(pre_text_span).append(input_text); add_get_branch_btn($(branch_span)); $(".security-level .current-level").after(branch_span); } }, 500); } // 获取分支按钮点击事件 $('#get_branch_btn, #last_branch_btn').unbind("click").click(function(event) { setTimeout(function () { // 当前节点的父节点 var parentNode = event.target.parentNode; // 如果父节点没有Id属性,则往上遍历 while (parentNode != null) { if (parentNode.hasAttribute("id")) { // 找到第一个有id属性的父节点 var parentWithId = parentNode; break; } parentNode = parentNode.parentNode; } // 第一个拥有Id的父节点的id let parentId = parentWithId.getAttribute("id"); // 获取当前节点id var selfId = event.target.id // 往网页中填入分支名 set_branch(selfId, parentId); },500); }); function hideUI(){ // 获取具有id为project-options的div元素 var projectOptionsDiv = document.getElementById('project-options'); if(projectOptionsDiv){ // 获取data-suggestions属性的值 var dataSuggestionsValue = projectOptionsDiv.getAttribute('data-suggestions'); var jsonObject = JSON.parse(dataSuggestionsValue); // 项目名 var project = jsonObject[0]['items'][0].label.trim(); var project_name = project.replace(/\s*\([^)]*\)\s*/, '').trim(); }else{ var project_name = $('#project-name-val').text().trim(); // 项目名 } if(project_name === "美图秀秀Starii"){ hideParentNodeById("customfield_10422"); hideParentNodeById("customfield_10202"); hideParentNodeById("customfield_10305"); hideParentNodeById("customfield_11100"); hideParentNodeById("customfield_11101"); hideParentNodeById("customfield_11102"); hideParentNodeById("customfield_10304"); hideParentNodeById("fixVersions"); hideParentNodeById("reporter"); hideParentNodeById("customfield_13601"); } } // 隐藏指定ID节点的父节点 function hideParentNodeById(childNodeId){ // 隐藏bug优先级 var element = document.getElementById(childNodeId); // 检查是否找到了元素 if (element) { // 获取父节点并将其样式的display属性设置为"none" element.parentNode.style.display = "none"; } } // 往网页中填入分支名称 async function set_branch(selfId, parentId) { if (selfId === "get_branch_btn") { switch (parentId) { // 创建Bug窗口填写分支 case "create-issue-dialog": // bug平台节点和buildId节点 var $platform = $('input:radio[name="customfield_10301"]:checked'); var $buildId = $('#customfield_10303'); // 通过buildId节点(input)定位到bug平台节点(label) var id = $platform.attr("id") var label = document.querySelector("label[for='" + id + "']"); // bug平台和buildId try { var platform = label.textContent; } catch (error) { GM_setValue('branch_value', "#请先选择Bug平台"); fillInBranch('#customfield_10303'); return; } var buildId = $buildId.val(); if (buildId === undefined || buildId === ''||buildId === null) { GM_setValue('branch_value', "#请先填写Build号"); fillInBranch('#customfield_10303'); return; } console.log(platform) // 获取分支名 await get_branch(platform, buildId); // 填入分支 fillInBranch('#customfield_10303'); counter = 0; break; // 关闭||重新打开窗口填写分支 case "issue-workflow-transition": var $platform = $('#customfield_10301-val'); var $buildId = $('#build_id_close'); // bug平台和buildId var platform = $platform.text().trim(); var buildId = $buildId.val(); // 获取分支名 get_branch(platform, buildId); // 填入分支 fillInBranchTextarea('div#comment-wiki-edit textarea#comment'); // 聚焦到输入框 sleep(500).then(() => { $('#comment-wiki-edit textarea').focus(); }) break; // 备注 case "issue-comment-add": var $platform = $('#customfield_10301-val'); var $buildId = $('#input_text'); // bug平台和buildId var platform = $platform.text().trim(); var buildId = $buildId.val(); // 获取分支名 get_branch(platform, buildId); // 填入分支 fillInBranchTextarea('div#comment-wiki-edit textarea#comment'); // 聚焦到输入框 sleep(500).then(() => { $('#comment-wiki-edit textarea').focus(); }) break; default: } } else if (selfId === "last_branch_btn") { switch (parentId) { case "create-issue-dialog": // 填入分支 fillInBranch('#customfield_10303'); break; case "issue-workflow-transition": // 填入分支 fillInBranchTextarea('div#comment-wiki-edit textarea#comment'); break; // 备注 case "issue-comment-add": fillInBranchTextarea('div#comment-wiki-edit textarea#comment'); break; default: } } } // 跳转到创建分支 $('#search_span_create').unbind("click").click(function () { var build_id = getBuildId("customfield_10303-val"); // 存储bug平台 GM_setValue('platform', $('#customfield_10301-val').text().trim()) sleep(500).then(() => { var targetUrl = getBaseUrl() + build_id; window.open(targetUrl); }) }); // 跳转到解决分支 $('#search_span_solved').unbind("click").click(function () { var build_id = getBuildId("customfield_10304-val"); // 存储bug平台 GM_setValue('platform', $('#customfield_10301-val').text().trim()) sleep(500).then(() => { var targetUrl = getBaseUrl() + build_id; window.open(targetUrl); }) }); // 切换到iOS bug模版 $('.ios').unbind("click").click(function () { changeBugPlatform('iOS') }); // 切换到Androidbug模版 $('.android').unbind("click").click(function () { changeBugPlatform('Android') }); // 切换到Webbug模版 $('.web').unbind("click").click(function () { changeBugPlatform('Web') }); // 点击关闭问题按钮,记录下填写的内容 var text_area = $('.jira-dialog-content').find('#comment') $('#issue-workflow-transition-submit').unbind("click").click(function(){ if($('#issue-workflow-transition-submit').val().trim()=="关闭问题"){ // 存储bug平台 GM_setValue('closeText',text_area.val().trim()) } }) // 点击上次填写按钮,填充上次填写的内容 $('#close-text').unbind("click").click(function(){ text_area.val(GM_getValue('closeText')) text_area.focus() }) // TODO:点击「创建」按钮时记录下所有的bug信息 const $createBtn = $('#create-issue-submit'); const $summary = $('#summary'); const $business = $('input:radio[name="customfield_12903"]:checked'); const $platform = $('input:radio[name="customfield_10301"]:checked'); const $path0 = $("#selectCFLevel0 option:selected"); const $path1 = $("#selectCFLevel1 option:selected"); const $assignee = $("#assignee-field"); const $severity = $("#customfield_10406 option:selected"); const $version = $("#versions-multi-select .value-text"); const $find = $("#customfield_10202 option:selected"); const $frequency = $("#customfield_10204 option:selected"); const $branch = $("#customfield_10303"); const $step = $("#customfield_10203"); const $tips = $("#labels-multi-select .representation .value-text"); $createBtn.unbind('click').click(function() { const bugDict = { 'summary': $summary.val(), 'business': $business.attr("id"), 'platform': $platform.attr("id"), 'path0': $path0.text(), 'path1': $path1.text(), 'assignee': $assignee.val(), 'severity': $severity.text(), 'version': $version.text(), 'find': $find.attr("value"), 'frequency': $frequency.attr("value"), 'branch': $branch.val(), 'step': $step.val(), 'tips': $tips.text() }; GM_setValue('bugDict', bugDict); }); // 点击再提一个 // 已知问题:1. 路径2无法填写 $('#once-again').unbind('click').click(function() { const bugDict = GM_getValue('bugDict'); function setValue(selector, value) { $(selector).val(value); } function setChecked(selector, value) { $(selector).attr("checked", value); } function setSelected(selector, value) { $(selector).find(`option[value='${value}']`).attr("selected", true); } console.log(bugDict); setValue("#summary", bugDict.summary); setChecked(`input[id=${bugDict.business}]`, true); setChecked(`input[id=${bugDict.platform}]`, true); setValue("#selectCFLevel0", bugDict.path0); setValue("#selectCFLevel1", bugDict.path1); setValue("#assignee-field", bugDict.assignee); // $('#assignee').append($(' 元素 let optgroup = $('.aui-field-versionspicker').find('.multi-select-select').find('[label="未发布版本"]')[0] // 获取