Greasy Fork

2.3-测序样品

测序样品

目前为 2023-07-02 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.cloud/scripts/469913/1214368/23-%E6%B5%8B%E5%BA%8F%E6%A0%B7%E5%93%81.js

function 测序样品(){
	console.log('新的测序样品界面')
	var local_修改样品名称=localStorage.getItem('修改样品名称');
	var html=$('iframe[src="/seq/SeqSampleList.aspx"]')//测序样品页面
	html=html.contents().find('body').eq(0)
	var toolbar=html.find('.toolbar').eq(0)  // 找到了toolbar工具栏
	var table=html.find('.ui-jqgrid-btable').eq(0)  // 找到了样品的table
	//添加toolbar工具栏按钮
	添加toolbar按钮(html)
	//添加toolbar工具栏按钮
	function 添加toolbar按钮(html){
		if (toolbar.find('.weiyiyici').length==0){
			//添加标记
			toolbar.addClass('weiyiyici')
			//添加修改样品名称按钮
			if (local_修改样品名称=='true'){
				toolbar.append('<span style="position:relative;z-index:2;"><button id="button_xiugai_yangpin" onclick="return false">修改样品名称◇</button><div id="div_xiugai_yangpin" style="position:absolute;width:230px;height:95px;border:1px solid orange;background-color:	#1B211D;display:none"></div></span>')
				var div_show_yincang=toolbar.find('#div_xiugai_yangpin').eq(0)
				div_show_yincang.append('<input type="text" id="text_qianzhui" placeholder="样品前缀" size="10"/><button id="button_qianzhui" onclick="return false">添加样品前缀</button>')
				div_show_yincang.append('<input type="text" id="text_houzhui"  placeholder="样品后缀" size="10"/><button id="button_houzhui" onclick="return false">添加样品后缀</button>')
				div_show_yincang.append('<input type="text" id="text_gaiqian"  placeholder="需要改的部分" size="15"/><input type="text" id="text_gaihou" placeholder="改成的部分" size="10"/><button id="button_genggai" onclick="return false">更改部分样品名称</button>')
				
				//点击修改样品名称按钮  显示或者隐藏DIV
				toolbar.find('#button_xiugai_yangpin').click(function(){
					显示隐藏DIV('#div_xiugai_yangpin',"button_xiugai_yangpin")
				})
				//点击添加样品前缀按钮执行如下函数
				toolbar.find('#button_qianzhui').click(function(){
					添加前后缀('前缀','#text_qianzhui')
				})
				//点击添加样品后缀按钮执行如下函数
				toolbar.find('#button_houzhui').click(function(){
					添加前后缀('后缀','#text_houzhui')
				})
				//点击 更改部分  执行如下函数
				toolbar.find('#button_genggai').click(function(){
					更改部分()
				})
				//给文本框绑定回车键的函数
				toolbar.find('#text_houzhui').eq(0).keypress(function(event){
					if(event.keyCode ==13){
						return false
					}
				});
				toolbar.find('#text_qianzhui').eq(0).keypress(function(event){
					if(event.keyCode ==13){
						return false
					}
				});
				toolbar.find('#text_gaiqian').eq(0).keypress(function(event){
					if(event.keyCode ==13){
						return false
					}
				});
				toolbar.find('#text_gaihou').eq(0).keypress(function(event){
					if(event.keyCode ==13){
						return false
					}
				});
			}
			//添加批量添加反应按钮
			if (local_批量添加反应=='true'){
				toolbar.append('<span style="position:relative;z-index:2;"><button id="button_piliang" onclick="return false"><font color="red">批量添加反应◇</font></button><div id="div_piliang" style="position:absolute;left:-250px;height:100px;width:430px;height:70px;border:1px solid orange;background-color:	#1B211D;display:none"></div></span>')
				div_piliang=toolbar.find('#div_piliang').eq(0)
				div_piliang.append('<input type="text" id="text_piliang_duotiaodai" placeholder="添加多条带,默认1" size="10" value="1"/><button id="button_duotiaodai" onclick="return false">批量添加多条带,默认双条带(带引物)</button><br/><br/>')
				div_piliang.append('<input type="text" id="text_piliang_tongming" placeholder="添加同名反应" size="10" value="1"/><button id="button_tongming" onclick="return false">批量添加同名反应,默认1(不带引物,一个名字只能选一次)</button>')			
				
				//点击批量添加反应按钮 显示或者隐藏DIV
				toolbar.find('#button_piliang').click(function(){
					显示隐藏DIV('#div_piliang',"button_piliang")
				})
			}
		}
	}
	
	//显示或者隐藏DIV
	function 显示隐藏DIV(div_id,button_id){
		div=toolbar.find(div_id).eq(0)
		div.toggle()
		//改变背景颜色
		if (div.css('display')==="none"){
			toolbar.find(button_id).css('background-color','')
		}else{
			toolbar.find(button_id).css('background-color','#B7A0AA')
			//如果是修改样品名称的div  把已填的数据清除
			if (div_id=='#div_xiugai_yangpin'){
				toolbar.find(div_id).eq(0).find(":input").val('')
			}
			//如果是批量添加反应的div  把已填的数据改为1
			if (div_id=='#div_piliang'){
				toolbar.find(div_id).eq(0).find(":input").val('1')
			}
		}
	}
	//添加前后缀
	function 添加前后缀(前后缀,id){
		//如果没有选择的行,那么退出
		if(table.find('tbody').find("[aria-selected='true']").size()==0){return false} 
		if(html.find(id).eq(0).val()===""){return false}
		selecteds=table.find('tbody').find("[aria-selected='true']")
		selecteds.each(function(){
			ids=$(this).find('[aria-describedby=list_undefined]').text()  //获取生产编号
			product_number=$(this).find('[aria-describedby=list_seqs_sam_num]').text()  //获取最开始的样品编号
			if (前后缀=='前缀'){
				new_product_number=toolbar.find('#text_qianzhui').eq(0).val()+product_number  //获取最新的样品编号
			}
			if (前后缀=='后缀'){
				new_product_number=product_number+toolbar.find('#text_houzhui').eq(0).val()  //获取最新的样品编号
			}
			//post请求 更改样品编号
			$.post("/seq/ashx/SeqSampleHandler.ashx",
				{action:"piliang_edit",ids:ids.slice(2),newValue:"seqs_sam_num="+new_product_number,rules_txt:"样品编号"},
				function (data,status) {console.log(data);}
			);
			html.find('.ui-pg-input').eq(0).focus()
			alert('修改了 '+table.find('tbody').find("[aria-selected='true']").size()+' 条反应的样品名称,光标自动定位在页数,直接按回车或更改页数可以查看更改结果')
			return false
		})
	}
	//更改部分样品名称
	function 更改部分(){
		//如果没有选择的行,那么退出
		if(table.find('tbody').find("[aria-selected='true']").size()==0){return false}  
		if(html.find('#text_gaiqian').eq(0).val()===""){return false}
		selecteds=table.find('tbody').find("[aria-selected='true']")
		//做个标记,只有所有的样品都只匹配到一次才可以
		var is_goon=true
		selecteds.each(function(){
			ids=$(this).find('[aria-describedby=list_undefined]').text()  //获取生产编号
			product_number=$(this).find('[aria-describedby=list_seqs_sam_num]').text()  //获取最开始的样品编号
			old_part=toolbar.find('#text_gaiqian').eq(0).val()  //获取需要更改的部分名称 前
			new_part=toolbar.find('#text_gaihou').eq(0).val()  //获取需要更改的部分名称  后
			num=product_number.split(old_part).length-1  //存在多少遍要更改的部分,只有1遍才可以
			if (num!=1){is_goon=false;  alert('只有每个样品都能匹配一次,才能修改');return false}
		})
		if (is_goon==true){
			selecteds.each(function(){
				ids=$(this).find('[aria-describedby=list_undefined]').text()  //获取生产编号
				product_number=$(this).find('[aria-describedby=list_seqs_sam_num]').text()  //获取最开始的样品编号
				old_part=toolbar.find('#text_gaiqian').eq(0).val()  //获取需要更改的部分名称
				new_part=toolbar.find('#text_gaihou').eq(0).val()  //获取需要更改的部分名称
				var reg = new RegExp(old_part,"g");
				new_product_number=product_number.replace(reg,new_part);  //改成最新的样品编号
				//post请求 更改样品编号
				$.post("/seq/ashx/SeqSampleHandler.ashx",
					{action:"piliang_edit",ids:ids.slice(2),newValue:"seqs_sam_num="+new_product_number,rules_txt:"样品编号"},
					function (data,status) {console.log("成功" + data);});
			})
			html.find('.ui-pg-input').eq(0).focus()
			alert('修改了 '+table.find('tbody').find("[aria-selected='true']").size()+' 条反应的样品名称,光标自动定位在页数,直接按回车或更改页数可以查看更改结果')
			return false
		}
	}
}