.net5 swagger添加复制链接
作者:互联网
在startup文件中的configure方法中添加
复制需要权限,可以在设置中打开
app.UseSwaggerUI(c =>
{
c.HeadContent = @"<script type='text/javascript'>
function getUrl(btn){
let text=btn.innerText;
let startIndex=text.indexOf('\n');
let endIndex=text.lastIndexOf('\n');
let url=text.substr(startIndex+1,endIndex-startIndex-1);
let encodeURL=encodeURI(url);
let index=encodeURL.indexOf('/');
url=encodeURL.substr(index,encodeURL.length-index);
//alert( url);
console.log(url);
navigator.clipboard.writeText(url);
//navigator.clipboard.writeText('test');
}
//let load=window.onload;
function init(){
//let btns=document.getElementsByClassName('opblock-summary-control');
let btns=document.getElementsByClassName('opblock-summary opblock-summary-get');
console.log(btns.length);
for(let i=0;i<btns.length;i++){
//let btn=btns[i];
let btn=document.createElement('button');
btn.textContent='获取url';
//btn.click=getUrl(btns[i]);
btn.addEventListener('click', function(e){getUrl(btns[i]); e.stopPropagation(); });
btns[i].append(btn);
}
}
console.log('init');
//window.addEventListener('load',init,false);
window.setTimeout(init,5000);
</script>";
});
标签:url,text,opblock,let,encodeURL,net5,swagger,链接,btns 来源: https://www.cnblogs.com/ives/p/15968946.html