UnTaint Wiki Improvement Script-G

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

当前为 2014-07-21 提交的版本,查看 最新版本

  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.004
  6. // @include http://*.wikifoundry.com/thread*
  7. // @include http://*.wikifoundry.com/forum/*
  8. // @include http://*.wikifoundry.com/forum
  9. // @include http://*.wikifoundry.com/account/*/thread/*
  10. // @include http://*.wikifoundry.com/photo/*/thread/*
  11. // @include http://*.wikifoundry.com/video/*/thread/*
  12. // @include http://www.sarahconnorfans.com/thread*
  13. // @include http://www.sarahconnorfans.com/forum/*
  14. // @include http://www.sarahconnorfans.com/forum
  15. // @include http://www.sarahconnorfans.com/account/*/thread/*
  16. // @include http://www.sarahconnorfans.com/photo/*/thread/*
  17. // @include http://www.sarahconnorfans.com/video/*/thread/*
  18. // @include http://www.vampirediariesfanwiki.com/thread*
  19. // @include http://www.vampirediariesfanwiki.com/forum/*
  20. // @include http://www.vampirediariesfanwiki.com/forum
  21. // @include http://www.vampirediariesfanwiki.com/account/*/thread/*
  22. // @include http://www.vampirediariesfanwiki.com/photo/*/thread/*
  23. // @include http://www.vampirediariesfanwiki.com/video/*/thread/*
  24. // @include http://www.thegreysanatomywiki.com/thread*
  25. // @include http://www.thegreysanatomywiki.com/forum/*
  26. // @include http://www.thegreysanatomywiki.com/forum
  27. // @include http://www.thegreysanatomywiki.com/account/*/thread/*
  28. // @include http://www.thegreysanatomywiki.com/photo/*/thread/*
  29. // @include http://www.thegreysanatomywiki.com/video/*/thread/*
  30. // @include http://dexterwiki.sho.com/thread*
  31. // @include http://dexterwiki.sho.com/forum/*
  32. // @include http://dexterwiki.sho.com/forum
  33. // @include http://dexterwiki.sho.com/account/*/thread/*
  34. // @include http://dexterwiki.sho.com/photo/*/thread/*
  35. // @include http://dexterwiki.sho.com/video/*/thread/*
  36. // @include http://www.wikifoundrycentral.com/thread*
  37. // @include http://www.wikifoundrycentral.com/forum/*
  38. // @include http://www.wikifoundrycentral.com/forum
  39. // @include http://www.wikifoundrycentral.com/account/*/thread/*
  40. // @include http://www.wikifoundrycentral.com/photo/*/thread/*
  41. // @include http://www.wikifoundrycentral.com/video/*/thread/*
  42. // @include http://www.warriorcatclans2.com/thread*
  43. // @include http://www.warriorcatclans2.com/forum/*
  44. // @include http://www.warriorcatclans2.com/forum
  45. // @include http://www.warriorcatclans2.com/account/*/thread/*
  46. // @include http://www.warriorcatclans2.com/photo/*/thread/*
  47. // @include http://www.warriorcatclans2.com/video/*/thread/*
  48. // @include http://www.zombieprepwiki.com/thread*
  49. // @include http://www.zombieprepwiki.com/forum/*
  50. // @include http://www.zombieprepwiki.com/forum
  51. // @include http://www.zombieprepwiki.com/account/*/thread/*
  52. // @include http://www.zombieprepwiki.com/photo/*/thread/*
  53. // @include http://www.zombieprepwiki.com/video/*/thread/*
  54. // ==/UserScript==
  55. // =============================================================================
  56. // Don't edit past here unless you know what you're doing.
  57. // *** Original namespace and project: http://files.randomresources.org/projects/untaint
  58. // *** Original description: Reduces the taint. Thanks to the inhabitants of the tsccwiki. Credits: toasty2 and Gu1.
  59. // TinyEditor integration and script adaptation to FF 4+ and Chrome 11+ by: SurfingEagle
  60. // Additional contributions: I.John
  61. // This version is adapted to work with GreaseMonkey 0.9+, Firefox 4+, and Chrome 11+ Not currently tested in IE
  62. // TinyEditor home http://www.scriptiny.com/2010/02/javascript-wysiwyg-editor/
  63.  
  64. // Convenient functions
  65. Array.prototype.contains = function(obj){var i = this.length;while(i--){if (this[i] === obj) {return true;}} return false;}
  66.  
  67. // SE: switch to using localStorage
  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. /*
  98. // TBD completion at a later date
  99. if(!GM_setValue)
  100. {
  101. GM_setValue = function(key,val) {if (window.localStorage) localStorage.setItem(key,val);}
  102. GM_getValue = function(key) {if (window.localStorage) localStorage.getItem(key);}
  103. }
  104. */
  105. /*
  106. Developed by Robert Nyman, http://www.robertnyman.com
  107. Code/licensing: http://code.google.com/p/getelementsbyclassname/
  108. */
  109. var getElementsByClassName = function (className, tag, elm){
  110. if (document.getElementsByClassName) {
  111. getElementsByClassName = function (className, tag, elm) {
  112. elm = elm || document;
  113. var elements = elm.getElementsByClassName(className),
  114. nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
  115. returnElements = [],
  116. current;
  117. for(var i=0, il=elements.length; i<il; i+=1){
  118. current = elements[i];
  119. if(!nodeName || nodeName.test(current.nodeName)) {
  120. returnElements.push(current);
  121. }
  122. }
  123. return returnElements;
  124. };
  125. }
  126. else if (document.evaluate) {
  127. getElementsByClassName = function (className, tag, elm) {
  128. tag = tag || "*";
  129. elm = elm || document;
  130. var classes = className.split(" "),
  131. classesToCheck = "",
  132. xhtmlNamespace = "http://www.w3.org/1999/xhtml",
  133. namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
  134. returnElements = [],
  135. elements,
  136. node;
  137. for(var j=0, jl=classes.length; j<jl; j+=1){
  138. classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
  139. }
  140. try {
  141. elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
  142. }
  143. catch (e) {
  144. elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
  145. }
  146. while ((node = elements.iterateNext())) {
  147. returnElements.push(node);
  148. }
  149. return returnElements;
  150. };
  151. }
  152. else {
  153. getElementsByClassName = function (className, tag, elm) {
  154. tag = tag || "*";
  155. elm = elm || document;
  156. var classes = className.split(" "),
  157. classesToCheck = [],
  158. elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
  159. current,
  160. returnElements = [],
  161. match;
  162. for(var k=0, kl=classes.length; k<kl; k+=1){
  163. classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
  164. }
  165. for(var l=0, ll=elements.length; l<ll; l+=1){
  166. current = elements[l];
  167. match = false;
  168. for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
  169. match = classesToCheck[m].test(current.className);
  170. if (!match) {
  171. break;
  172. }
  173. }
  174. if (match) {
  175. returnElements.push(current);
  176. }
  177. }
  178. return returnElements;
  179. };
  180. }
  181. return getElementsByClassName(className, tag, elm);
  182. };
  183.  
  184. // following block handles returning to end of thread after a new post
  185. try {
  186. if (window['sessionStorage'] !== null)
  187. {
  188. var added_post = window.sessionStorage['added_post'];
  189. if (getSetting('return_on_post', 'true') == 'true' && added_post.length > 0)
  190. {
  191. if (added_post == 'scroll_down')
  192. {
  193. var doc = document;
  194. // http://james.padolsey.com/javascript/get-document-height-cross-browser/
  195. var h = Math.max(
  196. Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight),
  197. Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight),
  198. Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
  199. );
  200. window.scroll(0, h);
  201. window.sessionStorage['added_post'] = '';
  202. }
  203. else if (added_post == 'jump_end_of_thread')
  204. {
  205. var p = getElementsByClassName('paging')[0];
  206. if (p)
  207. {
  208. p = p.lastChild.previousSibling;
  209. while (p)
  210. {
  211. if (p.nodeType == 1 && p.innerHTML != 'Next' && (p.innerHTML == 'Last' || Number(p.innerHTML) <= 5))
  212. {
  213. window.sessionStorage['added_post'] = 'scroll_down';
  214. window.location.href = p.href;
  215. break;
  216. }
  217. p = p.previousSibling;
  218. }
  219. if (!p) window.sessionStorage['added_post'] = '';
  220. }
  221. else
  222. window.sessionStorage['added_post'] = '';
  223. }
  224. else
  225. window.sessionStorage['added_post'] = '';
  226. } // end if
  227. } // end if
  228. }
  229. catch (e) {
  230. if (window['sessionStorage'] !== null) window.sessionStorage['added_post'] = '';
  231. }
  232.  
  233. // Get Configuration (or set defaults)
  234. var ui_avatar_w = getSetting('ui_avatar_w', '50');
  235. var ui_hide_rater = (getSetting('ui_hide_rater', 'true') == 'true');
  236. var ui_user_filter = getSetting('ui_user_filter', 'ExampleUser1,ExampleUser2');
  237. var refresh_threadlist = Number(getSetting('refresh_threadlist', '0'));
  238. // newest values
  239. var ui_auto_tinyeditor = (getSetting('ui_auto_tinyeditor', 'true') == 'true');
  240. var ui_show_leftcolumn = (getSetting('ui_show_leftcolumn', 'false') == 'true');
  241. var ui_default_post_font = getSetting('ui_default_post_font', '12px Arial');
  242. var isChrome = /chrome/.test(navigator.userAgent.toLowerCase());
  243.  
  244. // SE: tiny editor related styles
  245. GM_addStyle('#input {border:none; margin:0; padding:0; font:12px "Courier New", Verdana; border:0} ' +
  246. // in te, removed left margin
  247. '.te {border:1px solid #bbb; padding:0 1px 1px; font:12px Verdana, Arial;} ' +
  248. // .te iframe change WYSIWYG background color e.g. background-color:#222222. Effects Chrome but in FF color is overridden by body style setting.
  249. '.te iframe {border:none; background-color:silver;} ' +
  250. '.teheader {height:31px; border-bottom:1px solid #bbb; background:url(http://wikifoundryattachments.com/xg-mfHLVZfdD7OErlv0NxQ55) repeat-x; padding-top:1px} ' +
  251. '.teheader select {float:left; margin-top:5px} ' +
  252. '.tefont {margin-left:5px; width:118px;} ' +
  253. '.tesize {margin-left:4px; width:42px;} ' +
  254. '.tecolor {margin-left:4px; width:84px;} ' +
  255. '.testyle {margin-left:3px; margin-right:12px; width:70px;} ' +
  256. '.tedivider {float:left; width:2px; height:30px; background:#ccc} ' +
  257. '.tecontrol {float:left; width:34px; height:30px; cursor:pointer; background-image:url(http://wikifoundryattachments.com/jjINLqTU68Po418uA2wLPw18521)} ' +
  258. '.tecontrol:hover {background-color:#fff; background-position:30px 0} ' +
  259. '.tefooter {height:32px; border-top:1px solid #bbb; background:#f5f5f5} ' +
  260. '.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} ' +
  261. '.toggle:hover {background-color:#fff} ' +
  262. '.resize {float:right; height:32px; width:32px; background:url(http://wikifoundryattachments.com/W_Ipj_QMRSXNr7FEg3Sz8A78) 15px 15px no-repeat; cursor:s-resize}');
  263. // #editor change WYSIWYG font color e.g. color:white, color:blue, etc. *** Does not work in Chrome. Chrome defaults to black
  264. GM_addStyle('#editor {cursor:text; margin:10px; color:black; font:'+ui_default_post_font+';}');
  265. // GM_addStyle('#iframe_editor {background-color:dimgray;}');
  266.  
  267. // SE: the following block "main" is inserted into the page
  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. // 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. // SE: 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 constructor
  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() { // please god forgive me for this ugly piece of code
  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','Gray','Silver','White','Pink','HotPink','LightCoral','Tomato','Crimson','Red','FireBrick','Maroon','OrangeRed','Orange','Yellow','Gold','Olive','Lime','Green','Cyan','Teal','Blue','Navy','Magenta','Purple'],
  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. // SE: 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. // 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. document.body.innerHTML += '<div style="width:350px;margin:15px auto 15px auto;background-color:black;color:white;"><form id="cfg" name="cfg">'
  1029. +'<fieldset><legend>UnTaint Settings</legend><small>'
  1030. +'<input name="ui_avatar_w" id="ui_avatar_w" type="text" size="2" /> Avatar width (pixels)<br /><br />'
  1031. +'<input name="ui_hide_rater" id="ui_hide_rater" type="checkbox" /> Hide \'Do you find this valuable?\'<br />'
  1032. // added ui_show_leftcolumn. The option to allow for the left navigation bar to remain
  1033. +'<input name="ui_show_leftcolumn" id="ui_show_leftcolumn" type="checkbox" /> Show left navigation<br />'
  1034. // added ui_auto_tinyeditor.
  1035. +'<input name="ui_auto_tinyeditor" id="ui_auto_tinyeditor" type="checkbox" /> Auto load WYSIWYG (\'off\' restores older tools)<br />'
  1036. // added ui_uncheck_watch_this_thread.
  1037. +'<input name="ui_uncheck_watch_this_thread" id="ui_uncheck_watch_this_thread" type="checkbox" /> Auto uncheck \'watch this thread\'<br />'
  1038. // added return_on_post.
  1039. +'<input name="return_on_post" id="return_on_post" type="checkbox" /> On new post, auto jump to end of thread<br /><br />'
  1040. +'Default editing font:<br />'
  1041. // added ui_default_post_font.
  1042. +'<input type="text" name="ui_default_post_font" id="ui_default_post_font" /><br /><br />'
  1043. +'Filter users\' posts:<br />'
  1044. +'<textarea name="ui_user_filter" id="ui_user_filter" cols="40" rows="2" ></textarea><br />'
  1045. +'<small>Note: Names must be exact and separated by commas.</small><br /><br />'
  1046. +'<input name="refresh_threadlist" id="refresh_threadlist" type="text" size="2" /> Thread list reload interval <small>(in seconds; 0 to disable)</small><br />'
  1047. +'<center><button type="button" onclick="cfg_save();window.location.reload();">Save</button></center>'
  1048. +'</small></fieldset></form></div>';
  1049.  
  1050. document.getElementById('ui_avatar_w').value = getSetting('ui_avatar_w', '50');
  1051. document.getElementById('ui_hide_rater').checked = (getSetting('ui_hide_rater', 'true') == 'true');
  1052. document.getElementById('ui_user_filter').value = getSetting('ui_user_filter', '');
  1053. document.getElementById('refresh_threadlist').value = getSetting('refresh_threadlist', '0');
  1054. // newer values
  1055. document.getElementById('ui_show_leftcolumn').checked = (getSetting('ui_show_leftcolumn', 'false') == 'true');
  1056. document.getElementById('ui_auto_tinyeditor').checked = (getSetting('ui_auto_tinyeditor', 'true') == 'true');
  1057. document.getElementById('ui_uncheck_watch_this_thread').checked = (getSetting('ui_uncheck_watch_this_thread', 'true') == 'true');
  1058. document.getElementById('ui_default_post_font').value = getSetting('ui_default_post_font', '12px Arial');
  1059. document.getElementById('return_on_post').checked = (getSetting('return_on_post', 'true') == 'true');
  1060. }
  1061.  
  1062. // Save Configuration
  1063. cfg_save = function()
  1064. {
  1065. putSetting('ui_user_filter', document.getElementById('ui_user_filter').value.replace(', ',',').replace('\n',''));
  1066. putSetting('ui_avatar_w', document.getElementById('ui_avatar_w').value);
  1067. putSetting('ui_hide_rater', document.getElementById('ui_hide_rater').checked);
  1068. putSetting('refresh_threadlist', document.getElementById('refresh_threadlist').value);
  1069. // newer values
  1070. putSetting('ui_show_leftcolumn', document.getElementById('ui_show_leftcolumn').checked);
  1071. putSetting('ui_auto_tinyeditor', document.getElementById('ui_auto_tinyeditor').checked);
  1072. putSetting('ui_uncheck_watch_this_thread', document.getElementById('ui_uncheck_watch_this_thread').checked);
  1073. putSetting('ui_default_post_font', document.getElementById('ui_default_post_font').value);
  1074. putSetting('return_on_post', document.getElementById('return_on_post').checked);
  1075. }
  1076. } // end config
  1077.  
  1078. try
  1079. {
  1080. // Always add setting funtions to page
  1081. var script = document.createElement('script');
  1082. script.type = 'text/javascript';
  1083. script.appendChild(document.createTextNode('('+ config +')();'));
  1084. if (document.head) document.head.appendChild(script);
  1085. // Add posting tools when they're relevant
  1086. var reply = getElementsByClassName('threadModify');
  1087. if (reply[0])
  1088. {
  1089. // SE: add 'main' to page when needed
  1090. script = document.createElement('script');
  1091. script.type = 'text/javascript';
  1092. script.appendChild(document.createTextNode('('+ main +')();'));
  1093. if (document.head) document.head.appendChild(script);
  1094. var eventFunctions = 'loadInitialize(0);' + (ui_auto_tinyeditor ? '' : 'posting_tools();');
  1095. for (i in reply)
  1096. {
  1097. // SE: loadInitialize() is critical to the post filter
  1098. if (reply[i].hasAttributes)
  1099. {
  1100. if (reply[i].innerHTML.search('WPC-action_editThreadPost') >= 0)
  1101. reply[i].setAttribute('onclick', 'loadOriginalPost(this);' + eventFunctions);
  1102. else if (reply[i].innerHTML.search('WPC-action_deleteThread') < 0)
  1103. reply[i].setAttribute('onclick', eventFunctions);
  1104. }
  1105. }
  1106. }
  1107. }
  1108. catch (e)
  1109. {
  1110. // alert(e.source + '\n' + e.message);
  1111. }
  1112.  
  1113. // User posts filter
  1114. // Modified "for loops" by I.Join to function in FF 4.x
  1115. try
  1116. {
  1117. if (document.getElementById('threadList'))
  1118. {
  1119. var td = document.getElementById('threadList').getElementsByTagName('td');
  1120. for(var a = 0; a < td.length; a++) // for (var a in td)
  1121. {
  1122. if (td[a].getElementsByTagName('a'))
  1123. {
  1124. var td2 = td[a].getElementsByTagName('a');
  1125. for(var b = 0; b < td2.length; b++) // for (var b in td2)
  1126. {
  1127. if (b == 2 && td2[b].innerHTML && ui_user_filter.split(',').contains(td2[b].innerHTML))
  1128. {
  1129. var tr = td2[2].parentNode.parentNode;
  1130. tr.setAttribute('title', tr.getElementsByClassName('WPC-action')[1].innerHTML+': \n'+tr.getElementsByClassName('threadText')[0].innerHTML);
  1131. 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>';
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }
  1137. }
  1138. catch (e)
  1139. {
  1140. // alert(e.source + '\n' + e.message);
  1141. }
  1142.  
  1143. // SE: Added a show left navigation bar option for those who want to add new pages and/or use the navigation bar.
  1144. if(ui_show_leftcolumn)
  1145. // Show navigation and narrow page
  1146. GM_addStyle('#leftColumn {margin-top:1px;}')
  1147. else
  1148. // Hide navigation/Widen page to the entire screen
  1149. GM_addStyle('#outer {padding-left:0 !important;}');
  1150. // ======== AESTHETIC CHANGES ========
  1151. GM_addStyle('#userBrand, #gNav, #gnMain, #gnAccount{height:20px !important; line-height:20px !important;}');
  1152. GM_addStyle('#pageContentInner{min-height:400px !important;padding-bottom:0;}');
  1153. // 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
  1154. GM_addStyle('#footer{display:none !important;} body{background-color:silver !important;} #WPC-bodyContentContainer{margin-bottom:-50px !important;}');
  1155. GM_addStyle('#relatedContent{font-size:80% !important;} #pageContentInner{padding-bottom:0 !important;}');
  1156. GM_addStyle('#gnPromoLinks {display:none;}'); // Hide search area
  1157.  
  1158. // Modify Nav-Bar:
  1159. // SE: fan chat restored for tscc wiki only
  1160. if (document.getElementById('gnMain'))
  1161. {
  1162. var menu = document.getElementById('gnMain');
  1163. m1 = document.createElement('li');
  1164. m1.innerHTML = '<span><a href="/thread">Threads</a></span>';
  1165. menu.insertBefore(m1, menu.childNodes[2]);
  1166. if (/tsccwiki.wikifoundry/i.test(window.location.host))
  1167. {
  1168. m2 = document.createElement('li');
  1169. m2.innerHTML = '<span><a href="http://tsccwiki.wikifoundry.com/page/TSCC+Fan+Chat">Fan Chat</a></span>';
  1170. menu.appendChild(m2);
  1171. }
  1172. }
  1173.  
  1174. // Hide "Do you find this valuable?"
  1175. if(ui_hide_rater)
  1176. {
  1177. GM_addStyle('.threadRater{display:none !important;}');
  1178. }
  1179. // Enlarge Avatars
  1180. GM_addStyle('img.imageSm{width:'+ui_avatar_w+'px;}');
  1181. // Remove Ads for those without Adblock+
  1182. GM_addStyle('#adsTop, .ads{display:none !important;}')
  1183.  
  1184. // Auto-refresh for Thread list
  1185. // SE: stripped the domain back to .com to accommodate custom wiki names and
  1186. // added $/m as it wasn't always evaluating to true when "thread" at eol
  1187. if (window.location.href.search(/\.com\/thread($|[^\/])/mi) >= 0 && refresh_threadlist > 0) // Auto refresh
  1188. setTimeout(function(){window.location.reload()}, refresh_threadlist*1000);
  1189. // Untaint Panel
  1190. try {var pages = (getElementsByClassName('paging')[0]) ? getElementsByClassName('paging')[0].innerHTML : ''; /* Page #'s */ }
  1191. catch (e) {/* alert(e.source + '\n' + e.message) */}
  1192.  
  1193. var panelsTemp = null;
  1194. try {
  1195. panelsTemp = document.getElementById('siteHeader');
  1196. if (panelsTemp)
  1197. panelsTemp.innerHTML+='<a name="top"></a>';
  1198. }
  1199. catch (e) {
  1200. // alert(e.source + '\n' + e.message);
  1201. }
  1202.  
  1203. try {
  1204. // SE: changed element from allContentInner to pageContentInner.
  1205. panelsTemp = document.getElementById('pageContentInner');
  1206. if (panelsTemp)
  1207. panelsTemp.innerHTML+='<a name="bottom"></a>'
  1208. +'<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>';
  1209. }
  1210. catch (e) {
  1211. // alert(e.source + '\n' + e.message);
  1212. }
  1213.  
  1214. try {
  1215. var utpanel = document.getElementById('untaintpanel');
  1216. if (utpanel)
  1217. {
  1218. // SE: Chrome is not responding to href="#bottom" needs window.scroll(0,document.height).
  1219. utpanel.innerHTML=''
  1220. +'<b>UnTaint | <small><sup><a href="#bottom" onclick="cfg_show();'+(isChrome ? 'setTimeout(function(){window.scroll(0,document.height)},100);':'')+'">Settings</a></sup></small></b><small>'
  1221. +'<div style="float:right;padding-right:5px;padding-top:2px;"><a href="#top">Top</a><br /><a href="#bottom"'+(isChrome ? ' onclick="window.scroll(0,document.height);"':'')+'>Bottom</a></div>'
  1222. +'<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 />'
  1223. +'<hr style="border-color:black;margin:1px;" />'
  1224. +'<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 />'
  1225. +'<b><center style="margin-top:4px;margin-bottom:2px;">'+pages+'</center></b></small>'
  1226. utpanel.innerHTML = utpanel.innerHTML.replace('Previous','Prev');
  1227. }
  1228. }
  1229. catch (e) {
  1230. // alert(e.source + '\n' + e.message);
  1231. }
  1232.  
  1233. try {
  1234. panelsTemp = document.getElementById('gnSearch');
  1235. if (panelsTemp)
  1236. panelsTemp.innerHTML='<small>'+panelsTemp.innerHTML+'</small>';
  1237. }
  1238. catch (e) {
  1239. // alert(e.source + '\n' + e.message);
  1240. }