index.html 軽量化作戦スレの方に書こうかとも思ったんですが,
スレの流れとそぐわない部分もあるんでこっちに書いておきます.
CSS だけじゃなくて JavaScript 部分も分離して別ファイルにするのも一案じゃないか,
と思います.これは index.html だけじゃなくて read.cgi 出力の方も同様ですね.
ついでに,JavaScript コードに次のような改訂も加えるといいような,と.
・ getCookie() のスリム化.
・ NAME, MAIL の Cookie 設定処理をサーバ側からクライアント側に移管.
これは bbs.cgi の処理削減とともに,Mozilla や Firefox 等での
文字化け問題解消ということもあります.
で,以下その改定案.
----------------------------------------------------------------------
if (!window.encodeURIComponent)
encodeURIComponent = escape;
if (!window.decodeURIComponent)
decodeURIComponent = unescape;
if (!Date.prototype.toUTCString)
Date.prototype.toUTCString = Date.prototype.toGMTString;
Date.prototype.toExpireString = function(maxAge) {
this.setTime(this.getTime() + maxAge*1000);
return this.toUTCString();
};
function getCookie(key) {
var value = new RegExp("(^|[,;]\\s*)" + key + "=\"?([^\",;\\s]+)").exec(document.cookie);
return value ? decodeURIComponent(value[2]) : "";
}
function setCookie(key, value, maxAge) {
document.cookie = key + "=\"" + encodeURIComponent(value)
+ "\"; version=1; path=/; max-age=" + maxAge
+ "; expires=\"" + new Date().toExpireString(maxAge) + '"';
}
function be(i) {
var w = window.open("
http://be.2ch.net/test/p.php?i=" + i + "&u=d:" + document.URL);
if (w) w.focus();
}
onload = function(e) {
var N = getCookie("NAME"), M = getCookie("MAIL"), i;
for (i = 0; i < document.forms.length; i++)
if (document.forms[i].FROM && document.forms[i].mail) {
document.forms[i].FROM.value = N;
document.forms[i].mail.value = M;
if (!document.forms[i].addEventListener)
document.forms[i].addEventListener = function(t, l, c) { this["on"+t] = l; };
document.forms[i].addEventListener("submit", function(e) {
setCookie("NAME", this.FROM.value, 30*24*60*60);
setCookie("MAIL", this.mail.value, 30*24*60*60);
}, false);
}
};