AtCoderDevotionScript

Write contestID and problem to the clipboard

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.1
// @description  Write contestID and problem to the clipboard
// @author       imomo
// @match        https://atcoder.jp/contests/*/tasks/*
// @grant        none
// ==/UserScript==

onkeydown = function(){
  if(event.ctrlKey&&event.keyCode==81){
      //問題ページのURLを取得
      var contestUrl = location.href;
      //コンテストのパスのみ切り出し
      var problemPass = contestUrl.substr(contestUrl.lastIndexOf("/")+1);
      //contestID及び問題種別を格納
      var contestID = problemPass.substr(0,problemPass.length - 2);
      var problem =problemPass.substr(-1);

      // 空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 = contestID + " " + problem;

      // 要素を画面外へ
      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);
  }
}