AtCoderDevotionScript

Write contestID and problem to the clipboard

As of 2020-11-10. See the latest version.

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

// ==UserScript==
// @name         AtCoderDevotionScript
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Write contestID and problem to the clipboard
// @author       imomo
// @include      https://atcoder.jp/contests/*/tasks/*
// @grant        none
// ==/UserScript==
//シェルスクリプト、もしくはシェルスクリプトを呼び出すコマンドを設定
var callScripts = "nq";
var copystr;
onkeydown = function(){
  if(event.ctrlKey&&event.keyCode==81){
      //問題ページのURLを取得
      var contestUrl = location.href;
      //パス毎に分割
      var problemPass = contestUrl.split("/");
      //contestID及び問題種別を格納
      var contestID = problemPass[problemPass.length - 3];
      var problem =contestUrl.substr(-1);
      if(!isNaN(problem))problem = String.fromCharCode(96 + Number(problem));

      if(callScripts != "")copystr = callScripts + " " + contestID + " " + problem;
      else copystr = contestID +" " + problem;
      // 空div 生成
      var tmp = document.createElement("div");
      // 選択用のタグ生成
      var pre = document.createElement('pre');

      // 親要素のCSSで user-select: none だとコピーできないので書き換える
      pre.style.webkitUserSelect = 'auto';
      pre.style.userSelect = 'auto';
      tmp.appendChild(pre).textContent = copystr;

      // 要素を画面外へ
      var s = tmp.style;
      s.position = 'fixed';
      s.right = '200%';

      // body に追加
      document.body.appendChild(tmp);
      // 要素を選択
      document.getSelection().selectAllChildren(tmp);

      // クリップボードにコピー
      document.execCommand("copy");

      // 要素削除
      document.body.removeChild(tmp);
      //通知
      alert("ID:" + contestID +"& problem :" + problem+" copied!!");
  }
}