This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbs.js
62 lines (60 loc) · 3.16 KB
/
bbs.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
function init(){
var forms = document.body.getElementsByTagName('form');
for(var i = 0; i < forms.length; ++i){
var preview_container = document.createElement('div');
var preview = document.createElement('div');
var post = document.createElement('div');
var preview_comment = document.createElement('div');
preview_container.className = 'preview';
preview_container.style.display = 'none';
preview.className = 'post';
post.className = 'postbody';
preview_comment.className = 'commenttext';
post.appendChild(preview_comment);
preview.appendChild(post);
preview_container.appendChild(preview);
forms[i].appendChild(preview_container);
preview_comment = forms[i].lastChild.lastChild.lastChild.lastChild;
var textarea = forms[i].getElementsByTagName('textarea')[0];
textarea.onchange = textarea.onkeyup = function(){
var comment = this.value;
var thread = this.parentNode.parentNode.thread.value;
var script_name = this.parentNode.parentNode.action;
this.parentNode.parentNode.lastChild.style.display = comment ? 'block' : 'none';
var commenttext = document.createElement('div');
comment = format_comment(clean_string(comment), thread, script_name);
this.parentNode.parentNode.lastChild.lastChild.lastChild.lastChild.innerHTML = comment;
return true;
}
}
function clean_string(str){
str = str.replace(/&/g, '&');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
str = str.replace(/"/g, '"');
str = str.replace(/'/g, ''');
str = str.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x80-\x84]/g,'');
str = str.replace(/[\ud800-\udfff]/g,'');
str = str.replace(/[\u202a-\u202e]/g,'');
str = str.replace(/[\ufdd0-\ufdef\ufffe\uffff]/g,'');
return str;
}
function format_comment(text, thread, script_name){
text = text.replace(/\r\n/g, '\n');
text = text.replace(/\r/g, '\n');
text = text.replace(/((http|https|ftp|mailto|nntp):[^\s<>"]*?)((\s|<|>|"|\.|\)|\]|!|\?|,|,|")*([\s<>"]|$))/g, '<a href="$1" rel="nofollow">$1</a>$3');
text = text.replace(/>>([0-9,\-]+)/g, '<a href="' + script_name + '/' + thread + '/$1">>>$1</a>');
text = text.replace(/^(>.*)$/mg, '<blockquote><p>$1</p></blockquote>');
text = text.replace(/^\u3000(.*)$/mg, '<p lang="ja">$1</p>');
text = text.replace(/^ (.*)$/mg, '<code>$1</code>');
text = text.replace(/^spoiler:(.*)$/mg, '<div class="spoiler"><input type="button" class="spoilerbutton" value="spoiler" onclick="this.parentNode.getElementsByTagName(\'div\')[0].style.display=\'block\';this.style.display=\'none\'" \/><div class="spoilertext">$1<\/div><\/div>');
text = text.replace(/<\/p><\/blockquote>\n<blockquote><p>/g, '\n');
text = text.replace(/<\/p>\n<p lang="ja">/g, '\n');
text = text.replace(/<\/code>\n<code>/g, '\n');
text = text.replace(/<\/div><\/div>\n<div class="spoiler"><input type="button" class="spoilerbutton" value="spoiler" onclick="this.parentNode.getElementsByTagName('div')[0].style.display='block';this.style.display='none'" \/><div class="spoilertext">/g, '\n');
text = text.replace(/(<\/(?:blockquote|p)>)\n/g, '$1');
text = text.replace(/\n(<blockquote)/g, '$1');
text = text.replace(/\n/g, '<br />');
return text;
}
}