-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkiramoji.js
272 lines (225 loc) · 6.2 KB
/
kiramoji.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
function require_script_version(v)
{
if(v!="3.a") alert("The board has been upgraded. You need to force a reload in your browser to complete the update.\nThis is usually done by holding down Shift and pressing the reload button.");
}
function show(id)
{
var style=document.getElementById(id).style;
var status=document.getElementById("link"+id);
if(style.display) {
style.display="";
status.setAttribute("aria-expanded",true);
} else {
style.display="none";
status.setAttribute("aria-expanded",false);
}
}
function insert(text,thread)
{
var textarea=document.getElementById("postform"+thread).comment;
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 w_insert(text,link)
{
if(document.body.className=="mainpage") document.location=link+"#i"+text;
else insert(text,"");
}
function size_field(id,rows) { document.getElementById(id).comment.setAttribute("rows",rows); }
function delete_post(thread,post,file)
{
if(confirm("Are you sure you want to delete reply "+post+"?"))
{
var fileonly=false;
var script=document.forms[0].action;
var password=document.forms[0].password.value;
if(file) fileonly=confirm("Leave the reply text and delete the only file?");
document.location=script
+"?task=delete"
+"&delete="+thread+","+post
+"&password="+password
+"&fileonly="+(fileonly?"1":"0");
}
}
function preview_post(formid,thread)
{
var form=document.getElementById(formid);
var preview=document.getElementById("preview"+thread);
if(!form||!preview) return;
preview.style.display="";
preview.innerHTML="<em>Loading...</em>";
var text;
text="task=preview";
text+="&comment="+encodeURIComponent(form.comment.value);
text+="&markup="+encodeURIComponent(form.markup.value);
if(thread) text+="&thread="+thread;
var xmlhttp=get_xmlhttp();
xmlhttp.open("POST",self);
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4) preview.innerHTML=xmlhttp.responseText;
}
if(is_ie()||xmlhttp.setRequestHeader) xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(text);
form.comment.focus();
}
function get_xmlhttp()
{
var xmlhttp;
try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e1)
{
try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e1) { xmlhttp=null; }
}
if(!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
return(xmlhttp);
}
function is_ie()
{
return(document.all&&!document.opera);
}
function set_new_inputs(id)
{
var el=document.getElementById(id);
if(!el||!el.link) return;
if(!el.field_a.value) el.field_a.value=get_cookie("name");
if(!el.field_b.value) el.field_b.value=get_cookie("link");
if(!el.password.value) el.password.value=get_password("password");
if(el.markup&&!el.comment.value&&get_cookie("markup")) el.markup.value=get_cookie("markup");
select_markup(el.markup);
}
function set_delpass(id)
{
with(document.getElementById(id)) password.value=get_cookie("password");
}
function make_password()
{
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 get_password(name)
{
var pass=get_cookie(name);
if(pass) return pass;
return make_password();
}
function select_markup(sel)
{
if(!window.markup_descriptions) return;
var el=sel;
while(el=el.nextSibling) if(el.nodeName.toLowerCase()=="small") break;
if(el) el.innerHTML=markup_descriptions[sel.value];
}
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 set_stylesheet(styletitle)
{
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;
}
}
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;
}
window.onunload=function(e)
{
if(style_cookie)
{
var title=get_active_stylesheet();
set_cookie(style_cookie,title,365);
}
}
window.onload=function(e)
{
if(match=/#i(.+)/.exec(document.location.toString()))
if(!document.getElementById("postform").comment.value)
insert(unescape(match[1]),"");
}
if(style_cookie)
{
var cookie=get_cookie(style_cookie);
var title=cookie?cookie:get_preferred_stylesheet();
set_stylesheet(title);
}
var captcha_key=make_password();