-
Notifications
You must be signed in to change notification settings - Fork 1
/
wakaba3.js
177 lines (152 loc) · 4.14 KB
/
wakaba3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
function get_cookie(name)
{
with(document.cookie)
{
var regexp=new RegExp("(^|;\\s+)"+name+"=(.*?)(;|$)");
var hit=regexp.exec(document.cookie);
if(hit&&hit.length>2) return unescape(hit[2]);
else return '';
}
};
function set_cookie(name,value,days)
{
if(days)
{
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else expires="";
document.cookie=name+"="+value+expires+"; path=/";
}
function get_password(name)
{
var pass=get_cookie(name);
if(pass) return pass;
var chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var pass='';
for(var i=0;i<8;i++)
{
var rnd=Math.floor(Math.random()*chars.length);
pass+=chars.substring(rnd,rnd+1);
}
return(pass);
}
function insert(text)
{
var textarea=document.forms.postform.field4;
if(textarea)
{
if(textarea.createTextRange && textarea.caretPos) // IE
{
var caretPos=textarea.caretPos;
caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==" "?text+" ":text;
}
else if(textarea.setSelectionRange) // Firefox
{
var start=textarea.selectionStart;
var end=textarea.selectionEnd;
textarea.value=textarea.value.substr(0,start)+text+textarea.value.substr(end);
textarea.setSelectionRange(start+text.length,start+text.length);
}
else
{
textarea.value+=text+" ";
}
textarea.focus();
}
}
function highlight(post)
{
var cells=document.getElementsByTagName("td");
for(var i=0;i<cells.length;i++) if(cells[i].className=="highlight") cells[i].className="reply";
var reply=document.getElementById("reply"+post);
if(reply)
{
reply.className="highlight";
/* var match=/^([^#]*)/.exec(document.location.toString());
document.location=match[1]+"#"+post;*/
return false;
}
return true;
}
function set_stylesheet(styletitle,norefresh)
{
set_cookie("wakabastyle",styletitle,365);
var links=document.getElementsByTagName("link");
var found=false;
for(var i=0;i<links.length;i++)
{
var rel=links[i].getAttribute("rel");
var title=links[i].getAttribute("title");
if(rel.indexOf("style")!=-1&&title)
{
links[i].disabled=true; // IE needs this to work. IE needs to die.
if(styletitle==title) { links[i].disabled=false; found=true; }
}
}
if(!found) set_preferred_stylesheet();
}
function set_preferred_stylesheet()
{
var links=document.getElementsByTagName("link");
for(var i=0;i<links.length;i++)
{
var rel=links[i].getAttribute("rel");
var title=links[i].getAttribute("title");
if(rel.indexOf("style")!=-1&&title) links[i].disabled=(rel.indexOf("alt")!=-1);
}
}
function get_active_stylesheet()
{
var links=document.getElementsByTagName("link");
for(var i=0;i<links.length;i++)
{
var rel=links[i].getAttribute("rel");
var title=links[i].getAttribute("title");
if(rel.indexOf("style")!=-1&&title&&!links[i].disabled) return title;
}
return null;
}
function get_preferred_stylesheet()
{
var links=document.getElementsByTagName("link");
for(var i=0;i<links.length;i++)
{
var rel=links[i].getAttribute("rel");
var title=links[i].getAttribute("title");
if(rel.indexOf("style")!=-1&&rel.indexOf("alt")==-1&&title) return title;
}
return null;
}
function set_inputs(id) { with(document.getElementById(id)) {if(!field1.value) field1.value=get_cookie("name"); if(!field2.value) field2.value=get_cookie("email"); if(!password.value) password.value=get_password("password"); } }
function set_delpass(id) { with(document.getElementById(id)) password.value=get_cookie("password"); }
function do_ban(el)
{
var reason=prompt("Give a reason for this ban:");
if(reason) document.location=el.href+"&comment="+encodeURIComponent(reason);
return false;
}
window.onunload=function(e)
{
if(style_cookie)
{
var title=get_active_stylesheet();
set_cookie(style_cookie,title,365);
}
}
window.onload=function(e)
{
var match;
if(match=/#i([0-9]+)/.exec(document.location.toString()))
if(!document.forms.postform.field4.value)
insert(">>"+match[1]);
if(match=/#([0-9]+)/.exec(document.location.toString()))
highlight(match[1]);
}
if(style_cookie)
{
var cookie=get_cookie(style_cookie);
var title=cookie?cookie:get_preferred_stylesheet();
set_stylesheet(title);
}