-
-
Save koyumeishi/09f68ee93e0982e0fefe8bfaafa44b70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SmartSubmitAtAtCoder | |
// @namespace SmartSubmitAtAtCoder | |
// @version 0.2 | |
// @description ctrl + v => submit | |
// @author koyumeishi | |
// @include http://*.contest.atcoder.jp/tasks/* | |
// @include https://*.contest.atcoder.jp/submit* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
if(window.location.pathname === "/submit"){ | |
if(window.location.hash){ | |
let code = decodeURIComponent(window.location.hash.substr(1)); | |
document.getElementsByName("source_code")[0].value = code; | |
} | |
}else{ | |
window.addEventListener("paste", function(e){ | |
let data_transfer = (e.clipboardData) || (window.clipboardData); | |
let str = data_transfer.getData("text"); | |
let submission_url; | |
let a = document.getElementsByTagName("a"); | |
//console.log(encodeURI(str)); | |
for(let i=0; i<a.length; i++){ | |
let ref = a[i].getAttribute("href"); | |
if( ref && ref.match(/\/submit\?task_id=\d*/) ){ | |
submission_url = ref; | |
} | |
} | |
submission_url += "#" + encodeURIComponent(str); | |
//console.log(submission_url); | |
window.open(submission_url, "_self"); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NoScript 系の拡張機能を入れていると、 XSS 疑惑で弾かれます。 これはソースコードをURLのフラグメント識別子( URL の # 以降 ) に埋め込んでいるためです。 ( http://distraid.co.jp/demo/tips_noscript.html のページ下部 XSS Type 0: DOM-Based Cross-site scripting を参照 )
(見ればわかりますが) 上のコードは単純に、問題文ページでペースト操作が行われたとき "提出ページURL#ソースコード" へ移動し、 #以降をデコードしてテキストエリアにセットしているだけなので、特に問題ないと思います。
^https://([\w-]+?).contest.atcoder.jp/submit
を NoScript (等)のXSS例外に入れると何も言われなくなると思います。