leetcode copy testcase

leetcode自动将测试用例转化为sql语句

Fra 18.09.2019. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         leetcode copy testcase
// @namespace   https://leetcode-cn.com/
// @version      0.11
// @description  leetcode自动将测试用例转化为sql语句
// @author       LiMingYu
// @match      https://leetcode-cn.com/submissions/detail/*
// @grant        none
// ==/UserScript==
//获取表的对象集合信息
var creattable="";
var sql=""
var tableinfos=JSON.parse(pageData.submissionData.input).headers
//得到插入的行信息
var tablerows=JSON.parse(pageData.submissionData.input).rows
//获得表名,字段名
for(var name in tableinfos){
    //得到列头
         var list=new Array();
      for(var k=0;k<tableinfos[name].length;k++)
      {

           list.push(tableinfos[name][k]+" varchar(200)")
      }

      creattable+='CREATE TABLE IF NOT EXISTS '+name+'('+list.join(",")+')'+';\n';
}
//处理数据

      for(var row in tablerows)
     {

        for(var i=0;i<tablerows[row].length;i++)
         {
              for(var j=0;j<tablerows[row][i].length;j++)
              {
                   if(tablerows[row][i][j]==null)
                       tablerows[row][i][j]="-"
                  tablerows[row][i][j]='"'+tablerows[row][i][j]+'"'
              }

        }
           console.log(tablerows[row].length)
         for(var m=0;m<tablerows[row].length;m++)
         {
             var str=tablerows[row][m].toString();
              sql+='INSERT INTO'+' '+row+ ' VALUES ('+str.replace(new RegExp("\\-","g"),"null")+')'+';\n';
         }
    }

//添加到页面上
$("#details-summary").append('<input type="button" value="复制" id="copy" class="btn btn-primary" ><input type="button" value="隐藏" id="watch" style="margin-left:10px" class="btn btn-primary" > <textarea style="margin-top:10px;height:200px;display:block" id="sql" value="" " class="form-control"></textarea>')
$("#sql").val(creattable+sql)
//添加滑动及其处理
$("#watch").click(
 function(){
     if($("#watch").val()=="查看")
     {
          $('#sql').css("display","block")
        $("#watch").val("隐藏")
     }
     else
      {
          $('#sql').css("display","none")
           $("#watch").val("查看")

      }
 })

$("#copy").click(
 function(){
      var urlresult=document.getElementById("sql")
    urlresult.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    alert("已复制好,可贴粘。");
 }

)