Created
September 12, 2011 14:16
-
-
Save atomer/1211356 to your computer and use it in GitHub Desktop.
GDD2011 DevQuiz Web Game
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 GDD2011 Answer Web Game | |
// @namespace http://www.atomer.sakuran.ne.jp | |
// @description GDD2011の神経衰弱自動解答スクリプト | |
// @include http://gdd-2011-quiz-japan.appspot.com/webgame/problem | |
// @version 0.1 | |
// ==/UserScript== | |
var s = document.querySelectorAll("script")[2].innerHTML, a, cards; | |
s = s.split("\n").join(""); | |
a = s.replace(/^.+conc.setup\((\[.+\])\);.+$/, "$1"), | |
cards = JSON.parse(a); | |
if (typeof cards === "object") { | |
conc_hack(cards); | |
} else { | |
alert("parse error"); | |
} | |
function $(q) { | |
return document.querySelector(q); | |
} | |
function conc_hack(cards) { | |
var answer = [], len = cards.length, i, j; | |
for (i = 0; i < len; i++) { | |
check: for (j = i + 1; j < len; j++) { | |
if (answer[i] === undefined && cards[i] === cards[j]) { | |
answer[i] = j; | |
answer[j] = i; | |
break check; | |
} | |
} | |
} | |
var submit = function(answer) { | |
$("#answer").value = answer.join(","); | |
$("#solve").submit(); | |
}; | |
submit(answer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment