LG to MD

双击即可复制洛谷md题面

  1. // ==UserScript==
  2. // @name LG to MD
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 双击即可复制洛谷md题面
  6. // @author tojunfeng & lzx
  7. // @match https://www.luogu.com.cn/problem/*
  8. // @icon https://www.luogu.com.cn/favicon.ico
  9. // @grant none
  10. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. function getJSON(url){
  15. let Pdata;
  16. $.ajax({
  17. url:url,
  18. type:"GET", //请求类型
  19. dataType:'json', //返回 JSON 数据
  20. async : false, //是否支持异步刷新,默认是true(异步)
  21. data:{ //需要提交的数据
  22. _contentOnly:23333
  23. },
  24. success:function(data){ //请求成功后的回调函数
  25. //console.log(data["currentData"]["problem"])
  26. Pdata = data["currentData"]["problem"];
  27. },
  28. error:function () { //请求失败后的回调函数
  29. //alert("服务器内部异常")
  30. console.log("服务器内部异常");
  31. }
  32. });
  33. return Pdata;
  34. }
  35.  
  36. function Core(){
  37. let url = window.location.href;
  38. console.log(url);
  39. let Pdata = getJSON(url);
  40. let Problem = "# " + Pdata["title"] + "\n";
  41. if(Pdata["background"]!="")
  42. Problem += "## 题目背景\n\n" + Pdata["background"] + "\n";
  43. if(Pdata["description"]!="")
  44. Problem += "## 题目描述\n\n" + Pdata["description"] + "\n";
  45. if(Pdata["inputFormat"]!="")
  46. Problem += "## 输入格式\n\n" + Pdata["inputFormat"] + "\n";
  47. if(Pdata["outputFormat"]!="")
  48. Problem += "## 输出格式\n\n" + Pdata["outputFormat"] + "\n";
  49. //Problem += "## 输入输出样例\n\n";
  50. $.each(Pdata["samples"],(i,val)=>{
  51. let ret = "\n";
  52. if(val[0].length >= 1 && val[0].substr(-1)=="\n"){
  53. ret = "";
  54. console.log("in");
  55. }
  56. Problem += "```input"+String(i+1)+"\n" + val[0] +ret+"```\n";
  57. ret = "\n";
  58. if(val[1].length >= 1 && val[1].substr(-1)=="\n")
  59. ret = "";
  60. Problem += "```output"+String(i+1)+"\n" + val[1] +ret+"```\n";
  61. })
  62. if(Pdata["hint"]!="")
  63. Problem += "## 说明/提示\n\n" + Pdata["hint"] + "\n";
  64. //console.log(Problem);
  65. console.log("复制成功")
  66. navigator.clipboard.writeText(Problem); //复制到剪切板
  67. //copy(Problem);
  68. //alert("dbclick");
  69. }
  70.  
  71. function creatDiv(){
  72. let div = document.createElement('div');
  73. let css = "z-index: 12001;background-color: #c9bcbcbd;color: white; position: fixed; left: 45%; right: 45%; top: 12%;";
  74. css += "height:1em; width:6em; text-align: center; padding-top: 0.25em; padding-bottom: 0.25em; border-radius: 15px;"
  75. css += "display:none"
  76. div.setAttribute("style",css);
  77. div.innerHTML = "复制成功";
  78. $("body").before(div);
  79. return div;
  80. }
  81.  
  82.  
  83. (function() {
  84. 'use strict';
  85. let icon = creatDiv();
  86. $("body").dblclick(function(){
  87. Core();
  88. $(icon).fadeIn(200);
  89. $(icon).fadeOut(1200);
  90. });
  91. })();
  92.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址