AtCoderYesNoOutput

Write the output string when true and false to the clipboard

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!)

  1. // ==UserScript==
  2. // @name AtCoderYesNoOutput
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Write the output string when true and false to the clipboard
  6. // @author imomo
  7. // @include https://atcoder.jp/contests/*/tasks/*
  8. // @grant none
  9. // ==/UserScript==
  10. /*ユーザー設定項目*/
  11. //真偽値を入れる変数名を入力
  12. var boolval = "ans"
  13.  
  14. var cpp = "cout << (("+boolval+")?\"[first]\":\"[second]\") << endl;"
  15. var python = "print(\"[first]\" if "+boolval+" else \"[second]\")";
  16.  
  17. //使用言語に合わせてc++はcpp,Pythonはpythonと入力 エスケープ処理などが分かる方はオリジナルを入力しても構いません
  18. //オリジナルの場合、1番目の文字列を[first]、2つ目の文字列を[second]としてください。
  19. var outputtext = cpp;
  20.  
  21. /*設定項目終わり*/
  22.  
  23. onkeydown = function(){
  24. const regex = /[^A-Za-z!:()]/g;
  25. if((event.ctrlKey || event.metaKey) &&event.shiftKey){
  26. var selObj = window.getSelection().toString();
  27. console.log(selObj);
  28. var obj=[];
  29. if (selObj.indexOf(',') != -1)obj = selObj.split(',');
  30. else if(selObj.indexOf(',') != -1)obj = selObj.split(',');
  31. else obj = selObj.split('、');
  32. var first = obj[0].replace(regex,'');
  33. var second = obj[1].replace(regex,'');
  34. outputtext = outputtext.replace('[first]',first);
  35. outputtext = outputtext.replace('[second]',second);
  36.  
  37. // 空div 生成
  38. var tmp = document.createElement("div");
  39. // 選択用のタグ生成
  40. var pre = document.createElement('pre');
  41.  
  42. // 親要素のCSSで user-select: none だとコピーできないので書き換える
  43. pre.style.webkitUserSelect = 'auto';
  44. pre.style.userSelect = 'auto';
  45. tmp.appendChild(pre).textContent = outputtext;
  46.  
  47. // 要素を画面外へ
  48. var s = tmp.style;
  49. s.position = 'fixed';
  50. s.right = '200%';
  51.  
  52. // body に追加
  53. document.body.appendChild(tmp);
  54. // 要素を選択
  55. document.getSelection().selectAllChildren(tmp);
  56.  
  57. // クリップボードにコピー
  58. document.execCommand("copy");
  59.  
  60. // 要素削除
  61. document.body.removeChild(tmp);
  62. }
  63. }