折角作ったので | Polyhedron

Polyhedron

速水が思った事を書いていきます。twitterを始めたのでこちらはほぼ廃墟かも。

あげてみる。javascriptの勉強がてら。
一部パクリ。完璧な出来ではないけど、一応動く。
タブ文字は無視されてるから見づらいけど、まあ許して。

if(window.location.href.indexOf("http://ほげほげ/")==0){
document.addEventListener(
"load",
function(){

var naiyou=document.createTextNode(getCookie("honbun"));
var honbun=document.createElement('textarea');
honbun.id="honbun";
honbun.rows="20";
honbun.cols="80";
honbun.appendChild(naiyou);
document.form.appendChild(honbun);

document.form[0].setAttribute("onclick", "repCookie()");

var tds=document.body.getElementsByTagName('TD');
for (i = 0; i < tds.length; i++) {
if (tds[i].getAttribute('colspan') != "2") {
continue;
}
var kami = tds[i].firstChild.getAttribute('src');
if(kami == "./img/dead2.gif") {
tds[i].firstChild.nextSibling.nextSibling.setAttribute('onclick','jusatu(this)');
}
}


},
null
);
}

function jusatu(ele) {
str = "占いの結果、"+ele.innerHTML+"さんは村人でございました";
window.document.form[3].value=str;
window.document.form[2].click();
}

function repCookie() {
var ima = document.getElementById("honbun").value;
document.cookie="; honbun="+escape(ima);
}

function getCookie(name) {
if (!name || !document.cookie) return "";
var cookies = document.cookie.split("; ");
for (var i = 0; i < cookies.length; i++) {
var str = cookies[i].split("=");
if (str[0] != name) continue;
return unescape(str[1]);
}
return "";
}