Write contestID and problem to the clipboard
当前为
// ==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);
}
}