atcoder_collect_all_examples

入出力例をまとめた項目を生成

当前为 2019-07-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name atcoder_collect_all_examples
  3. // @namespace https://github.com/Haar-you
  4. // @version 1.0
  5. // @description 入出力例をまとめた項目を生成
  6. // @author Haar-you
  7. // @match https://atcoder.jp/contests/*
  8. // @grant none
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. $(function(){
  13. 'use strict';
  14. this.$ = this.jQuery = jQuery.noConflict(true);
  15.  
  16. const part_iostyle = $($("#task-statement .io-style")[0]);
  17. const part_example = $("#task-statement .part");
  18.  
  19. const text_input =
  20. part_example.filter(function(i,elem){
  21. const s = $($(elem).find("h3")[0]).text();
  22. return /入力例/.test(s);
  23. }).map(function(i,elem){
  24. return $($(elem).find("pre")[0]).text();
  25. }).get().join("\n");
  26.  
  27. const text_output =
  28. part_example.filter(function(i,elem){
  29. const s = $($(elem).find("h3")[0]).text();
  30. return /出力例/.test(s);
  31. }).map(function(i,elem){
  32. return $($(elem).find("pre")[0]).text();
  33. }).get().join("\n");
  34.  
  35. const pre_all_inputs = $("<pre></pre>", {
  36. text: text_input
  37. });
  38. const pre_all_outputs = $("<pre></pre>", {
  39. text: text_output
  40. });
  41.  
  42. function copyExample(elem){
  43. window.getSelection().removeAllRanges();
  44. var range = document.createRange();
  45. range.selectNode(elem);
  46. window.getSelection().addRange(range);
  47. document.execCommand('copy');
  48.  
  49. $(this).tooltip("show");
  50. var _this = this;
  51. setTimeout(function() {
  52. $(_this).tooltip('hide');
  53. }, 800);
  54.  
  55. window.getSelection().removeAllRanges();
  56. }
  57.  
  58. part_iostyle.after(
  59. $("<div></div>", {
  60. "class": "part"
  61. }).append(
  62. $("<section></section>").append(
  63. $("<h3></h3>", {text: "全入出力例 "}).append(
  64. $("<span></span>", {
  65. "class": "btn btn-default btn-sm",
  66. text: "Copy input",
  67. "data-toggle": "tooltip",
  68. "data-trigger": "manual",
  69. "data-title": "Copied!",
  70. on:{
  71. click: function(){
  72. copyExample.call(this, pre_all_inputs.get(0));
  73. }
  74. }
  75. }),
  76. $("<span></span>", {
  77. "class": "btn btn-default btn-sm",
  78. text: "Copy output",
  79. "data-toggle": "tooltip",
  80. "data-trigger": "manual",
  81. "data-title": "Copied!",
  82. on:{
  83. click: function(){
  84. copyExample.call(this, pre_all_outputs.get(0));
  85. }
  86. }
  87. })
  88. ),
  89. pre_all_inputs,
  90. pre_all_outputs
  91. )
  92. )
  93. );
  94. });

QingJ © 2025

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