leetcode copy testcase

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

Verze ze dne 18. 09. 2019. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name leetcode copy testcase
  3. // @namespace https://leetcode-cn.com/
  4. // @version 0.11
  5. // @description leetcode自动将测试用例转化为sql语句
  6. // @author LiMingYu
  7. // @match https://leetcode-cn.com/submissions/detail/*
  8. // @grant none
  9. // ==/UserScript==
  10. //获取表的对象集合信息
  11. var creattable="";
  12. var sql=""
  13. var tableinfos=JSON.parse(pageData.submissionData.input).headers
  14. //得到插入的行信息
  15. var tablerows=JSON.parse(pageData.submissionData.input).rows
  16. //获得表名,字段名
  17. for(var name in tableinfos){
  18. //得到列头
  19. var list=new Array();
  20. for(var k=0;k<tableinfos[name].length;k++)
  21. {
  22.  
  23. list.push(tableinfos[name][k]+" varchar(200)")
  24. }
  25.  
  26. creattable+='CREATE TABLE IF NOT EXISTS '+name+'('+list.join(",")+')'+';\n';
  27. }
  28. //处理数据
  29.  
  30. for(var row in tablerows)
  31. {
  32.  
  33. for(var i=0;i<tablerows[row].length;i++)
  34. {
  35. for(var j=0;j<tablerows[row][i].length;j++)
  36. {
  37. if(tablerows[row][i][j]==null)
  38. tablerows[row][i][j]="-"
  39. tablerows[row][i][j]='"'+tablerows[row][i][j]+'"'
  40. }
  41.  
  42. }
  43. console.log(tablerows[row].length)
  44. for(var m=0;m<tablerows[row].length;m++)
  45. {
  46. var str=tablerows[row][m].toString();
  47. sql+='INSERT INTO'+' '+row+ ' VALUES ('+str.replace(new RegExp("\\-","g"),"null")+')'+';\n';
  48. }
  49. }
  50.  
  51. //添加到页面上
  52. $("#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>')
  53. $("#sql").val(creattable+sql)
  54. //添加滑动及其处理
  55. $("#watch").click(
  56. function(){
  57. if($("#watch").val()=="查看")
  58. {
  59. $('#sql').css("display","block")
  60. $("#watch").val("隐藏")
  61. }
  62. else
  63. {
  64. $('#sql').css("display","none")
  65. $("#watch").val("查看")
  66.  
  67. }
  68. })
  69.  
  70. $("#copy").click(
  71. function(){
  72. var urlresult=document.getElementById("sql")
  73. urlresult.select(); // 选择对象
  74. document.execCommand("Copy"); // 执行浏览器复制命令
  75. alert("已复制好,可贴粘。");
  76. }
  77.  
  78. )