UnTaint Wiki Improvement Script-G

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

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