1
+ // These could be edited in the Options page.
2
+ // When it gets built.
3
+ var AllowQuoteButton = 1 ;
4
+ var AllowCodeizeButton = 1 ;
5
+ var AllowQuoteSpoilers = 1 ;
6
+ var AllowCodeSpoilers = 1 ;
7
+ var IsEditablePage = 0 ;
8
+
9
+ var DefQuoteOpen = 1 ;
10
+ var DefCodeOpen = 0 ;
11
+
12
+ var DefQuoteSize = "20px" ;
13
+ var DefQuoteExtSize = "35px" ;
14
+ var DefCodeSize = "20px" ;
15
+
16
+ function DefQuoteState ( ) { return DefQuoteOpen ?"shownicon" :"hiddenicon" ; }
17
+ function DefCodeState ( ) { return DefCodeOpen ?"shownicon" :"hiddenicon" ; }
18
+ function DefQuoteHgt ( sh ) { return DefQuoteOpen ?"auto" :sh ; }
19
+ function DefCodeHgt ( sh ) { return DefCodeOpen ?"auto" :sh ; }
20
+ function DefQuoteClass ( ) { return DefQuoteOpen ?"ofshow" :"ofhide" ; }
21
+ function DefCodeClass ( ) { return DefCodeOpen ?"ofshow" :"ofhide" ; }
22
+
23
+ function childOf ( c , p ) { while ( ( c = c . parentNode ) && c !== p ) ; return ! ! c }
24
+
25
+ function toggledisplay ( target , icon , tinysize )
26
+ {
27
+ if ( target . style . height == "auto" )
28
+ {
29
+ target . style . height = tinysize ;
30
+ target . className = "ofhide" ;
31
+ icon . className = "C_ico hiddenicon" ;
32
+ }
33
+ else
34
+ {
35
+ target . style . height = "auto" ;
36
+ target . className = "ofshow" ;
37
+ icon . className = "C_ico shownicon" ;
38
+ }
39
+ }
40
+
41
+ function forEachItem ( Item , IsCode , IsReplyable )
42
+ {
43
+ if ( IsCode && AllowCodeSpoilers )
44
+ {
45
+ var newdiv = document . createElement ( 'div' ) ;
46
+ newdiv . style . height = DefCodeHgt ( DefCodeSize ) ;
47
+ newdiv . className = DefCodeClass ( ) ;
48
+ var newa = document . createElement ( 'a' ) ;
49
+ var newspan = document . createElement ( 'span' ) ;
50
+ newspan . className = 'C_ico ' + DefCodeState ( ) ;
51
+ newa . appendChild ( newspan ) ;
52
+ newa . onclick = function ( ) { toggledisplay ( this . parentNode , newspan , DefCodeSize ) ; return false ; }
53
+ newdiv . appendChild ( newa ) ;
54
+
55
+ //codeonly
56
+ var codespan = document . createElement ( 'span' ) ;
57
+ codespan . className = 'codeSpan' ;
58
+ codespan . innerHTML = 'Code' ;
59
+ newdiv . appendChild ( codespan ) ;
60
+ //endcodeonly
61
+
62
+ newdiv . appendChild ( Item . cloneNode ( true ) ) ;
63
+ Item . parentNode . replaceChild ( newdiv , Item ) ;
64
+ }
65
+ if ( ! IsCode && AllowQuoteSpoilers )
66
+ {
67
+ var itemshortsize = DefQuoteSize ;
68
+ if ( Item . getElementsByClassName ( 'qh' ) . length != 0 )
69
+ itemshortsize = DefQuoteExtSize ;
70
+
71
+ var newdiv = document . createElement ( 'div' ) ;
72
+ newdiv . style . height = DefQuoteHgt ( itemshortsize ) ;
73
+ newdiv . className = DefQuoteClass ( ) ;
74
+ var newa = document . createElement ( 'a' ) ;
75
+ var newspan = document . createElement ( 'span' ) ;
76
+ newspan . className = 'C_ico ' + DefQuoteState ( ) ;
77
+ newa . appendChild ( newspan ) ;
78
+ newa . onclick = function ( ) { toggledisplay ( this . parentNode , newspan , DefQuoteSize ) ; return false ; }
79
+ newdiv . appendChild ( newa ) ;
80
+ newdiv . appendChild ( Item . cloneNode ( true ) ) ;
81
+ Item . parentNode . replaceChild ( newdiv , Item ) ;
82
+ }
83
+ }
84
+ function forEachPost_Buttons ( ButtonStorage , PostID , IsReplyable )
85
+ {
86
+ var Result = '' ;
87
+ if ( AllowCodeizeButton )
88
+ {
89
+ Result += '<span><a href="javascript:post' ;
90
+ Result += PostID ;
91
+ Result += '.showascode()" class="C_btn narrow" title="Show as Code"><b class="C_ico ascode"></b>Code-ize</a></span>' ;
92
+ }
93
+ if ( AllowQuoteButton && IsReplyable )
94
+ {
95
+ Result += '<span><a href="javascript:post' ;
96
+ Result += PostID ;
97
+ Result += '.quote()" class="C_btn narrow" title="Quote post"><b class="C_ico postreply"></b>Quote</a></span>' ;
98
+ }
99
+ if ( Result != '' )
100
+ {
101
+ Result += ButtonStorage . innerHTML ,
102
+ ButtonStorage . innerHTML = Result ;
103
+ }
104
+ }
105
+
106
+ do {
107
+ var CanReply = 1 ;
108
+ if ( ! document . getElementsByClassName ( 'postreply' ) . length )
109
+ CanReply = 0 ;
110
+
111
+ var currenttopic = document . location . pathname ;
112
+ var occ = 0 ;
113
+ var ctbegin = 0 ;
114
+ var ctend = 0 ;
115
+ for ( var zix = 0 ; zix < currenttopic . length ; zix ++ )
116
+ {
117
+ if ( currenttopic [ zix ] == '/'
118
+ || currenttopic [ zix ] == '\\' )
119
+ {
120
+ occ ++ ;
121
+ if ( occ == 3 )
122
+ {
123
+ ctbegin = zix + 1 ;
124
+ }
125
+ else if ( occ == 4 )
126
+ {
127
+ ctend = zix ;
128
+ break ;
129
+ }
130
+ }
131
+ }
132
+ if ( ctbegin == 0 || ctend == 0 )
133
+ break ;
134
+ currenttopic = currenttopic . substring ( ctbegin , ctend ) ;
135
+ currenttopic = parseInt ( currenttopic ) ;
136
+ if ( isNaN ( currenttopic ) )
137
+ {
138
+ console . log ( "Could not parse topic ID." ) ;
139
+ break ;
140
+ }
141
+
142
+ var x = document . getElementById ( 'CH_PostList' ) ;
143
+ if ( x ) {
144
+ var y = x . getElementsByTagName ( 'div' ) ;
145
+ if ( y . length )
146
+ {
147
+ var spanlist ;
148
+ var postlist = [ ] ;
149
+ var currItem ;
150
+ for ( var zix = 0 ; currItem = y [ zix ] ; zix ++ )
151
+ {
152
+ if ( ( currItem . id . indexOf ( 'msg' ) == 0 ) &&
153
+ ( ! isNaN ( parseInt ( currItem . id . substr ( 3 ) , 10 ) ) ) )
154
+ {
155
+ spanlist = currItem . getElementsByTagName ( 'span' ) ;
156
+ for ( var ziy = 0 ; ziy < spanlist . length ; ziy ++ )
157
+ {
158
+ if ( ( spanlist [ ziy ] . className == 'dbtn' ) &&
159
+ ( spanlist [ ziy ] . id . indexOf ( 'CH_btn' ) == 0 ) &&
160
+ ( ! isNaN ( parseInt ( spanlist [ ziy ] . id . substr ( 6 ) ) ) )
161
+ )
162
+ {
163
+ var postid = parseInt ( spanlist [ ziy ] . id . substr ( 6 ) ) ;
164
+ if ( isNaN ( postid ) )
165
+ continue ;
166
+ IsEditablePage = 1 ;
167
+ forEachPost_Buttons ( spanlist [ ziy ] , postid , CanReply ) ;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ else
174
+ {
175
+ console . log ( "No posts in topic." ) ;
176
+ }
177
+ }
178
+ else
179
+ {
180
+ console . log ( "No postlist in topic." ) ;
181
+ }
182
+ x = document . getElementsByClassName ( 'quote' ) ;
183
+ if ( x ) {
184
+ var currItem ;
185
+ for ( var zix = 0 ; currItem = x [ zix ] ; zix ++ )
186
+ {
187
+ forEachItem ( currItem , 0 , CanReply ) ;
188
+ IsEditablePage = 1 ;
189
+ }
190
+ }
191
+ else
192
+ {
193
+ console . log ( "No quotes in this topic." ) ;
194
+ }
195
+ x = document . getElementsByClassName ( 'snippet' ) ;
196
+ if ( x ) {
197
+ var currItem ;
198
+ for ( var zix = 0 ; currItem = x [ zix ] ; zix ++ )
199
+ {
200
+ forEachItem ( currItem , 1 , CanReply ) ;
201
+ IsEditablePage = 1 ;
202
+ }
203
+ }
204
+ else
205
+ {
206
+ console . log ( "No sources in this topic." ) ;
207
+ }
208
+ } while ( 0 ) ;
209
+
210
+ if ( IsEditablePage != 0 )
211
+ {
212
+ var formpreview = document . createElement ( 'form' ) ;
213
+ var forminput_w = document . createElement ( 'input' ) ;
214
+ var forminput_content = document . createElement ( 'input' ) ;
215
+
216
+ forminput_w . type = 'hidden' ;
217
+ forminput_w . name = 'w' ;
218
+ forminput_w . value = 'preview' ;
219
+
220
+ forminput_content . type = 'hidden' ;
221
+ forminput_content . name = 'content' ;
222
+ forminput_content . id = 'show_as_code_id' ;
223
+
224
+ formpreview . appendChild ( forminput_w ) ;
225
+ formpreview . appendChild ( forminput_content ) ;
226
+ formpreview . id = 'run_show_as_code_id' ;
227
+ formpreview . action = '/forum/post.cgi' ;
228
+ formpreview . target = 'previewing' ;
229
+ formpreview . method = 'post' ;
230
+ formpreview . name = 'prevthread' ;
231
+ document . documentElement . appendChild ( formpreview ) ;
232
+
233
+ // http://www.cplusplus.com/forum/post.cgi?w=text&p= #ID
234
+ // ---> Formatted text
235
+ var js_common_code = 'function getpostinternal(x){var result="";var Network=new XMLHttpRequest();Network.onreadystatechange=function(){if(Network.readyState==4&&Network.status==200){result=Network.responseText;}else result="error";};Network.open("GET","http://www.cplusplus.com/forum/post.cgi\?w=text\&p="+x,false);Network.send();return result;}' ;
236
+ var js_quote_code = 'for_Post.prototype.quote = function(){var result=getpostinternal(this.postid);if(result!="error"){var reply=document.getElementById("CH_reply").getElementsByTagName("a");if(reply[0].href.indexOf("javascript:thread")==0){eval(reply[0].href.substr(11)+";")}reply=document.getElementById("CH_reply").getElementsByTagName("textarea");var replier=this.el.innerHTML;var begin=replier.indexOf("<b>");var end=replier.indexOf("</b>");if(begin>0&&end>0)replier="="+replier.substring(begin+3,end);else replier="";reply[0].value="[quote";reply[0].value+=replier;reply[0].value+="]"+result+"[/quote]";}};' ;
237
+ var js_codeize_code = 'for_Post.prototype.showascode = function(){var result=getpostinternal(this.postid);if(result!="error"){var codeshw=document.getElementById("show_as_code_id");var sendcode=document.getElementById("run_show_as_code_id");if(codeshw&&sendcode){codeshw.value="[code]"+result+"[/code]";sendcode.submit();}}};' ;
238
+ var s = document . createElement ( 'script' ) ;
239
+ s . textContent = js_common_code + js_quote_code + js_codeize_code ;
240
+ document . documentElement . appendChild ( s ) ;
241
+ }
242
+
243
+ // dev'ed by SGH. Ideas by LB. Uploading fee provided by BHXSpecter.
0 commit comments