Greasy Fork is available in English.

AtCoderDevotionScript

Write contestID and problem to the clipboard

2020-11-09 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

  1. // ==UserScript==
  2. // @name AtCoderDevotionScript
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Write contestID and problem to the clipboard
  6. // @author imomo
  7. // @match https://atcoder.jp/contests/*/tasks/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. onkeydown = function(){
  12. if(event.ctrlKey&&event.keyCode==81){
  13. //問題ページのURLを取得
  14. var contestUrl = location.href;
  15. //コンテストのパスのみ切り出し
  16. var problemPass = contestUrl.substr(contestUrl.lastIndexOf("/")+1);
  17. //contestID及び問題種別を格納
  18. var contestID = problemPass.substr(0,problemPass.length - 2);
  19. var problem =problemPass.substr(-1);
  20.  
  21. // 空div 生成
  22. var tmp = document.createElement("div");
  23. // 選択用のタグ生成
  24. var pre = document.createElement('pre');
  25.  
  26. // 親要素のCSSで user-select: none だとコピーできないので書き換える
  27. pre.style.webkitUserSelect = 'auto';
  28. pre.style.userSelect = 'auto';
  29.  
  30. tmp.appendChild(pre).textContent = contestID + " " + problem;
  31.  
  32. // 要素を画面外へ
  33. var s = tmp.style;
  34. s.position = 'fixed';
  35. s.right = '200%';
  36.  
  37. // body に追加
  38. document.body.appendChild(tmp);
  39. // 要素を選択
  40. document.getSelection().selectAllChildren(tmp);
  41.  
  42. // クリップボードにコピー
  43. document.execCommand("copy");
  44.  
  45. // 要素削除
  46. document.body.removeChild(tmp);
  47. }
  48. }