AtCoderDevotionScript

Write contestID and problem to the clipboard

Tính đến 10-11-2020. Xem phiên bản mới nhất.

  1. // ==UserScript==
  2. // @name AtCoderDevotionScript
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Write contestID and problem to the clipboard
  6. // @author imomo
  7. // @include https://atcoder.jp/contests/*/tasks/*
  8. // @grant none
  9. // ==/UserScript==
  10. //シェルスクリプト、もしくはシェルスクリプトを呼び出すコマンドを設定
  11. var callScripts = "nq";
  12. var copystr;
  13. onkeydown = function(){
  14. if(event.ctrlKey&&event.keyCode==81){
  15. //問題ページのURLを取得
  16. var contestUrl = location.href;
  17. //パス毎に分割
  18. var problemPass = contestUrl.split("/");
  19. //contestID及び問題種別を格納
  20. var contestID = problemPass[problemPass.length - 3];
  21. var problem =contestUrl.substr(-1);
  22. if(!isNaN(problem))problem = String.fromCharCode(96 + Number(problem));
  23.  
  24. if(callScripts != "")copystr = callScripts + " " + contestID + " " + problem;
  25. else copystr = contestID +" " + problem;
  26. // 空div 生成
  27. var tmp = document.createElement("div");
  28. // 選択用のタグ生成
  29. var pre = document.createElement('pre');
  30.  
  31. // 親要素のCSSで user-select: none だとコピーできないので書き換える
  32. pre.style.webkitUserSelect = 'auto';
  33. pre.style.userSelect = 'auto';
  34. tmp.appendChild(pre).textContent = copystr;
  35.  
  36. // 要素を画面外へ
  37. var s = tmp.style;
  38. s.position = 'fixed';
  39. s.right = '200%';
  40.  
  41. // body に追加
  42. document.body.appendChild(tmp);
  43. // 要素を選択
  44. document.getSelection().selectAllChildren(tmp);
  45.  
  46. // クリップボードにコピー
  47. document.execCommand("copy");
  48.  
  49. // 要素削除
  50. document.body.removeChild(tmp);
  51. //通知
  52. alert("ID:" + contestID +"& problem :" + problem+" copied!!");
  53. }
  54. }