UnTaint - Wiki Improvement Script

Greasemonkey script that improves the Wikifoundry wiki interface and integrates TinyEditor. For Firefox and Chrome.

  1. // ==UserScript==
  2. // @name UnTaint - Wiki Improvement Script
  3. // @namespace http://hawaiifive-0.wikifoundry.com/
  4. // @description Greasemonkey script that improves the Wikifoundry wiki interface and integrates TinyEditor. For Firefox and Chrome.
  5. // @version 1.6.ffc.005
  6. // @copyright 2014+, SurfingEagle
  7. // @grant GM_addStyle
  8. // @include http://*.wikifoundry.com/thread*
  9. // @include http://*.wikifoundry.com/forum/*
  10. // @include http://*.wikifoundry.com/forum
  11. // @include http://*.wikifoundry.com/account/*/thread/*
  12. // @include http://*.wikifoundry.com/photo/*/thread/*
  13. // @include http://*.wikifoundry.com/video/*/thread/*
  14. // @include http://www.sarahconnorfans.com/thread*
  15. // @include http://www.sarahconnorfans.com/forum/*
  16. // @include http://www.sarahconnorfans.com/forum
  17. // @include http://www.sarahconnorfans.com/account/*/thread/*
  18. // @include http://www.sarahconnorfans.com/photo/*/thread/*
  19. // @include http://www.sarahconnorfans.com/video/*/thread/*
  20. // @include
  21. http://www.marsmissionwiki.wikifoundry.com/thread*
  22. // @include http://www.marsmissionwiki.wikifoundry.com/forum/*
  23. // @include http://www.marsmissionwiki.wikifoundry.com/forum
  24. // @include http://www.marsmissionwiki.wikifoundry.com/account/*/thread/*
  25. // @include http://www.marsmissionwiki.wikifoundry.com/photo/*/thread/*
  26. // @include http://www.marsmissionwiki.wikifoundry.com/video/*/thread/*
  27. // @include http://www.vampirediariesfanwiki.com/thread*
  28. // @include http://www.vampirediariesfanwiki.com/forum/*
  29. // @include http://www.vampirediariesfanwiki.com/forum
  30. // @include http://www.vampirediariesfanwiki.com/account/*/thread/*
  31. // @include http://www.vampirediariesfanwiki.com/photo/*/thread/*
  32. // @include http://www.vampirediariesfanwiki.com/video/*/thread/*
  33. // @include http://www.thegreysanatomywiki.com/thread*
  34. // @include http://www.thegreysanatomywiki.com/forum/*
  35. // @include http://www.thegreysanatomywiki.com/forum
  36. // @include http://www.thegreysanatomywiki.com/account/*/thread/*
  37. // @include http://www.thegreysanatomywiki.com/photo/*/thread/*
  38. // @include http://www.thegreysanatomywiki.com/video/*/thread/*
  39. // @include http://www.warriorcatclans2.com/thread*
  40. // @include http://www.warriorcatclans2.com/forum/*
  41. // @include http://www.warriorcatclans2.com/forum
  42. // @include http://www.warriorcatclans2.com/account/*/thread/*
  43. // @include http://www.warriorcatclans2.com/photo/*/thread/*
  44. // @include http://www.warriorcatclans2.com/video/*/thread/*
  45. // @include http://www.zombieprepwiki.com/thread*
  46. // @include http://www.zombieprepwiki.com/forum/*
  47. // @include http://www.zombieprepwiki.com/forum
  48. // @include http://www.zombieprepwiki.com/account/*/thread/*
  49. // @include http://www.zombieprepwiki.com/photo/*/thread/*
  50. // @include http://www.zombieprepwiki.com/video/*/thread/*
  51. // ==/UserScript==
  52. // =============================================================================
  53. // Don't edit past here unless you know what you're doing.
  54. // *** Original namespace and project: http://files.randomresources.org/projects/untaint
  55. // *** Original description: Reduces the taint. Thanks to the inhabitants of the tsccwiki. Credits: toasty2 and Gu1.
  56. // TinyEditor integration and script adaptation to FF 4+ and Chrome 11+ by: SurfingEagle
  57. // Additional contributions: I.John
  58. // This version is adapted to work with GreaseMonkey 0.9+, Firefox 4+, and Chrome 11+ Not currently tested in IE
  59. // TinyEditor home http://www.scriptiny.com/2010/02/javascript-wysiwyg-editor/
  60.  
  61. // Convenient functions
  62. Array.prototype.contains = function(obj){var i = this.length;while(i--){if (this[i] === obj) {return true;}} return false;}
  63.  
  64. // SE: switch to using localStorage
  65. function putSetting (name, val)
  66. {
  67. if (name && 'localStorage' in window && window['localStorage'] !== null)
  68. window.localStorage[name] = val;
  69. }
  70.  
  71. function getSetting (name, defval)
  72. {
  73. var val = null;
  74. if (name && 'localStorage' in window && window['localStorage'] !== null)
  75. val = window.localStorage[name];
  76. if (val)
  77. return val;
  78. else
  79. return defval;
  80. }
  81.  
  82. function deleteSetting (name)
  83. {
  84. if (name && 'localStorage' in window && window['localStorage'] !== null)
  85. window.localStorage.removeItem(name);
  86. }
  87.  
  88. function emptySetting (name)
  89. {
  90. if (name && 'localStorage' in window && window['localStorage'] !== null)
  91. window.localStorage[name] = '';
  92. }
  93.  
  94. // http://james.padolsey.com/javascript/get-document-height-cross-browser/
  95. function getDocHeight() {
  96. var D = document;
  97. return Math.max(
  98. D.body.scrollHeight, D.documentElement.scrollHeight,
  99. D.body.offsetHeight, D.documentElement.offsetHeight,
  100. D.body.clientHeight, D.documentElement.clientHeight
  101. );
  102. }
  103.  
  104. /*
  105. Developed by Robert Nyman, http://www.robertnyman.com
  106. Code/licensing: http://code.google.com/p/getelementsbyclassname/
  107. */
  108. var getElementsByClassName = function (className, tag, elm){
  109. if (document.getElementsByClassName) {
  110. getElementsByClassName = function (className, tag, elm) {
  111. elm = elm || document;
  112. var elements = elm.getElementsByClassName(className),
  113. nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
  114. returnElements = [],
  115. current;
  116. for(var i=0, il=elements.length; i<il; i+=1){
  117. current = elements[i];
  118. if(!nodeName || nodeName.test(current.nodeName)) {
  119. returnElements.push(current);
  120. }
  121. }
  122. return returnElements;
  123. };
  124. }
  125. else if (document.evaluate) {
  126. getElementsByClassName = function (className, tag, elm) {
  127. tag = tag || "*";
  128. elm = elm || document;
  129. var classes = className.split(" "),
  130. classesToCheck = "",
  131. xhtmlNamespace = "http://www.w3.org/1999/xhtml",
  132. namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
  133. returnElements = [],
  134. elements,
  135. node;
  136. for(var j=0, jl=classes.length; j<jl; j+=1){
  137. classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
  138. }
  139. try {
  140. elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
  141. }
  142. catch (e) {
  143. elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
  144. }
  145. while ((node = elements.iterateNext())) {
  146. returnElements.push(node);
  147. }
  148. return returnElements;
  149. };
  150. }
  151. else {
  152. getElementsByClassName = function (className, tag, elm) {
  153. tag = tag || "*";
  154. elm = elm || document;
  155. var classes = className.split(" "),
  156. classesToCheck = [],
  157. elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
  158. current,
  159. returnElements = [],
  160. match;
  161. for(var k=0, kl=classes.length; k<kl; k+=1){
  162. classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
  163. }
  164. for(var l=0, ll=elements.length; l<ll; l+=1){
  165. current = elements[l];
  166. match = false;
  167. for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
  168. match = classesToCheck[m].test(current.className);
  169. if (!match) {
  170. break;
  171. }
  172. }
  173. if (match) {
  174. returnElements.push(current);
  175. }
  176. }
  177. return returnElements;
  178. };
  179. }
  180. return getElementsByClassName(className, tag, elm);
  181. };
  182.  
  183. // following block handles returning to end of thread after a new post
  184. try {
  185. if (window['sessionStorage'] !== null)
  186. {
  187. var added_post = window.sessionStorage['added_post'];
  188. if (getSetting('return_on_post', 'true') == 'true' && added_post.length > 0)
  189. {
  190. if (added_post == 'scroll_down')
  191. {
  192. window.scroll(0, getDocHeight());
  193. window.sessionStorage['added_post'] = '';
  194. }
  195. else if (added_post == 'jump_end_of_thread')
  196. {
  197. var p = getElementsByClassName('paging')[0];
  198. if (p)
  199. {
  200. p = p.lastChild.previousSibling;
  201. while (p)
  202. {
  203. if (p.nodeType == 1 && p.innerHTML != 'Next' && (p.innerHTML == 'Last' || Number(p.innerHTML) <= 5))
  204. {
  205. window.sessionStorage['added_post'] = 'scroll_down';
  206. window.location.href = p.href;
  207. break;
  208. }
  209. p = p.previousSibling;
  210. }
  211. if (!p) window.sessionStorage['added_post'] = '';
  212. }
  213. else
  214. window.sessionStorage['added_post'] = '';
  215. }
  216. else
  217. window.sessionStorage['added_post'] = '';
  218. } // end if
  219. } // end if
  220. }
  221. catch (e) {
  222. if (window['sessionStorage'] !== null) window.sessionStorage['added_post'] = '';
  223. }
  224.  
  225. // Get Configuration (or set defaults)
  226. var ui_avatar_w = getSetting('ui_avatar_w', '50');
  227. var ui_hide_rater = (getSetting('ui_hide_rater', 'true') == 'true');
  228. var ui_user_filter = getSetting('ui_user_filter', 'ExampleUser1,ExampleUser2');
  229. var refresh_threadlist = Number(getSetting('refresh_threadlist', '0'));
  230. // newest values
  231. var ui_auto_tinyeditor = (getSetting('ui_auto_tinyeditor', 'true') == 'true');
  232. var ui_show_leftcolumn = (getSetting('ui_show_leftcolumn', 'false') == 'true');
  233. var ui_default_post_font = getSetting('ui_default_post_font', '12px Arial');
  234. var isChrome = /chrome/.test(navigator.userAgent.toLowerCase());
  235.  
  236. // SE: tiny editor related styles
  237. GM_addStyle('#input {border:none; margin:0; padding:0; font:12px "Courier New", Verdana; border:0} ' +
  238. // in te, removed left margin
  239. '.te {border:1px solid #bbb; padding:0 1px 1px; font:12px Verdana, Arial;} ' +
  240. // .te iframe change WYSIWYG background color e.g. background-color:#222222. Effects Chrome but in FF color is overridden by body style setting.
  241. '.te iframe {border:none; background-color:silver;} ' +
  242. '.teheader {height:31px; border-bottom:1px solid #bbb; background:url(http://wikifoundryattachments.com/xg-mfHLVZfdD7OErlv0NxQ55) repeat-x; padding-top:1px} ' +
  243. '.teheader select {float:left; margin-top:5px} ' +
  244. '.tefont {margin-left:5px; width:118px;} ' +
  245. '.tesize {margin-left:4px; width:42px;} ' +
  246. '.tecolor {margin-left:4px; width:84px;} ' +
  247. '.testyle {margin-left:3px; margin-right:12px; width:70px;} ' +
  248. '.tedivider {float:left; width:2px; height:30px; background:#ccc} ' +
  249. '.tecontrol {float:left; width:34px; height:30px; cursor:pointer; background-image:url(http://wikifoundryattachments.com/jjINLqTU68Po418uA2wLPw18521)} ' +
  250. '.tecontrol:hover {background-color:#fff; background-position:30px 0} ' +
  251. '.tefooter {height:32px; border-top:1px solid #bbb; background:#f5f5f5} ' +
  252. '.toggle {float:left; background:url(http://wikifoundryattachments.com/jjINLqTU68Po418uA2wLPw18521) -34px 2px no-repeat; padding:9px 13px 0 31px; height:23px; border-right:1px solid #ccc; cursor:pointer; color:#666} ' +
  253. '.toggle:hover {background-color:#fff} ' +
  254. '.resize {float:right; height:32px; width:32px; background:url(http://wikifoundryattachments.com/W_Ipj_QMRSXNr7FEg3Sz8A78) 15px 15px no-repeat; cursor:s-resize}');
  255. // #editor change WYSIWYG font color e.g. color:white, color:blue, etc. *** Does not work in Chrome. Chrome defaults to black
  256. GM_addStyle('#editor {cursor:text; margin:10px; color:black; font:'+ui_default_post_font+';}');
  257. // GM_addStyle('#iframe_editor {background-color:dimgray;}');
  258.  
  259. // SE: the following block "main" is inserted into the page
  260. function main()
  261. {
  262. innerGetPostElement = function (idPostNew, idPostEdit)
  263. {
  264. try
  265. {
  266. if (!idPostNew && !idPostEdit) return undefined;
  267. var i = 0, j = 0;
  268. var cForms = document.getElementsByName('threadFormElement');
  269. if (cForms[0])
  270. for (i in cForms)
  271. {
  272. if (cForms[i] && cForms[i].parentNode)
  273. if (cForms[i].name == 'threadFormElement' && cForms[i].style.display == 'block' && cForms[i].parentNode.style.display == 'block')
  274. {
  275. if (cForms[i].elements)
  276. {
  277. for (j in cForms[i].elements)
  278. {
  279. if (cForms[i].elements[j].id == idPostNew)
  280. {
  281. return cForms[i].elements[j];
  282. break;
  283. }
  284. }
  285. }
  286. break;
  287. }
  288. }
  289. var editElement = document.getElementById(idPostEdit);
  290. if (editElement && editElement.parentNode.parentNode)
  291. if (editElement.parentNode.parentNode.style.display == 'block')
  292. return editElement;
  293. else
  294. return undefined;
  295. }
  296. catch (e) {
  297. // alert(e.source + '\n' + e.message);
  298. return undefined;
  299. }
  300. }
  301.  
  302. // POSTING TOOLS
  303. posting_tools = function()
  304. {
  305. if (document.getElementById('posting_tools')){return 0;}
  306. document.getElementById('untaintpanel').innerHTML+=''
  307. +'<form id="posting_tools"><small><br />'
  308. +'<input type="button" onclick="posting_add(\'a\');" value="Link" />'
  309. +'<input type="button" onclick="posting_add(\'img\');" value="Image" />'
  310. +'<input type="button" onclick="posting_add(\'youtube\');" value="Youtube" />'
  311. +'<input type="button" onclick="posting_add(\'font\');" value="Font" />'
  312. +'<br /><input type="text" id="posting_code" onfocus="this.select()" size="27" value="" style="margin-top:3px;" />'
  313. +' <input type="button" onclick="activateTinyEditor();" value="TE" />'
  314. +'</small>'
  315. +'</form>';
  316. }
  317.  
  318. // Posting tools code generation
  319. posting_add = function(x)
  320. {
  321. var y = ' ';
  322. if(x=='img')
  323. {
  324. y = prompt('Enter Image URL:','http://');
  325. if (!y) return;
  326. if (y.search(/wikifoundry.com/i) != -1) // Need to treat wikifoundry URLs differently
  327. y = y.replace(/\./g,'-').replace('http://','http://tinyurl.com/');
  328. width = prompt('Image Width:\n\nAuto (image\'s default size), a number (pixels), or a percentage of the page\'s width (e.g. 50%)','auto');
  329. if (!width) width = 'auto';
  330. // concept of including image title credited to I.Join
  331. title = prompt('Image description (Cancel to skip):\n\nA floating popup description dislays when the user\nmoves the mouse cursor over the image.','image');
  332. if (title)
  333. title = 'title="' + title + '"';
  334. else
  335. title = '';
  336. x='<img src="'+ y +'" ' + title + ' width="'+ width +'">';
  337. }
  338. if(x=='a'){
  339. x='<a href="'+ prompt('Link URL:','http://') +'">'+ prompt('Link text:','Link') +'</a>';}
  340. if(x=='font'){
  341. ff = prompt('Enter font face:','arial');
  342. if (!ff) return;
  343. x='<font face="' + ff + '" size="'+ prompt('Size:\nEnter a number 1-7, a point value (e.g. 12pt), a percentage of the default font (e.g. 200%), or a relative value (e.g. +1 or -1)','-1') +'" color="'+ prompt('Color:','red') +'">'+ prompt('Text:',' ') +'</font>';}
  344. if(x=='youtube')
  345. {
  346. url = prompt('Youtube URL:'+'\n\nE.g. http://www.youtube.com/watch?v=abc123','');
  347. if (!url) return;
  348. // http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url
  349. regexp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|watch\?feature=player_embedded\&v=)([^#\&\?]*).*/;
  350. match = url.match(regexp);
  351. if (match && match[2].length == 11)
  352. {
  353. y = match[2];
  354. }
  355. else if (url.length == 11)
  356. {
  357. // If just the id is entered, then do a minimal check of the currently accepted length.
  358. // Presently, Youtube doesn't guaranty any character set or length of an id
  359. y = url;
  360. }
  361. else
  362. {
  363. alert("The URL or Video ID doesn't appear to be valid or is not matchable. Please ensure a correct entry or try another value.");
  364. return;
  365. }
  366. f = prompt('Scale default resolution between "0" and "2":\n\nE.g. entering "0.25" will make the video one\nquarter the default size, "2" twice the size, "1" no change, etc.','1');
  367. h = 320;
  368. w = 405;
  369. if (f != null && Number(f))
  370. if (Number(f)>0 && Number(f)<=2)
  371. {
  372. h = Math.round(h * Number(f));
  373. w = Math.round(w * Number(f));
  374. }
  375. // Embed tag credit http://m7r-227.wikifoundry.com
  376. x = '<object height="' + h + '" width="' + w + '">'
  377. + '<param name="movie" value="http://wikifoundryattachments.com/IHOlZ-XE6QdUuBNdXdk9jA154555?null=http://'
  378. + '<param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="never"><param name="wmode" value="transparent">'
  379. + '<embed allowfullscreen="true" flashvars="provider=video&amp;image=http://i.ytimg.com/vi/' + y + '/hqdefault.jpg&amp;file=http://ox-proxy.no-ip.org/youtube/'
  380. + y + '" src="http://wikifoundrytools.com/wiki/m7r-227/widget/unknown/d5a99526c41ad11592c12c7b323ca651af50909a?null=http://" type="application/x-shockwave-flash" wmode="transparent" height="'
  381. + h + '" width="' + w + '">'
  382. + '<param name="flashvars" value="provider=video&amp;image=http://i.ytimg.com/vi/'
  383. + y + '/hqdefault.jpg&amp;file=http://ox-proxy.no-ip.org/youtube/' + y + '"></object>';
  384. x += '<br><a href="http://youtu.be/' + y + '">' + 'http://youtu.be/' + y + '</a><br><br>';
  385. }
  386. document.getElementById('posting_code').value=x;
  387. try{innerGetPostElement('threadFormBody','edit_postText').value+=x}catch(e){};
  388. }
  389.  
  390. TINY={};
  391.  
  392. function T$(i){return document.getElementById(i)}
  393. function T$$$(){return document.all?1:0}
  394.  
  395. // SE: the modified TinyEditor control
  396. // Original control: http://www.scriptiny.com/2010/02/javascript-wysiwyg-editor/
  397. TINY.editor=function(){
  398. var c=[], offset=-30;
  399. c['cut']=[1,'Cut','a','cut',1];
  400. c['copy']=[2,'Copy','a','copy',1];
  401. c['paste']=[3,'Paste','a','paste',1];
  402. c['bold']=[4,'Bold','a','bold'];
  403. c['italic']=[5,'Italic','a','italic'];
  404. c['underline']=[6,'Underline','a','underline'];
  405. c['strikethrough']=[7,'Strikethrough','a','strikethrough'];
  406. c['subscript']=[8,'Subscript','a','subscript'];
  407. c['superscript']=[9,'Superscript','a','superscript'];
  408. c['orderedlist']=[10,'Insert Ordered List','a','insertorderedlist'];
  409. c['unorderedlist']=[11,'Insert Unordered List','a','insertunorderedlist'];
  410. c['outdent']=[12,'Outdent','a','outdent'];
  411. c['indent']=[13,'Indent','a','indent'];
  412. c['leftalign']=[14,'Left Align','a','justifyleft'];
  413. c['centeralign']=[15,'Center Align','a','justifycenter'];
  414. c['rightalign']=[16,'Right Align','a','justifyright'];
  415. c['blockjustify']=[17,'Block Justify','a','justifyfull'];
  416. c['undo']=[18,'Undo','a','undo'];
  417. c['redo']=[19,'Redo','a','redo'];
  418. c['image']=[20,'Insert Image','i','insertimage','Enter Image URL:','http://'];
  419. c['hr']=[21,'Insert Horizontal Rule','a','inserthorizontalrule'];
  420. c['link']=[22,'Insert Hyperlink','i','createlink','Enter URL:','http://'];
  421. c['unlink']=[23,'Remove Hyperlink','a','unlink'];
  422. c['unformat']=[24,'Remove Formatting','a','removeformat'];
  423. c['print']=[25,'Print','a','print'];
  424. // Note: These 3 use the positions in the image used by the other original function with the same index number.
  425. // Subscript and Superscript do not work in wikifoundry. If the originals are activated, the image must be redone.
  426. c['insertyoutube']=[8,'Insert Youtube Video','i','insertyoutube','Youtube URL:',''];
  427. c['inserttable']=[9,'Insert Table','i','inserttable'];
  428. c['help']=[25,'Notes','a','help'];
  429. function edit(n,obj){
  430. this.n=n; window[n]=this; /* this.t=T$(obj.id); */ this.t=innerGetPostElement('threadFormBody', 'edit_postText');
  431. this.obj=obj; this.xhtml=obj.xhtml;
  432. var p=document.createElement('div'), w=document.createElement('div'), h=document.createElement('div'),
  433. l=obj.controls.length, i=0;
  434. this.i=document.createElement('iframe'); this.i.frameBorder=0; /* added to give id */ this.i.id='iframe_'+obj.bodyid;
  435. this.i.width=obj.width||'500'; this.i.height=obj.height||'250'; this.ie=T$$$();
  436. this.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
  437. h.className=obj.rowclass||'teheader'; p.className=obj.cssclass||'te'; p.style.width=this.i.width+'px'; p.appendChild(h);
  438. for(i;i<l;i++){
  439. var id=obj.controls[i];
  440. if(id=='n'){
  441. h=document.createElement('div'); h.className=obj.rowclass||'teheader'; p.appendChild(h)
  442. }else if(id=='|'){
  443. var d=document.createElement('div'); d.className=obj.dividerclass||'tedivider'; h.appendChild(d)
  444. }else if(id=='font'){
  445. var sel=document.createElement('select'), fonts=obj.fonts||['Verdana','Arial','Georgia'], fl=fonts.length, x=0;
  446. sel.className='tefont'; sel.onchange=new Function(this.n+'.ddaction(this,"fontname")');
  447. sel.options[0]=new Option('[Font]','');
  448. for(x;x<fl;x++){
  449. var font=fonts[x];
  450. sel.options[x+1]=new Option(font,font)
  451. }
  452. h.appendChild(sel)
  453. }else if(id=='size'){
  454. var sel=document.createElement('select'), sizes=obj.sizes||[1,2,3,4,5,6,7,-1,-2], sl=sizes.length, x=0;
  455. sel.className='tesize'; sel.onchange=new Function(this.n+'.ddaction(this,"fontsize")');
  456. for(x;x<sl;x++){
  457. var size=sizes[x];
  458. sel.options[x]=new Option(size,size)
  459. }
  460. h.appendChild(sel)
  461. }else if(id=='tcolor'){
  462. // added to allow for text colors
  463. var sel=document.createElement('select'), tcolors=obj.tcolors||['Black','Gray','Silver','White'], tcl=tcolors.length, x=0;
  464. sel.className='tecolor'; sel.onchange=new Function(this.n+'.ddaction(this,"forecolor")');
  465. sel.options[0]=new Option('[Color]','');
  466. for(x;x<tcl;x++){
  467. var tcolor=tcolors[x];
  468. sel.options[x+1]=new Option(tcolor,tcolor)
  469. }
  470. h.appendChild(sel)
  471. }else if(id=='style'){
  472. var sel=document.createElement('select'),
  473. styles=obj.styles||[['[Style]',''],['Paragraph','<p>'],['Header 1','<h1>'],['Header 2','<h2>'],['Header 3','<h3>'],['Header 4','<h4>'],['Header 5','<h5>'],['Header 6','<h6>']],
  474. sl=styles.length, x=0;
  475. sel.className='testyle'; sel.onchange=new Function(this.n+'.ddaction(this,"formatblock")');
  476. for(x;x<sl;x++){
  477. var style=styles[x];
  478. sel.options[x]=new Option(style[0],style[1])
  479. }
  480. h.appendChild(sel)
  481. }else if(c[id]){
  482. var div=document.createElement('div'), x=c[id], func=x[2], ex, pos=x[0]*offset;
  483. div.className=obj.controlclass;
  484. div.style.backgroundPosition='0px '+pos+'px';
  485. div.title=x[1];
  486. ex=func=='a'?'.action("'+x[3]+'",0,'+(x[4]||0)+')':'.insert("'+x[4]+'","'+x[5]+'","'+x[3]+'")';
  487. div.onclick=new Function(this.n+(id=='print'?'.print()':ex));
  488. div.onclick=new Function(this.n+(id=='help'?'.help()':ex));
  489. div.onmouseover=new Function(this.n+'.hover(this,'+pos+',1)');
  490. div.onmouseout=new Function(this.n+'.hover(this,'+pos+',0)');
  491. h.appendChild(div);
  492. if(this.ie){div.unselectable='on'}
  493. }
  494. }
  495. this.t.parentNode.insertBefore(p,this.t); this.t.style.width=this.i.width+'px';
  496. w.appendChild(this.t); w.appendChild(this.i); p.appendChild(w); this.t.style.display='none';
  497. if(obj.footer){
  498. var f=document.createElement('div'); f.className=obj.footerclass||'tefooter';
  499. if(obj.toggle){
  500. var to=obj.toggle, ts=document.createElement('div');
  501. ts.className=to.cssclass||'toggle';
  502. ts.innerHTML=obj.toggletext||'source';
  503. ts.onclick=new Function(this.n+'.toggle(0,this);return false');
  504. f.appendChild(ts);
  505. }
  506. if(obj.resize){
  507. var ro=obj.resize, rs=document.createElement('div');
  508. rs.className=ro.cssclass||'resize';
  509. rs.onmousedown=new Function('event',this.n+'.resize(event);return false');
  510. rs.onselectstart=function(){return false};
  511. f.appendChild(rs)
  512. }
  513. p.appendChild(f)
  514. }
  515. this.e=this.i.contentWindow.document; this.e.open();
  516. var m='<html><head>', bodyid=obj.bodyid?" id=\""+obj.bodyid+"\"":"";
  517. if(obj.cssfile){m+='<link rel="stylesheet" href="'+obj.cssfile+'" />'}
  518. if(obj.css){m+='<style type="text/css">'+obj.css+'</style>'}
  519. m+='</head><body'+bodyid+'>'+(obj.content||this.t.value);
  520. m+='</body></html>';
  521. this.e.write(m);
  522. this.e.close(); this.e.designMode='on'; /* this.d=1; */
  523. // wikifoundry pages require custom handling of styleWithCSS
  524. if(this.xhtml){
  525. try{this.e.execCommand('styleWithCSS',false,false)}
  526. catch(e){try{this.e.execCommand('useCSS',0,1)}catch(e){}}
  527. }
  528. // auto toggle to initialize an edit in the designer with regular expressions needed on wikifoundry sites.
  529. this.d=0;
  530. this.toggle(0, this);
  531. // added set focus
  532. this.i.contentWindow.focus();
  533. }; // end constructor
  534. edit.prototype.print=function(){
  535. this.i.contentWindow.print()
  536. },
  537. // added notes/help
  538. edit.prototype.help=function(){
  539. alert('Notes:\n\nThe WYSIWYG editor simulates roughly what a post will look like once posted. The design mode allows for '
  540. + 'text, links and images to be edited similarly to a very simple HTML editor. Wikifoundry posts can only handle '
  541. + 'simple markup tags. Pressing "source" switches to a purely text mode normally seen when creating a post. '
  542. + 'The "source" is what is actually posted but should look similar to what is displayed in design mode once '
  543. + 'posted. The "source" can be edited and sent without using the design window. The control is based on the '
  544. + 'Tiny Editor modified to work with Wikifoundry and GreaseMonkey.\n\n'
  545. + 'For more info see:\n'
  546. + 'http://www.scriptiny.com/2010/02/javascript-wysiwyg-editor/\n\n'
  547. + 'Some usage notes: In addition to being able to insert images, images can be dragged and dropped to the window. '
  548. + 'But the size will be automatic. Images and text can be used to dynamically create links. Fonts, sizes and colors '
  549. + 'can be modified directly in design mode which translate into the post. Links can also be dragged and dropped into '
  550. + 'the window. Copying and pasting images will paste the image data directly into the window. Unless the image is very small, the '
  551. + 'number of characters will likely be in the thousands and not post. Very small images can, however, still be posted this way.');
  552. alert('Some issues to be aware of:\n\nThe control is set to stay in a mode of using only simple markup or RTF. '
  553. + 'There is some bugginess with this mode, and if it\'s pushed too much, will revert to more complex HTML which is ignored '
  554. + 'by Wikifoundry servers. Reverting to HTML is not a major problem, however, as the basic text and images will '
  555. + 'generally make it into the post even if some styling is stripped out by the server. In addition, Youtube videos '
  556. + 'are placed in a containing iframe to make them a visible object in the designer. Youtube videos will not '
  557. + 'display in the designer in Firefox but will post normally as the "source" is what actually gets posted. Youtube videos will, '
  558. + 'however, display in the designer in Chrome. The designer, in general, still performs better in Firefox. The server '
  559. + 'accepts very simple unformatted tables, and additionally, simple tables have been added which can hold and organize '
  560. + 'graphics and text.\n\n'
  561. + 'In summary, the control is only designed to handle simple formatting tasks. Switch to "source" in order to more easily straighten '
  562. + 'things out if things get too messed up. Automatically loading the control can be turned on or off in the settings.');
  563. },
  564. edit.prototype.hover=function(div,pos,dir){
  565. div.style.backgroundPosition=(dir?'34px ':'0px ')+(pos)+'px'
  566. },
  567. edit.prototype.ddaction=function(dd,a){
  568. var i=dd.selectedIndex, v=dd.options[i].value;
  569. this.action(a,v)
  570. },
  571. edit.prototype.action=function(cmd,val,ie){
  572. if (!this.d) return;
  573. if(ie&&!this.ie){
  574. alert('Your browser does not support this function.')
  575. }else{
  576. this.e.execCommand('styleWithCSS',false,false);
  577. this.e.execCommand(cmd,0,val||null);
  578. }
  579. },
  580. edit.prototype.insert=function(pro,msg,cmd){
  581. if (!this.d) return;
  582. if (cmd == 'insertyoutube')
  583. {
  584. url = prompt(pro+'\n\nE.g. http://www.youtube.com/watch?v=abc123',msg);
  585. if (!url) return;
  586. // http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url
  587. regexp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|watch\?feature=player_embedded\&v=)([^#\&\?]*).*/;
  588. match = url.match(regexp);
  589. if (match && match[2].length == 11)
  590. {
  591. y = match[2];
  592. }
  593. else if (url.length == 11)
  594. {
  595. // If just the id is entered, then do a minimal check of the currently accepted length.
  596. // Presently, Youtube doesn't guaranty any character set or length of an id
  597. y = url;
  598. }
  599. else
  600. {
  601. alert("The URL or Video ID doesn't appear to be valid or is not matchable. Please ensure a correct entry or try another value.");
  602. return;
  603. }
  604. f = prompt('Scale default resolution between "0" and "2":\n\nE.g. entering "0.25" will make the video one\nquarter the default size, "2" twice the size, "1" no change, etc.','1');
  605. h = 320;
  606. w = 405;
  607. if (f != null && Number(f))
  608. if (Number(f)>0 && Number(f)<=2)
  609. {
  610. h = Math.round(h * Number(f));
  611. w = Math.round(w * Number(f));
  612. }
  613. // Embed tag credit http://m7r-227.wikifoundry.com
  614. val = '<object height="' + h + '" width="' + w + '">'
  615. + '<param name="movie" value="http://wikifoundryattachments.com/IHOlZ-XE6QdUuBNdXdk9jA154555?null=http://'
  616. + '<param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="never"><param name="wmode" value="transparent">'
  617. + '<embed allowfullscreen="true" flashvars="provider=video&amp;image=http://i.ytimg.com/vi/' + y + '/hqdefault.jpg&amp;file=http://ox-proxy.no-ip.org/youtube/'
  618. + y + '" src="http://wikifoundrytools.com/wiki/m7r-227/widget/unknown/d5a99526c41ad11592c12c7b323ca651af50909a?null=http://" type="application/x-shockwave-flash" wmode="transparent" height="'
  619. + h + '" width="' + w + '">'
  620. + '<param name="flashvars" value="provider=video&amp;image=http://i.ytimg.com/vi/'
  621. + y + '/hqdefault.jpg&amp;file=http://ox-proxy.no-ip.org/youtube/' + y + '"></object>';
  622. val += '<br><a href="http://youtu.be/' + y + '">' + 'http://youtu.be/' + y + '</a><br><br>';
  623. cmd = 'inserthtml';
  624. }
  625. else if (cmd == 'insertimage')
  626. {
  627. y = prompt(pro,msg);
  628. if (!y) return;
  629. if (y.search(/wikifoundry.com/i) != -1) // Need to treat wikifoundry URLs differently
  630. y = y.replace(/\./g,'-').replace('http://','http://tinyurl.com/');
  631. width = prompt('Image Width:\n\nAuto (image\'s default size), a number (pixels), or a percentage of the page\'s width (e.g. 50%)','auto');
  632. if (!width) width = 'auto';
  633. // concept of including image title credited to I.Join
  634. title = prompt('Image description (Cancel to skip):\n\nA floating popup description dislays when the user\nmoves the mouse cursor over the image.','image');
  635. if (title)
  636. title = 'title="' + title + '"';
  637. else
  638. title = '';
  639. val='<img src="'+ y +'" ' + title + ' width="'+ width +'">';
  640. cmd = 'inserthtml';
  641. }
  642. else if (cmd == 'inserttable')
  643. {
  644. rowstext = prompt("Enter rows:");
  645. colstext = prompt("Enter cols:");
  646. rows = parseInt(rowstext);
  647. cols = parseInt(colstext);
  648. if ((rows > 0) && (cols > 0))
  649. {
  650. div = document.createElement("div");
  651. table = document.createElement("table");
  652. table.setAttribute("border", "1");
  653. table.setAttribute("cellpadding", "5");
  654. table.setAttribute("cellspacing", "2");
  655. tbody = document.createElement("tbody");
  656. for (var i=0; i < rows; i++)
  657. {
  658. tr = document.createElement("tr");
  659. for (var j=0; j < cols; j++)
  660. {
  661. td = document.createElement("td");
  662. br = document.createElement("br");
  663. td.appendChild(br);
  664. tr.appendChild(td);
  665. }
  666. tbody.appendChild(tr);
  667. }
  668. table.appendChild(tbody);
  669. div.appendChild(table);
  670. val = div.innerHTML;
  671. cmd = 'inserthtml';
  672. }
  673. else return;
  674. }
  675. else val=prompt(pro,msg);
  676. if(val!=null&&val!='')
  677. {
  678. // use styleWithCSS
  679. this.e.execCommand('styleWithCSS',false,false);
  680. this.e.execCommand(cmd,0,val);
  681. }
  682. },
  683. edit.prototype.setfont=function(){
  684. if (!this.d) return;
  685. // use styleWithCSS
  686. this.e.execCommand('styleWithCSS',false,false);
  687. execCommand('formatblock',0,hType);
  688. },
  689. edit.prototype.resize=function(e){
  690. if(this.mv){this.freeze()}
  691. this.i.bcs=TINY.cursor.top(e);
  692. this.mv=new Function('event',this.n+'.move(event)');
  693. this.sr=new Function(this.n+'.freeze()');
  694. if(this.ie){
  695. document.attachEvent('onmousemove',this.mv); document.attachEvent('onmouseup',this.sr)
  696. }else{
  697. document.addEventListener('mousemove',this.mv,1); document.addEventListener('mouseup',this.sr,1)
  698. }
  699. },
  700. edit.prototype.move=function(e){
  701. var pos=TINY.cursor.top(e);
  702. this.i.height=parseInt(this.i.height)+pos-this.i.bcs;
  703. this.i.bcs=pos
  704. },
  705. edit.prototype.freeze=function(){
  706. if(this.ie){
  707. document.detachEvent('onmousemove',this.mv); document.detachEvent('onmouseup',this.sr);
  708. // store height
  709. putSetting('ui_textarea_height', this.i.height)
  710. }else{
  711. document.removeEventListener('mousemove',this.mv,1); document.removeEventListener('mouseup',this.sr,1)
  712. // store height
  713. putSetting('ui_textarea_height', this.i.height)
  714. }
  715. },
  716. edit.prototype.toggle=function(post,div){
  717. if(!this.d)
  718. {
  719. // From source to wysiwyg
  720. var v=this.t.value;
  721. if(div){div.innerHTML=this.obj.toggletext||'source'}
  722.  
  723. // wikifoundry specific replacements
  724. v=v.replace(/\n/gi,'<br />');
  725. // v=v.replace(/<strong>(.*?)<\/strong>/gi,'<b>$1</b>');
  726. // v=v.replace(/<em>(.*?)<\/em>/gi,'<i>$1</i>')
  727. // v=v.replace(/<span style="font-weight: bold;?">(.*)<\/span>/gi,'<b>$1</b>');
  728. // v=v.replace(/<span style="font-style: italic;?">(.*)<\/span>/gi,'<i>$1</i>');
  729. // v=v.replace(/<span style="font-weight: bold;?">(.*)<\/span>|<b\b[^>]*>(.*?)<\/b[^>]*>/gi,'<b>$1</b>');
  730. if(this.xhtml&&!this.ie){
  731. // v=v.replace(/<strong>(.*)<\/strong>/gi,'<span style="font-weight: bold;">$1</span>');
  732. // v=v.replace(/<em>(.*)<\/em>/gi,'<span style="font-weight: italic;">$1</span>')
  733. }
  734. this.e.body.innerHTML=v;
  735. this.t.style.display='none'; this.i.style.display='block'; this.d=1;
  736. }
  737. else
  738. {
  739. // From wysiwyg to source
  740. var v=this.e.body.innerHTML;
  741. // wikifoundry specific replacements
  742. v=v.replace(/&nbsp;/gi,' ');
  743. v=v.replace(/&amp;/gi,'&');
  744. v=v.replace(/&lt;/gi,'<');
  745. v=v.replace(/&gt;/gi,'>');
  746. v=v.replace(/&quot;/gi,'"');
  747. v=v.replace(/&#0?39;/g,'\'');
  748. // Strip out unusable attributes in certain tags
  749. v=v.replace(/(<(?:img|font|div|table|tbody|t[rd]|b|u|i|h[2-4]|ol|ul|li|blockquote)\s.*?)(?:class=".*?"\s?)(.*?>)/gi,'$1$2');
  750. v=v.replace(/(<(?:img|a|font|div|table|tbody|t[rd]|b|u|i|h[2-4]|ol|ul|li|blockquote)\s.*?)(?:id=".*?"\s?)(.*?>)/gi,'$1$2');
  751. v=v.replace(/(<(?:img|a)\s.*?)(?:name=".*?"\s?)(.*?>)/gi,'$1$2');
  752. if (this.chrome)
  753. {
  754. v=v.replace(/style="text-align:\s?(.*?);?"/gi,'align="$1"');
  755. v=v.replace(/<div\s*?>\s*?<br\s*?\/?\s*?>\s*?<\/div\s*?>/gi,'\n');
  756. }
  757. v=v.replace(/style="width: ?(.*?)px; ?height: ?(.*?)px;?"/gi,'width="$1" height="$2"');
  758. v=v.replace(/<br\s*?\/?\s*?>/gi,'\n');
  759. v=v.replace(/<strong>(.*?)<\/strong>/gi,'<b>$1</b>');
  760. v=v.replace(/<em>(.*?)<\/em>/gi,'<i>$1</i>')
  761. v=v.replace(/<a href="(.*?)">(.*?)<\/a>/gi,'<a class="external" href="$1" rel="nofollow" target="_blank">$2</a>');
  762. v=v.replace(/<span style="font-weight: bold;?">(.*)<\/span>/gi,'<b>$1</b>');
  763. v=v.replace(/<span style="font-style: italic;?">(.*)<\/span>/gi,'<i>$1</i>');
  764. // Attempt to strip out any remaining unusable tags
  765. v=v.replace(/<\/?(?:\!DOCTYPE|abbr|acronym|address|applet|area|base|basefont|bdo|big|body|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|dl|dt|em|fieldset|form|frame|frameset|head|h1|h5|h6|hr|html|input|ins|kbd|label|legend|link|map|menu|meta|noframes|noscript|optgroup|option|p|pre|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|textarea|tfoot|th|thead|title|tt|var)(?:>|\s.*?>)/gi,'');
  766. // Attempt to strip out the unusable style attribute in any remaining usable tags
  767. v=v.replace(/(<(?:img|a|font|div|table|tbody|t[rd]|b|u|i|h[2-4]|ol|ul|li|blockquote)\s.*?)(?:style=".*?"\s?)(.*?>)/gi,'$1$2');
  768.  
  769. if(this.xhtml){
  770. // v=v.replace(/<span class="apple-style-span">(.*)<\/span>/gi,'$1');
  771. // v=v.replace(/ class="apple-style-span"/gi,'');
  772. // v=v.replace(/<span style="">/gi,'');
  773. // v=v.replace(/<br>/gi,'<br />');
  774. // v=v.replace(/<br ?\/?>$/gi,'');
  775. // v=v.replace(/^<br ?\/?>/gi,'');
  776. // v=v.replace(/(<img [^>]+[^\/])>/gi,'$1 />');
  777. // v=v.replace(/<b\b[^>]*>(.*?)<\/b[^>]*>/gi,'<strong>$1</strong>');
  778. // v=v.replace(/<i\b[^>]*>(.*?)<\/i[^>]*>/gi,'<em>$1</em>');
  779. // v=v.replace(/<u\b[^>]*>(.*?)<\/u[^>]*>/gi,'<span style="text-decoration:underline">$1</span>');
  780. // v=v.replace(/<(b|strong|em|i|u) style="font-weight: normal;?">(.*)<\/(b|strong|em|i|u)>/gi,'$2');
  781. // v=v.replace(/<(b|strong|em|i|u) style="(.*)">(.*)<\/(b|strong|em|i|u)>/gi,'<span style="$2"><$4>$3</$4></span>');
  782. // v=v.replace(/<span style="font-weight: normal;?">(.*)<\/span>/gi,'$1');
  783. // v=v.replace(/<span style="font-weight: bold;?">(.*)<\/span>/gi,'<strong>$1</strong>');
  784. // v=v.replace(/<span style="font-style: italic;?">(.*)<\/span>/gi,'<em>$1</em>');
  785. // v=v.replace(/<span style="font-weight: bold;?">(.*)<\/span>|<b\b[^>]*>(.*?)<\/b[^>]*>/gi,'<strong>$1</strong>')
  786. }
  787. if(div){div.innerHTML=this.obj.toggletext||'wysiwyg'}
  788. this.t.value=v;
  789. if(!post){
  790. this.t.style.height=this.i.height+'px';
  791. this.i.style.display='none'; this.t.style.display='block'; this.d=0
  792. }
  793. }
  794. },
  795. edit.prototype.post=function(){
  796. this.e.execCommand('styleWithCSS',false,false);
  797. if(this.d){this.toggle(1)}
  798. };
  799. return{edit:edit}
  800. }();
  801.  
  802. TINY.cursor=function(){
  803. return{
  804. top:function(e){
  805. return T$$$()?window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop:e.clientY+window.scrollY
  806. }
  807. }
  808. }();
  809. decodeHTML = function(a) {return a.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#0?39;/g, '\'');}
  810. newlinesToUnicode = function(a) {return a.replace(/<br\s*\/?>/gi,"\n");}
  811.  
  812. // Corresponds to original processing when editing a post, originally coded by Gu1.
  813. loadOriginalPost = function(e)
  814. {
  815. var textNode = e.parentNode.parentNode.childNodes[5];
  816. var postText = document.getElementById('edit_postText');
  817. var postQuote = document.getElementById('edit_postQuote');
  818. setTimeout(function() { // please god forgive me for this ugly piece of code
  819. if(document.getElementById('postEditor').style.display == 'block')
  820. {
  821. var A = textNode.cloneNode(true);
  822. var B;
  823. var C = A.firstChild;
  824. while(C)
  825. {
  826. B = C.nextSibling;
  827. if(C.nodeName.toUpperCase() === "BLOCKQUOTE")
  828. {
  829. postQuote.value = C.innerHTML.replace(/^"|"$/g, '');
  830. postQuote.value = decodeHTML(newlinesToUnicode(postQuote.value));
  831. A.removeChild(C);
  832. break;
  833. }
  834. C=B;
  835. }
  836. postText.value = decodeHTML(newlinesToUnicode(A.innerHTML));
  837. }
  838. }, 50); // we wait 50ms before executing
  839. }
  840. var tinyEditor = null;
  841. postSubmitted = function(elem)
  842. {
  843. if (tinyEditor) tinyEditor.post();
  844. if (getSetting('return_on_post', 'true') == 'true' && elem.id == 'threadFormSubmitButton' && window['sessionStorage'] !== null)
  845. if (document.getElementsByClassName('paging')[0])
  846. window.sessionStorage['added_post'] = 'jump_end_of_thread';
  847. else
  848. window.sessionStorage['added_post'] = 'scroll_down';
  849. }
  850. cancelPost = function(){window.location.reload()}
  851. loadInitialize = function(nCount)
  852. {
  853. if (nCount > 10) return;
  854. var textElement = innerGetPostElement('threadFormBody', 'edit_postText');
  855. // if text area loaded and visible
  856. if (textElement)
  857. {
  858. if (getSetting('ui_uncheck_watch_this_thread', 'true') == 'true')
  859. {
  860. elem = innerGetPostElement('notifyMeCbx','');
  861. if (elem) elem.checked = false;
  862. }
  863. textElement.style.font = getSetting('ui_default_post_font', '12px Arial');
  864. // Critical part of unrestricted posting first added by Gu1
  865. XMLHttpRequest.prototype.origsend = XMLHttpRequest.prototype.send;
  866. XMLHttpRequest.prototype.send = function(input)
  867. {
  868. if(input == null)
  869. {
  870. return this.origsend();
  871. }
  872. if(input.substr != undefined && input.substr(0, 20) == "<thread><posts><post") // are we posting a new post ?
  873. {
  874. // Use [\s\S]* instead of .* because the dot doesnt match new lines and there is no "DOTALL" flag
  875. var regex = new Array();
  876. // Regular expression, to match valid tags, modified to fix issue that sometimes occurs with nested tags. In input, \n is already replaced with <br> or <br />
  877. regex[0] = /&lt;\/?(?:img|a|font|div|table|tbody|t[rd]|object|param|b|u|i|embed|h[2-4]|ol|ul|li|blockquote)(?:&gt;|\s[\s\S]*?&gt;)/gi;
  878. // HTML tags that should be stripped out because they can not be used.
  879. regex[1] = /&lt;\/?(?:\!DOCTYPE|abbr|acronym|address|applet|area|base|basefont|bdo|big|body|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|dl|dt|em|fieldset|form|frame|frameset|head|h1|h5|h6|hr|html|iframe|input|ins|kbd|label|legend|link|map|menu|meta|noframes|noscript|optgroup|option|p|pre|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|textarea|tfoot|th|thead|title|tt|var)(?:&gt;|\s[\s\S]*?&gt;)/gi;
  880. // Dirtiest array in western hemisphere ;)
  881. touncensor = ['asshole', 'bitch', 'cunt', 'fuck', 'shit', 'whore', 'pussy', 'damn[^a-z]', 'hell[^a-z]', 'tit[^a-rt-z]', 'cock[^a-rt-z]', 'cum[^a-z]'];
  882. input = input.replace(new RegExp(touncensor.join('|'), 'gi'), function(str) {
  883. return str.substr(0, 1)+'\u00AD'+str.substr(1);
  884. });
  885.  
  886. var docu = (new DOMParser).parseFromString(input, "text/xml"); // the data as an XMLDocument object
  887. var text = docu.getElementsByTagName('text');
  888. if(text.length == 1) // to avoid an error if the text element doesnt exist
  889. {
  890. text = text[0].firstChild;
  891. // see "decodeHTML" in www.js
  892. // Strip out unusable tags
  893. text.nodeValue = text.nodeValue.replace(regex[1], '');
  894. // Decode usable tags
  895. text.nodeValue = text.nodeValue.replace(regex[0], function(i){return decodeHTML(i)});
  896. input = (new XMLSerializer()).serializeToString(docu);
  897. }
  898. }
  899. return this.origsend(input); // calling the real method
  900. } // end send
  901.  
  902. var postBtn = innerGetPostElement('threadFormSubmitButton', 'edit_postSubmit');
  903. if (postBtn) {
  904. postBtn.addEventListener('mousedown', function(){postSubmitted(this)}, false);
  905. postBtn.disabled = false;
  906. }
  907. postBtn = innerGetPostElement('closeThreadButton', 'edit_postCancel');
  908. if (postBtn) {
  909. postBtn.addEventListener('click', cancelPost, false);
  910. }
  911.  
  912. if (getSetting('ui_auto_tinyeditor', 'true') == 'true') activateTinyEditor();
  913.  
  914. return;
  915. }
  916. else
  917. {
  918. nCount++;
  919. setTimeout("loadInitialize("+nCount+")", 100);
  920. }
  921. }
  922. activateTinyEditor = function()
  923. {
  924. var teFrame = document.getElementById('iframe_editor');
  925. if (!teFrame)
  926. {
  927. tinyEditor = new TINY.editor.edit('editor',{
  928. id:'',
  929. width:"98%",
  930. height:getSetting('ui_textarea_height', '200'),
  931. cssclass:'te',
  932. controlclass:'tecontrol',
  933. rowclass:'teheader',
  934. dividerclass:'tedivider',
  935. controls:['bold','italic','underline','|','leftalign','centeralign','rightalign','blockjustify','|','link','unlink','image','insertyoutube','inserttable','|','orderedlist','unorderedlist','n',
  936. 'font','size','tcolor','style','|','undo','redo','|','unformat','|','help'],
  937. footer:true,
  938. fonts:['Arial','Arial Black','Comic Sans MS','Courier','Courier New','Cursive','Garamond','Georgia','Helvetica','Impact','Monospace','Sans-Serif','Serif','Times','Verdana'],
  939. tcolors:['Black','Blue','Brown','Crimson','Cyan','FireBrick','Gold','Gray','Green','HotPink','LightCoral','Lime','Magenta','Maroon','Navy','Olive','Orange','OrangeRed','Pink','Purple','Red','Silver','Teal','Tomato','White','Yellow'],
  940. styles:[['[Style]',''],['Header 2','<h2>'],['Header 3','<h3>'],['Header 4','<h4>']],
  941. xhtml:false,
  942. bodyid:'editor',
  943. footerclass:'tefooter',
  944. toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'},
  945. resize:{cssclass:'resize'}
  946. });
  947. } // end if
  948. // Seems to be the way with the least bugginess to use RTF.
  949. teFrame = document.getElementById('iframe_editor'); // if editor just created
  950. if (!teFrame) teFrame.contentWindow.document.execCommand('styleWithCSS', false, false);
  951. } // end activateTinyEditor
  952. } // end main
  953.  
  954. // SE: function finds and returns an element in a new post or edit
  955. getPostElement = function(idPostNew, idPostEdit)
  956. {
  957. try
  958. {
  959. // Find the area the user is actually using.
  960. if (!idPostNew && !idPostEdit) return undefined;
  961. var i = 0, j = 0;
  962. var cForms = document.getElementsByName('threadFormElement');
  963. if (cForms[0])
  964. for (i in cForms)
  965. {
  966. // Find the correct form, style and parent div with a visible style. This only occurs on a new post
  967. if (cForms[i] && cForms[i].parentNode)
  968. if (cForms[i].name == 'threadFormElement' && cForms[i].style.display == 'block' && cForms[i].parentNode.style.display == 'block')
  969. {
  970. if (cForms[i].elements)
  971. {
  972. // find the specified element in the form
  973. for (j in cForms[i].elements)
  974. {
  975. if (cForms[i].elements[j].id == idPostNew)
  976. {
  977. return cForms[i].elements[j];
  978. break;
  979. } // end if
  980. } // end for
  981. }
  982. break;
  983. } // end if
  984. } // end for
  985. // Post is an edit
  986. var elemPost = document.getElementById(idPostEdit);
  987. // Check again to make sure the div parent is visible
  988. if (elemPost && elemPost.parentNode.parentNode)
  989. if (elemPost.parentNode.parentNode.style.display == 'block')
  990. return elemPost;
  991. else
  992. return undefined;
  993. }
  994. catch (e) {
  995. // GM_log(e.source + '\n' + e.message);
  996. // alert(e.source + '\n' + e.message);
  997. return undefined;
  998. } // end try catch
  999. }
  1000.  
  1001. // Separate config from main so that settings can be set on any page but still referenced by functions in main
  1002. function config()
  1003. {
  1004. putSetting = function(name, val)
  1005. {
  1006. if (name && 'localStorage' in window && window['localStorage'] !== null)
  1007. window.localStorage[name] = val;
  1008. }
  1009.  
  1010. getSetting = function(name, defval)
  1011. {
  1012. var val = null;
  1013. if (name && 'localStorage' in window && window['localStorage'] !== null)
  1014. val = window.localStorage[name];
  1015. if (val)
  1016. return val;
  1017. else
  1018. return defval;
  1019. }
  1020.  
  1021. // CONFIGURATION
  1022. // Configuration Panel
  1023. cfg_show = function()
  1024. {
  1025. if(document.getElementById('cfg')){return 0;}
  1026. var pnlcon = null;
  1027. pnlcon = document.getElementById('pageContentInner');
  1028. if (pnlcon)
  1029. {
  1030. pnlcon.innerHTML+='<div style="position:fixed;z-index:10;top:0px;left:50%;width:350px;margin-left:-175px;background-color:black;color:white;"><form id="cfg" name="cfg">'
  1031. +'<fieldset><legend>UnTaint Settings</legend><small>'
  1032. +'<input name="ui_avatar_w" id="ui_avatar_w" type="text" size="2" /> Avatar width (pixels)<br /><br />'
  1033. +'<input name="ui_hide_rater" id="ui_hide_rater" type="checkbox" /> Hide \'Do you find this valuable?\'<br />'
  1034. // added ui_show_leftcolumn. The option to allow for the left navigation bar to remain
  1035. +'<input name="ui_show_leftcolumn" id="ui_show_leftcolumn" type="checkbox" /> Show left navigation<br />'
  1036. // added ui_auto_tinyeditor.
  1037. +'<input name="ui_auto_tinyeditor" id="ui_auto_tinyeditor" type="checkbox" /> Auto load WYSIWYG (\'off\' restores older tools)<br />'
  1038. // added ui_uncheck_watch_this_thread.
  1039. +'<input name="ui_uncheck_watch_this_thread" id="ui_uncheck_watch_this_thread" type="checkbox" /> Auto uncheck \'watch this thread\'<br />'
  1040. // added return_on_post.
  1041. +'<input name="return_on_post" id="return_on_post" type="checkbox" /> On new post, auto jump to end of thread<br /><br />'
  1042. +'Default editing font:<br />'
  1043. // added ui_default_post_font.
  1044. +'<input type="text" name="ui_default_post_font" id="ui_default_post_font" /><br /><br />'
  1045. +'Filter users\' posts:<br />'
  1046. +'<textarea name="ui_user_filter" id="ui_user_filter" cols="40" rows="2" ></textarea><br />'
  1047. +'<small>Note: Names must be exact and separated by commas.</small><br /><br />'
  1048. +'<input name="refresh_threadlist" id="refresh_threadlist" type="text" size="2" /> Thread list reload interval <small>(in seconds; 0 to disable)</small><br />'
  1049. +'<center><button type="button" onclick="cfg_save();window.location.reload();">Save</button><button type="button" onclick="window.location.reload();">Cancel</button></center>'
  1050. +'</small></fieldset></form></div>';
  1051.  
  1052. document.getElementById('ui_avatar_w').value = getSetting('ui_avatar_w', '50');
  1053. document.getElementById('ui_hide_rater').checked = (getSetting('ui_hide_rater', 'true') == 'true');
  1054. document.getElementById('ui_user_filter').value = getSetting('ui_user_filter', '');
  1055. document.getElementById('refresh_threadlist').value = getSetting('refresh_threadlist', '0');
  1056. // newer values
  1057. document.getElementById('ui_show_leftcolumn').checked = (getSetting('ui_show_leftcolumn', 'false') == 'true');
  1058. document.getElementById('ui_auto_tinyeditor').checked = (getSetting('ui_auto_tinyeditor', 'true') == 'true');
  1059. document.getElementById('ui_uncheck_watch_this_thread').checked = (getSetting('ui_uncheck_watch_this_thread', 'true') == 'true');
  1060. document.getElementById('ui_default_post_font').value = getSetting('ui_default_post_font', '12px Arial');
  1061. document.getElementById('return_on_post').checked = (getSetting('return_on_post', 'true') == 'true');
  1062. }
  1063. }
  1064.  
  1065. // Save Configuration
  1066. cfg_save = function()
  1067. {
  1068. putSetting('ui_user_filter', document.getElementById('ui_user_filter').value.replace(', ',',').replace('\n',''));
  1069. putSetting('ui_avatar_w', document.getElementById('ui_avatar_w').value);
  1070. putSetting('ui_hide_rater', document.getElementById('ui_hide_rater').checked);
  1071. putSetting('refresh_threadlist', document.getElementById('refresh_threadlist').value);
  1072. // newer values
  1073. putSetting('ui_show_leftcolumn', document.getElementById('ui_show_leftcolumn').checked);
  1074. putSetting('ui_auto_tinyeditor', document.getElementById('ui_auto_tinyeditor').checked);
  1075. putSetting('ui_uncheck_watch_this_thread', document.getElementById('ui_uncheck_watch_this_thread').checked);
  1076. putSetting('ui_default_post_font', document.getElementById('ui_default_post_font').value);
  1077. putSetting('return_on_post', document.getElementById('return_on_post').checked);
  1078. }
  1079. } // end config
  1080.  
  1081. try
  1082. {
  1083. // Always add setting functions to page
  1084. var script = document.createElement('script');
  1085. script.type = 'text/javascript';
  1086. script.appendChild(document.createTextNode('('+ config +')();'));
  1087. if (document.head) document.head.appendChild(script);
  1088. // Add posting tools when they're relevant
  1089. var reply = getElementsByClassName('threadModify');
  1090. if (reply[0])
  1091. {
  1092. // SE: add 'main' to page when needed
  1093. script = document.createElement('script');
  1094. script.type = 'text/javascript';
  1095. script.appendChild(document.createTextNode('('+ main +')();'));
  1096. if (document.head) document.head.appendChild(script);
  1097. var eventFunctions = 'loadInitialize(0);' + (ui_auto_tinyeditor ? '' : 'posting_tools();');
  1098. for (i in reply)
  1099. {
  1100. // SE: loadInitialize() is critical to the post filter
  1101. if (reply[i].hasAttributes)
  1102. {
  1103. if (reply[i].innerHTML.search('WPC-action_editThreadPost') >= 0)
  1104. reply[i].setAttribute('onclick', 'loadOriginalPost(this);' + eventFunctions);
  1105. else if (reply[i].innerHTML.search('WPC-action_deleteThread') < 0)
  1106. reply[i].setAttribute('onclick', eventFunctions);
  1107. }
  1108. }
  1109. }
  1110. }
  1111. catch (e)
  1112. {
  1113. // alert(e.source + '\n' + e.message);
  1114. }
  1115.  
  1116. // User posts filter
  1117. // Modified "for loops" by I.Join to function in FF 4.x
  1118. try
  1119. {
  1120. if (document.getElementById('threadList'))
  1121. {
  1122. var td = document.getElementById('threadList').getElementsByTagName('td');
  1123. for(var a = 0; a < td.length; a++) // for (var a in td)
  1124. {
  1125. if (td[a].getElementsByTagName('a'))
  1126. {
  1127. var td2 = td[a].getElementsByTagName('a');
  1128. for(var b = 0; b < td2.length; b++) // for (var b in td2)
  1129. {
  1130. if (b == 2 && td2[b].innerHTML && ui_user_filter.split(',').contains(td2[b].innerHTML))
  1131. {
  1132. var tr = td2[2].parentNode.parentNode;
  1133. tr.setAttribute('title', tr.getElementsByClassName('WPC-action')[1].innerHTML+': \n'+tr.getElementsByClassName('threadText')[0].innerHTML);
  1134. tr.innerHTML = '<td style="background-color:firebrick;border:1px solid maroon;border-right-width:0;"></td><td style="background-color:firebrick;border:1px solid maroon;border-left-width:0;"></td>';
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. catch (e)
  1142. {
  1143. // alert(e.source + '\n' + e.message);
  1144. }
  1145.  
  1146. // SE: Added a show left navigation bar option for those who want to add new pages and/or use the navigation bar.
  1147. if(ui_show_leftcolumn)
  1148. // Show navigation and narrow page
  1149. GM_addStyle('#leftColumn {margin-top:1px;}')
  1150. else
  1151. // Hide navigation/Widen page to the entire screen
  1152. GM_addStyle('#outer {padding-left:0 !important;}');
  1153. // ======== AESTHETIC CHANGES ========
  1154. GM_addStyle('#userBrand, #gNav, #gnMain, #gnAccount{height:20px !important; line-height:20px !important;}');
  1155. GM_addStyle('#pageContentInner{min-height:400px !important;padding-bottom:0;}');
  1156. // Set background color from black to silver to make it more generic for all sites. This also effects the background color in design mode in FF but not in Chrome
  1157. GM_addStyle('#footer{display:none !important;} body{background-color:silver !important;} #WPC-bodyContentContainer{margin-bottom:-50px !important;}');
  1158. GM_addStyle('#relatedContent{font-size:80% !important;} #pageContentInner{padding-bottom:0 !important;}');
  1159. GM_addStyle('#gnPromoLinks {display:none;}'); // Hide search area
  1160.  
  1161. // Modify Nav-Bar:
  1162. // SE: fan chat restored for tscc wiki only
  1163. if (document.getElementById('gnMain'))
  1164. {
  1165. var menu = document.getElementById('gnMain');
  1166. m1 = document.createElement('li');
  1167. m1.innerHTML = '<span><a href="/thread">Threads</a></span>';
  1168. menu.insertBefore(m1, menu.childNodes[2]);
  1169. if (/tsccwiki.wikifoundry/i.test(window.location.host))
  1170. {
  1171. m2 = document.createElement('li');
  1172. m2.innerHTML = '<span><a href="http://tsccwiki.wikifoundry.com/page/TSCC+Fan+Chat">Fan Chat</a></span>';
  1173. menu.appendChild(m2);
  1174. }
  1175. }
  1176.  
  1177. // Hide "Do you find this valuable?"
  1178. if(ui_hide_rater)
  1179. {
  1180. GM_addStyle('.threadRater{display:none !important;}');
  1181. }
  1182. // Enlarge Avatars
  1183. GM_addStyle('img.imageSm{width:'+ui_avatar_w+'px;}');
  1184. // Remove Ads for those without Adblock+
  1185. GM_addStyle('#adsTop, .ads{display:none !important;}')
  1186.  
  1187. // Auto-refresh for Thread list
  1188. // SE: stripped the domain back to .com to accommodate custom wiki names and
  1189. // added $/m as it wasn't always evaluating to true when "thread" at eol
  1190. if (window.location.href.search(/\.com\/thread($|[^\/])/mi) >= 0 && refresh_threadlist > 0) // Auto refresh
  1191. setTimeout(function(){window.location.reload()}, refresh_threadlist*1000);
  1192. // Untaint Panel
  1193. try {var pages = (getElementsByClassName('paging')[0]) ? getElementsByClassName('paging')[0].innerHTML : ''; /* Page #'s */ }
  1194. catch (e) {/* alert(e.source + '\n' + e.message) */}
  1195.  
  1196. var panelsTemp = null;
  1197. try {
  1198. panelsTemp = document.getElementById('siteHeader');
  1199. if (panelsTemp)
  1200. panelsTemp.innerHTML+='<a name="top"></a>';
  1201. }
  1202. catch (e) {
  1203. // alert(e.source + '\n' + e.message);
  1204. }
  1205.  
  1206. try {
  1207. // SE: changed element from allContentInner to pageContentInner.
  1208. // The outer frame and styling of the navigation panel. Plus, adding "bottom"
  1209. panelsTemp = document.getElementById('pageContentInner');
  1210. if (panelsTemp)
  1211. panelsTemp.innerHTML+='<a name="bottom"></a>'
  1212. +'<div style="position:fixed;top:25px;right:6px;width:200px;background:black;color:white;font-size:80%;border:1px solid white;padding:4px;" id="untaintpanel"></div>';
  1213. }
  1214. catch (e) {
  1215. // alert(e.source + '\n' + e.message);
  1216. }
  1217.  
  1218. try {
  1219. var utpanel = document.getElementById('untaintpanel');
  1220. if (utpanel)
  1221. {
  1222. // SE: Inner components of the navigation panel
  1223. utpanel.innerHTML=''
  1224. +'<b>UnTaint | <small><sup><a href="#top" onclick="cfg_show();">Settings</a></sup></small></b><small>'
  1225. +'<div style="float:right;padding-right:5px;padding-top:2px;"><a href="#top">Top</a><br /><a href="#bottom" onclick="setTimeout(function(){window.scroll(0,'+getDocHeight()+')},100);">Bottom</a></div>'
  1226. +'<br /><form method="get" action="http://google.com/search" style="display:inline;"><input type="text" name="q" size="18" maxlength="255" /><input type="hidden" name="sitesearch" value="'+window.location.host+'" /> <input type="submit" value="Search" /></form><br />'
  1227. +'<hr style="border-color:black;margin:1px;" />'
  1228. +'<form style="display:inline;"><input size="18" name="num" id="num" /> <input type="button" value="To Page" onclick="javascript:window.location=\'?offset=\'+(parseInt(document.getElementById(\'num\').value)*20-20).toString()+\'&maxResults=20\';" /></form><br />'
  1229. +'<b><center style="margin-top:4px;margin-bottom:2px;">'+pages+'</center></b></small>';
  1230. utpanel.innerHTML = utpanel.innerHTML.replace('Previous','Prev');
  1231. }
  1232. }
  1233. catch (e) {
  1234. // alert(e.source + '\n' + e.message);
  1235. }
  1236.  
  1237. try {
  1238. panelsTemp = document.getElementById('gnSearch');
  1239. if (panelsTemp)
  1240. panelsTemp.innerHTML='<small>'+panelsTemp.innerHTML+'</small>';
  1241. }
  1242. catch (e) {
  1243. // alert(e.source + '\n' + e.message);
  1244. }