LORCode Tools

Кнопка цитирования выделенного и панель тегов для LORCode

  1. // ==UserScript==
  2. // @name LORCode Tools
  3. // @description Кнопка цитирования выделенного и панель тегов для LORCode
  4. // @author Алексей Соловьев aka moscwich; Емельянов Эдуард aka Eddy_Em -- Fork && upgrade
  5. // @license Creative Commons Attribution 3.0 Unported
  6. // @version 0.0.3
  7. // @grant none
  8. // @namespace http://www.linux.org.ru/*
  9. // @namespace https://www.linux.org.ru/*
  10. // @include http://www.linux.org.ru/*
  11. // @include https://www.linux.org.ru/*
  12. // ==/UserScript==
  13.  
  14. // Based on MultiCodePanel 2.2 (v. 0.22)
  15. // http://al-moscwich.tk/tag/multicodepanel
  16.  
  17. /*
  18. * CHANGELOG
  19. *
  20. * 25.12.2014 Eddy_Em
  21. * Fixed bug with menu "sort tracker"
  22. * Warning! refresh your stylish rules to see normal menu
  23. *
  24. * 16.07.2014 Eddy_Em
  25. * Some little fixes with JS syntax + no quotes substitution in [inline]
  26. *
  27. * 16.05.2014 Eddy_Em
  28. * Fixed regular Maxcom's caprice with "tracker/?filter=all" instead of simple "tracker"
  29. *
  30. * 07.02.2014 Eddy_Em
  31. * Hiding of "Similar topics"
  32. *
  33. * 02.12.2013 Eddy_Em
  34. * Latex imaging + quotation
  35. *
  36. * 08.11.2013 Edward V. Emelianoff <eddy@sao.ru>
  37. * Add collapsing of large code blocks
  38. *
  39. * 13.02.2013 Eddy_Em
  40. * Add "replace quotes by quotes" to fight with hizel's shit
  41. *
  42. * 4.02.2013 Eddy_Em
  43. * Add "Show seconds in datetime"
  44. *
  45. * 14.12.2012 Eddy_Em
  46. * Fixed small bug with editing of topics
  47. *
  48. * 13.12.2012 Eddy_Em
  49. * Fixed bug with no panels in edit form
  50. * Fixed tag focusing
  51. * Modified [list] tag in case of nonempty selection
  52. *
  53. * 29.11.2012 Eddy_Em
  54. * Fixed problems with new LOR formatting
  55. * Now script works in tango too
  56. *
  57. * 22.11.2012 Eddy_Em
  58. * Fix problem with citing & add tags in block-quote
  59. *
  60. * 21.11.2012 Eddy_Em
  61. * Some little fixes + add global settings in user profile
  62. *
  63. * 19.11.2012 Eddy_Em
  64. * Some little fixes
  65. *
  66. * TODO:
  67. * - don't change <<>> to "" in [code] and [inline]
  68. * - changing of <<>> to "" in topic form
  69. * - direct change of user comment
  70. * - preview of links to images
  71. * - messages preview
  72. */
  73. (function(){
  74.  
  75. const TEST = false; // set to false in release
  76.  
  77. if(window.parent != window){
  78. unsafeWindow.console.log("INFRAME!!!");
  79. return;
  80. }
  81.  
  82. const pluginVersion = "0.0.3"; // версия скрипта; нужна для оповещения при внесении изменений
  83.  
  84. unsafeWindow.console.log("start");
  85. function tlog__(msg){unsafeWindow.console.log(msg);}
  86. var tlog;
  87. if(TEST) tlog = tlog__;
  88. else tlog = function(msg){};
  89.  
  90. /*
  91. * GLOBAL FUNCTIONS
  92. */
  93. tlog("begin");
  94. var Glob; // global settings
  95. /*
  96. * Load object nm from local storage
  97. * if it's absent set it to defval or return null if devfal undefined
  98. */
  99. function LoadObject(nm, defval){
  100. var val = JSON.parse(localStorage.getItem(nm));
  101. if(val == null && typeof(defval) != "undefined"){
  102. tlog("Can't load object, try to use defaults");
  103. val = defval;
  104. }
  105. return val;
  106. }
  107. /*
  108. * Save object obj in local storage as nm
  109. */
  110. function SaveObject(obj, nm){
  111. tlog("save " + obj);
  112. localStorage.setItem(nm, JSON.stringify(obj));
  113. }
  114.  
  115. function $(id){
  116. return document.getElementById(id);
  117. }
  118. function noDef(evt){ // remove default event action
  119. evt.stopPropagation();
  120. evt.preventDefault();
  121. }
  122. function rmElement(el){ // remove element from DOM tree
  123. if(typeof(el) != "undefined" && el)
  124. el.parentNode.removeChild(el);
  125. }
  126. function getURL(full){ // get URL of current page
  127. // if full defined && true, don't cut GET parameters from URL
  128. var qpos, CurURL = location.href;
  129. if(typeof(full) == "undefined" || !full){
  130. qpos = CurURL.indexOf("?");
  131. if(qpos > -1) CurURL = CurURL.substring(0,qpos);
  132. }
  133. qpos = CurURL.indexOf("//") + 2;
  134. CurURL = CurURL.substring(qpos);
  135. if(CurURL.charAt(CurURL.length - 1) == "/")
  136. CurURL = CurURL.substring(0,CurURL.length - 1);
  137. return CurURL;
  138. }
  139. // insert newElement after targetElement
  140. function insertAfter(newElement, targetElement){
  141. var parent = targetElement.parentNode;
  142. if(parent.lastchild == targetElement)
  143. parent.appendChild(newElement);
  144. else
  145. parent.insertBefore(newElement, targetElement.nextSibling);
  146. }
  147. // indicate that iframe content is loaded
  148. var iframeLoaded = false, nTries = 0;
  149. function iframeIsLoaded(){
  150. var F = $("innerFrame");
  151. if (F.src == "") return;
  152. var D = (F.contentDocument) ? F.contentDocument : F.contentWindow.document;
  153. if(D.getElementsByClassName("head").length == 0 && D.getElementsByClassName("menu").length == 0){
  154. nTries = 100; return; // frame is blocked by AdBlock
  155. }
  156. iframeLoaded = true; nTries = 0;
  157. tlog("IFRAME loaded " + F.src);
  158. }
  159. // alert that iframe could be blocked by adBlock
  160. function IFRMerror(){
  161. tlog("CAN'T LOAD IFRAME!");
  162. alert("Не могу подгрузить дополнительные сообщения!\n"+
  163. "Проверьте, не блокирует ли adBlock элементы iframe на ЛОРе\n"+
  164. "(нажмите в меню adBlock \"Открыть список элементов\" и снимите "+
  165. "блокировку с элемента \"фрейм\"");
  166. }
  167. /*
  168. * USERSCRIPT ITSELF
  169. */
  170. function AlertOnFirstRun(){
  171. alert("Вы запускаете в первый раз LOR-panel, либо обновили ее!\n"
  172. +"Обратите внимание на то, что настройки скрипта находятся в вашем профиле"
  173. +"(«Настройки пользовательского скрипта»)\n"
  174. +"для полноценного отображения меню добавьте в ЛОР-стиль Stylish следующее:\n\n"
  175. +".SortTrackMenu{position: absolute; margin: auto;"
  176. +"background: none repeat scroll 0 0 #0000ff !important; text-align: left;}\n"
  177. +".SortTrackMenuItem{left: 0px; margin: 1px; background-color: #c0c0c0 !important; color: black;}\n\n"
  178. +"либо что-нибудь свое"
  179. )
  180. SaveObject(pluginVersion, "LOR-panel.version");
  181. }
  182. var savedVersion = LoadObject("LOR-panel.version", false);
  183. if(pluginVersion != savedVersion) AlertOnFirstRun();
  184. // parent with class "msg" for element el of first element with class "msg"
  185. function getMsg(el){
  186. while(el && el.className != "msg") el = el.parentElement;
  187. if(!el) el = document.getElementsByClassName("msg")[0];
  188. return el;
  189. }
  190. // get URL of message, aMsg -- article element
  191. function getMsgURL(aMsg){
  192. aMsg = getMsg(aMsg);//while(aMsg.className != "msg") aMsg = aMsg.parentElement;
  193. var id = aMsg.id;
  194. var href = "";
  195. if(id.indexOf("topic") != -1){ // topic
  196. var H = aMsg.getElementsByTagName("h1");
  197. if(H.length > 0) href = H[0].firstElementChild.href;
  198. }else{ // message
  199. //href = pMsg.firstElementChild.firstElementChild.href;
  200. var As = aMsg.getElementsByTagName("a");
  201. for(var l in As)
  202. if(As[l].innerHTML == "Ссылка"){href = As[l].href; break;}
  203. //href = pMsg.getElementsByClassName("reply")[0].firstElementChild.lastElementChild.firstElementChild.href;
  204. }
  205. return href;
  206. }
  207.  
  208. /*
  209. * Global settings
  210. */
  211. function GlobSettings(){
  212. function nope(){};
  213. // array: item name, defval, menu name, appr. function
  214. var GMitems = [ ["addSortMenu", true, "фильтрация трекера", addSortMenu],
  215. ["rmAttInAll", false, "удалить прикрепленные везде", rmAttInAll],
  216. ["rmAttInTalks", true, "удалить прикрепленные только в Talks", rmAttInTalks],
  217. ["expandCollapseCODE", true, "сворачивать большие блоки CODE", expandCollapseCODE],
  218. //["tagsInSpoiler",true, "помещать теги в профиле в спойлер", mkSpoiler], Broken by Maxcom & Hizel
  219. // ["noSymbols", true, "удалить «страшный глаз»", idioticSymbolsRemove], Мне глаз нужен
  220. ["addUserPanel" ,true, "добавить пользовательскую панель", AddUserPanel],
  221. ["showSeconds", true, "отображать секунды в дате", ShowSecondsInDate],
  222. ["reparceQuots",false, "заменять кавычки кавычками", nope],
  223. ["SortBackwards", false, "отображать новые сообщения первыми", SortBackwards],
  224. ["HideSimilar", true, "скрывать «Похожие темы»", HideSimilar]
  225. ];
  226. var milen = GMitems.length;
  227. var i, defvar = new Object();
  228. for(i = 0; i < milen; i++) defvar[GMitems[i][0]] = GMitems[i][1];
  229. Glob = LoadObject("GlobalLORoptions", defvar);
  230. if(TEST)for(i = 0; i < milen; i++) tlog("GL["+GMitems[i][0]+"] = "+Glob[GMitems[i][0]]);
  231. if(location.href == getProfile()){tlog("Load global menu"); UserGlobMenu();}
  232. for(i = 0; i < milen; i++)
  233. if(Glob[GMitems[i][0]])GMitems[i][3]();
  234. function getProfile(){ // check whether this is "black" or "tango" → get URL of user's profile
  235. var hd = document.getElementsByClassName("head");
  236. if(hd.length > 0){
  237. var ankor = hd[0].getElementsByTagName("a");
  238. if(ankor.length > 1) return ankor[1].href; // black
  239. }
  240. // no? maybe tango ???
  241. var grt = $("loginGreating");
  242. if(typeof(grt) != "undefined"){
  243. var ankor = grt.getElementsByTagName("a");
  244. if(ankor.length > 0) return ankor[0].href; // tango
  245. }
  246. unsafeWindow.console.log("Incorrect style or document");
  247. return "";
  248. }
  249. function UserGlobMenu(){
  250. function onkey(evt){
  251. noDef(evt);
  252. if(evt.keyCode != 27) return;
  253. menuShowHide();
  254. }
  255. var oldkeyd;
  256. function menuShowHide(){
  257. var M = $('UserSettingsButton').nextSibling;
  258. if(M.style.display != "block"){
  259. M.style.display = "block";
  260. oldkeyd = document.body.onkeydown;
  261. document.body.onkeydown = onkey;
  262. return;
  263. }else{
  264. document.body.onkeydown = oldkeyd;
  265. M.style.display = "none";
  266. var boxes = M.getElementsByTagName("input");
  267. for(var b in boxes){
  268. var B = boxes[b];
  269. if(B.type != "checkbox") continue;
  270. Glob[B.id] = B.checked;
  271. }
  272. SaveObject(Glob, "GlobalLORoptions");
  273. }
  274. }
  275. function SaveMenu(evt){
  276. noDef(evt);
  277. menuShowHide();
  278. return;
  279. }
  280. function genMenuBoxes(parent){ // generate menu
  281. for(var i = 0; i < milen; i++){
  282. var str = document.createElement('div');
  283. str.className = "SortTrackMenuItem";
  284. var inp = document.createElement('input'); inp.type = "checkbox";
  285. inp.id = GMitems[i][0]; inp.checked = Glob[GMitems[i][0]];
  286. str.appendChild(inp);
  287. var txt = document.createTextNode(GMitems[i][2]);
  288. str.appendChild(txt);
  289. parent.appendChild(str);
  290. }
  291. }
  292. var ul, found = false, h2 = document.getElementsByTagName("h2");
  293. for(var el in h2)
  294. if(h2[el].innerHTML == "Действия"){
  295. found = true; ul = h2[el].nextElementSibling; break;
  296. }
  297. if(!found) return;
  298. var msi = document.createElement('li');
  299. var mitem = document.createElement('a');
  300. mitem.href = "'#'"; mitem.innerHTML = "Настройки пользовательского скрипта";
  301. mitem.id = "UserSettingsButton"; mitem.onclick = SaveMenu;
  302. msi.appendChild(mitem);
  303.  
  304. var Smenu = document.createElement('div');
  305. Smenu.className = "UserSettingsMenu";
  306. Smenu.style.display = "none";
  307. genMenuBoxes(Smenu);
  308. msi.appendChild(Smenu);
  309. ul.appendChild(msi);
  310. }
  311. }
  312. tlog("BEFORE");
  313. GlobSettings();
  314. tlog("AFTER");
  315.  
  316. /*
  317. * Expand/collapse large (more than 6 lines) code blocks
  318. */
  319. function expandCollapseCODE(){
  320. tlog("expandCollapseCODE()");
  321. var Code_blocks = document.getElementsByTagName("code");
  322. function codeshowhihide(E){
  323. if(E.style.maxHeight == "100px"){
  324. E.style.maxHeight = "";
  325. E.title = "Click to collapse";
  326. }else{
  327. E.style.maxHeight = "100px";
  328. E.title = "Click to expand";
  329. }
  330. }
  331. function ShowBlk(e){
  332. var E = e.target;
  333. if(E.tagName != "PRE") E = E.parentNode;
  334. codeshowhihide(E);
  335. }
  336. for(var i in Code_blocks){
  337. var tN = Code_blocks[i].tagName;
  338. if(tN != "CODE") continue;
  339. var lines = Code_blocks[i].textContent.split("\n");
  340. if(lines.length < 6) continue;
  341. var P = Code_blocks[i].parentNode;
  342. codeshowhihide(P);
  343. P.style.overflowY = "auto";
  344. P.onclick = ShowBlk;
  345. }
  346. }
  347.  
  348. /*
  349. * sort tracker
  350. */
  351. function addSortMenu(){
  352. tlog("addSortMenu()");
  353. var CurURL = getURL(true); // don't sort sorted tracker
  354. tlog("URL: "+CurURL);
  355. if(CurURL.indexOf("www.linux.org.ru/tracker") == -1) return;
  356. const maxElems = 50; // maximum amount of records in tracker
  357. var WasSorted = false; // whether tracker was sorted?
  358. var menuitems = ["general", "desktop", "admin", "linux-install", "development",
  359. "linux-org-ru", "security", "linux-hardware", "talks", "science", "job",
  360. "games", "web-development", "lor-source", "mobile",
  361. "multimedia", "midnight"];
  362. var milen = menuitems.length;
  363. var ichkd = LoadObject("FilterTracker");
  364. if(!ichkd) ichkd = new Array();
  365. var ichkdlen = ichkd.length;
  366. var TotalElements = 0;
  367. function onkey(evt){ // Sort tracker by ESC
  368. noDef(evt);
  369. if(evt.keyCode != 27) return;
  370. menuShowHide();
  371. }
  372. function getCheckedItems(){ // save checked menu items in local storage
  373. ichkd = [];
  374. for(var i = 0; i < milen; i++)
  375. if($('MB'+i).checked)
  376. ichkd.push(i);
  377. ichkdlen = ichkd.length;
  378. SaveObject(ichkd, "FilterTracker");
  379. }
  380. function checkHref(a, tbl){ // check if topic is selected
  381. var H = a.href;
  382. var addEl = (typeof(tbl) != "undefined"); // whether add needed or remove unneeded
  383. if(H.charAt(H.length - 1) == "/") // cut forum name
  384. H = H.slice(0,-1);
  385. var slashpos = H.lastIndexOf("/");
  386. H = H.slice(slashpos+1);
  387. var found = false;
  388. for(var i = 0; i < ichkdlen; i++)
  389. if(H == menuitems[ichkd[i]]){
  390. found = true; break;
  391. }
  392. if(!found){
  393. if(!addEl) rmElement(a.parentNode.parentNode);
  394. }else{
  395. TotalElements++;
  396. if(addEl)
  397. tbl.appendChild(a.parentNode.parentNode);
  398. }
  399. }
  400. function genMenuBoxes(parent){ // generate menu
  401. var i;
  402. for(i = 0; i < milen; i++){
  403. var str = document.createElement('div');
  404. str.className = "SortTrackMenuItem";
  405. var inp = document.createElement('input'); inp.type = "checkbox";
  406. inp.onclick = function(){menuwaschanged = true;}; inp.id = "MB"+i;
  407. str.appendChild(inp);
  408. var txt = document.createTextNode(menuitems[i]);
  409. str.appendChild(txt);
  410. parent.appendChild(str);
  411. }
  412. }
  413. /*
  414. * Добавить в Stylish для ЛОРа [ОБЯЗАТЕЛЬНО!]:
  415. .SortTrackMenu{position: absolute; margin: auto;
  416. background: none repeat scroll 0 0 #0000ff !important; text-align: left;}
  417. .SortTrackMenuItem{left: 0px; margin: 1px; background-color: #c0c0c0 !important; color: black;}
  418. */
  419. function appendMenu(genmenu){ // add menu
  420. //var menu = document.getElementsByClassName('nav-buttons')[0];
  421. var menu = document.getElementsByTagName('nav')[0];
  422. //var C = menu.firstElementChild;
  423. //var unneed = C.firstElementChild;
  424. var unneed = menu.firstElementChild;
  425. var msi = document.createElement('span');
  426. var mitem = document.createElement('a');
  427. mitem.href = "'#'"; mitem.innerHTML = "Фильтрация";
  428. mitem.id = "SortTrackerButton";
  429. //if(unneed.getElementsByClassName("current").length)mitem.className = "current";
  430. mitem.className = "btn btn-default";
  431. if(genmenu) mitem.onclick = SortTracker;
  432. msi.appendChild(mitem);
  433. if(genmenu){
  434. var Smenu = document.createElement('div');
  435. Smenu.className = "SortTrackMenu";
  436. Smenu.style.display = "none";
  437. genMenuBoxes(Smenu);
  438. msi.appendChild(Smenu);
  439. }else mitem.href = "/tracker";
  440. //C.insertBefore(msi, C.firstChild);
  441. menu.insertBefore(msi, unneed);
  442. rmElement(unneed);
  443. for(i = 0; i < ichkdlen; i++)
  444. $("MB"+ichkd[i]).checked = "true";
  445. }
  446. if(CurURL != "www.linux.org.ru/tracker"){
  447. appendMenu(false);
  448. return;
  449. }
  450. appendMenu(true);
  451. // create iframe
  452. var innerFrame = document.createElement('iframe');
  453. innerFrame.id = "innerFrame";
  454. innerFrame.width = 0; innerFrame.height = 0; innerFrame.style.display = "none";
  455. document.body.appendChild(innerFrame);
  456. innerFrame.onload = iframeIsLoaded;
  457. innerFrame.src = "/tracker/?offset=50";
  458. function collectHrefs(doc, tbl){ // add more topics from iframe
  459. function chkA(A){
  460. if(typeof(A) != "undefined" && typeof(A.href) != "undefined" && A.parentNode.nodeName == "TD")
  461. checkHref(A, tbl);
  462. }
  463. var i, hrefs = doc.getElementsByClassName("secondary");
  464. if(typeof(tbl) == "undefined")
  465. for(i = hrefs.length-1; i > -1; i--){
  466. if(TotalElements >= maxElems) return;
  467. chkA(hrefs[i]);
  468. }
  469. else
  470. for(i in hrefs){
  471. if(TotalElements >= maxElems) return;
  472. chkA(hrefs[i]);
  473. }
  474. }
  475. var Wto;
  476. function AddMoreItems(){ // find table with topics & try to add to it more items
  477. clearTimeout(Wto);
  478. if(!iframeLoaded){
  479. if(nTries > 10){
  480. IFRMerror();
  481. return;
  482. }
  483. nTries++;
  484. Wto = setTimeout(AddMoreItems, 300);
  485. return;
  486. }
  487. mTbl = document.getElementsByClassName("message-table")[0];
  488. if(typeof(mTbl) == "undefined") return;
  489. var chlds = mTbl.childNodes;
  490. for(var n in chlds)
  491. if(chlds[n].nodeName == "TBODY"){
  492. mTbl = chlds[n];
  493. break;
  494. }
  495. var innerDoc = (innerFrame.contentDocument) ? innerFrame.contentDocument : innerFrame.contentWindow.document;
  496. var hrefs = innerDoc.getElementsByClassName("secondary");
  497. collectHrefs(innerDoc, mTbl);
  498. }
  499. function StartSorting(){ // Start filtering of tracker
  500. var nav = document.getElementsByClassName("nav");
  501. rmElement(nav[nav.length - 1]); // remove navigation since it won't work
  502. WasSorted = true;
  503. TotalElements = 0;
  504. collectHrefs(document);
  505. if(TotalElements < 50){
  506. if(!iframeLoaded){
  507. nTries = 0;
  508. Wto = setTimeout(AddMoreItems, 300);
  509. }
  510. else
  511. AddMoreItems();
  512. }
  513. }
  514. var oldkeyd;
  515. var menuwaschanged = false;
  516. function menuShowHide(){ // show menu || start filtering
  517. var M = $('SortTrackerButton').nextSibling;
  518. if(M.style.display != "block"){
  519. menuwaschanged = false;
  520. M.style.display = "block";
  521. oldkeyd = document.body.onkeydown;
  522. document.body.onkeydown = onkey;
  523. return;
  524. }
  525. if(!menuwaschanged){
  526. document.body.onkeydown = oldkeyd;
  527. M.style.display = "none";
  528. return;
  529. }
  530. getCheckedItems();
  531. location.reload(true);
  532. document.location.reload(true);
  533. }
  534. function SortTracker(evt){ // menu's "onclick"
  535. noDef(evt);
  536. menuShowHide();
  537. return false;
  538. }
  539. if(ichkdlen) StartSorting();
  540. }
  541. /*
  542. * Remove glued topics
  543. */
  544. var filtered = false;
  545. function goodtalks(isAll){
  546. tlog("goodtalks()");
  547. var CurURL = getURL();
  548. if(isAll){
  549. var pos = CurURL.indexOf("/"), count;
  550. for(count = 0; pos != -1; count++)
  551. pos = CurURL.indexOf("/", pos + 1);
  552. if(count != 2) return; // remove attached anywhere
  553. }else
  554. if(CurURL != "www.linux.org.ru/forum/talks" && !filtered) return;
  555. var i, blk = document.getElementsByClassName("infoblock");
  556. for(i = blk.length-1; i > -1; i--){
  557. rmElement(blk[i]);
  558. }
  559. blk = document.getElementsByTagName("td");
  560. // remove attached
  561. for(i = blk.length-1; i > -1; i--){
  562. for (var c in blk[i].children){
  563. var C = blk[i].children[c];
  564. if(C.nodeName == "IMG" && C.title == "Прикреплено"){
  565. rmElement(blk[i].parentNode);
  566. break;
  567. }
  568. }
  569. }
  570. filtered = true;
  571. }
  572. function rmAttInAll(){
  573. goodtalks(true);
  574. }
  575. function rmAttInTalks(){
  576. goodtalks(false);
  577. }
  578. /*
  579. * button "knock-knock!"
  580. */
  581. var knockHref = "", badHref = "";
  582. function knock_knock(e){
  583. tlog("knock-knock!");
  584. noDef(e);
  585. var T = e.target;
  586. rmElement($("RePoRtFoRm"));
  587. rmElement($("cnockFrame"));
  588. if(knockHref == ""){
  589. var iF = document.createElement('iframe');
  590. iF.id = "innerFrame";
  591. iF.width = 0; iF.height = 0; iF.style.display = "none";
  592. document.body.appendChild(iF);
  593. iF.onload = iframeIsLoaded;
  594. iF.src = "/forum/linux-org-ru/";
  595. var Wto = setTimeout(LORready, 300);
  596. return false;
  597. }else MKmalyava();
  598. function LORready(){
  599. clearTimeout(Wto);
  600. if(!iframeLoaded){
  601. if(nTries > 10){
  602. rmElement($("innerFrame"));
  603. IFRMerror();
  604. return;
  605. }
  606. nTries++;
  607. Wto = setTimeout(LORready, 300);
  608. return;
  609. };
  610. var iF = $("innerFrame");
  611. var D = (iF.contentDocument) ? iF.contentDocument : iF.contentWindow.document;
  612. var i, blk = D.getElementsByTagName("td");
  613. for(i in blk){
  614. for (var c in blk[i].children){
  615. var C = blk[i].children[c];
  616. if(C.nodeName == "I"){
  617. var A = C.nextElementSibling;
  618. if(A.nodeName == "I") // пропускаем знак "Решето"
  619. A = A.nextElementSibling;
  620. tlog(A.innerHTML);
  621. if(A.innerHTML.indexOf("Ссылки на некорректные сообщения") > -1){
  622. var hr = A.href.replace(/.*\//,"");
  623. knockHref = "/comment-message.jsp?topic=" + hr.replace(/\?.*/, "");
  624. i = blk.length + 1;
  625. }
  626. break;
  627. }
  628. }
  629. }
  630. rmElement(iF);
  631. if(knockHref != "") MKmalyava();
  632. }
  633. var pMsg;
  634. function MKmalyava(){
  635. var i, href = "";
  636. pMsg = T;
  637. while(pMsg.className != "msg") pMsg = pMsg.parentElement;
  638. href = getMsgURL(pMsg);
  639. if(href == ""){ alert("Упс. Ссылка потерялась!"); return;}
  640. badHref = href;
  641. var iF = document.createElement('iframe');
  642. iF.id = "cnockFrame";
  643. iF.width = 0; iF.height = 0; iF.style.display = "none";
  644. document.body.appendChild(iF);
  645. iF.onload = fillFrame;
  646. iF.src = knockHref;
  647. }
  648. function fillFrame(){
  649. var iF = $("cnockFrame");
  650. var D = (iF.contentDocument) ? iF.contentDocument : iF.contentWindow.document;
  651. var msg, form = D.getElementById("commentForm");
  652. if(typeof(form) == "undefined" || form == null){
  653. alert("Ошибка загрузки формы"); rmElement(iF); return;
  654. }
  655. var F = document.createElement('div');
  656. F.style.border = "2px dotted"; F.style.padding = "5px";
  657. F.id = "RePoRtFoRm";
  658. //F.innerHTML = form.outerHTML;
  659. F.innerHTML = "<textarea id=\"RepMsg\" required=\"\" cols=\"100\" rows=\"5\"></textarea>"+
  660. "<br><br><button id=\"putMSG\">Поместить</button>&nbsp;&nbsp;"+
  661. "<button id=\"cnslMSG\">Отмена</button>";
  662. insertAfter(F, pMsg);
  663. $("putMSG").onclick = sbmForm;
  664. $("cnslMSG").onclick = rmForm;
  665. msg = $("RepMsg");
  666. msg.value = "Некорректное сообщение:\n\n" + badHref;
  667. msg.focus();
  668. }
  669. function rmForm(){rmElement($("RePoRtFoRm")); rmElement($("cnockFrame"));}
  670. function sbmForm(){
  671. var iF = $("cnockFrame");
  672. iF.onload = delFrm;
  673. var D = (iF.contentDocument) ? iF.contentDocument : iF.contentWindow.document;
  674. var form = D.getElementById("commentForm");
  675. var msg = D.getElementById("msg");
  676. var ori = $("RepMsg");
  677. msg.value = ori.value;
  678. rmElement($("RePoRtFoRm"));
  679. form.submit();
  680. }
  681. function delFrm(){rmElement($("cnockFrame")); alert("Жалоба принята");}
  682. return false;
  683. }
  684.  
  685. /*
  686. * Spoiler-like show/hide tags in profile
  687. */
  688. function mkSpoiler(){
  689. tlog("mkSpoiler()");
  690. function SwitchVis(e){
  691. var F = e.target;
  692. if(F.nodeName == "LEGEND") F = F.parentNode;
  693. if(F.nodeName != "FIELDSET") return;
  694. noDef(e);
  695. for (var c in F.children) {
  696. var C = F.children[c];
  697. if(C.nodeName != "LEGEND" && C.nodeType == 1)
  698. C.style.display = (C.style.display == "none") ? "block" : "none";
  699. }
  700. }
  701. var fields = document.getElementsByTagName("fieldset");
  702. var L = fields.length;
  703. for(var i = 0; i < L; i++){
  704. var F = fields[i];
  705. var invis = 0;
  706. for (var c in F.children) {
  707. var C = F.children[c];
  708. if(C.nodeName == "LEGEND" && C.innerHTML.indexOf("теги") > -1){
  709. invis = 1;
  710. F.onclick = SwitchVis;
  711. C.onclick = SwitchVis;;
  712. }else{
  713. str = "invis = " + invis + " text = " + C.innerHTML + " type=" + C.nodeType;
  714. if(invis && C.nodeType == 1){
  715. C.style.display = "none";
  716. }
  717. }
  718. }
  719. }
  720. }
  721.  
  722. /*
  723. * Remove idiot symbols of quasy-eye and so on
  724. */
  725. function idioticSymbolsRemove(){
  726. tlog("idioticSymbolsRemove()");
  727. // original of next functions was snatched from LOR code, don't beat me for it!s
  728. if(!$("memories_count") || !$("favs_count")) return;
  729. var memcntr = Number($("memories_count").innerHTML);
  730. var favcntr = Number($("favs_count").innerHTML);
  731. function memories_add(event, id, w) {
  732. event.preventDefault();
  733. var target = $(id);
  734. var evt = document.createEvent("MouseEvents");
  735. evt.initEvent("click", true, true);
  736. target.dispatchEvent(evt);
  737. memories_form_setup(w,0);
  738. }
  739. function memories_remove(event, id, w){
  740. event.preventDefault();
  741. var target = $(id);
  742. var evt = document.createEvent("MouseEvents");
  743. evt.initEvent("click", true, true);
  744. target.dispatchEvent(evt);
  745. memories_form_setup(w,0);
  746. }
  747. function memories_form_setup(watch, clear) {
  748. var el, Id, ParentId, text;
  749. var memcntr = Number($("memories_count").innerHTML);
  750. var favcntr = Number($("favs_count").innerHTML);
  751. if (watch){
  752. Id = 'memories0_button';
  753. ParentId = 'memories_button';
  754. }else{
  755. Id = 'favs0_button';
  756. ParentId = 'favs_button';
  757. }
  758. el = $(Id);
  759. if(typeof(clear) != "undefined"){
  760. text = "Подождите, пожалуйста";
  761. }else{
  762. parCls = $(ParentId).className;
  763. if (parCls=="") {
  764. text = watch?"Отслеживать ("+memcntr+")":"В избранное ("+favcntr+")";
  765. el.onclick = function(evt){ memories_add(evt, ParentId,watch);};
  766. } else {
  767. text = watch?"Не отслеживать ("+memcntr+")":"Удалить из избранного ("+favcntr+")";
  768. el.onclick = function(evt){ memories_remove(evt, ParentId,watch);};
  769. }
  770. }
  771. el.title = text;
  772. el.innerHTML = text;
  773. }
  774. var NonShown = document.getElementsByClassName("fav-buttons");
  775. for(var i=0,j=NonShown.length; i<j; i++) NonShown[i].style.display = "none";
  776. var TM = $("topicMenu");
  777. if(!TM) return; // edit topic
  778. var favs = document.createElement("li");
  779. var mems = document.createElement("li");
  780. favs.innerHTML = "<a id='favs0_button' href='#'></a>";
  781. mems.innerHTML = "<a id='memories0_button' href='#'></a>";
  782. TM.appendChild(favs);
  783. TM.appendChild(mems);
  784. var Itimeout = window.setInterval(initForms, 300);
  785. function initForms(){
  786. clearInterval(Itimeout);
  787. memories_form_setup(false);
  788. memories_form_setup(true);
  789. Itimeout = window.setInterval(initForms, 3000);
  790. }
  791. var shit = document.getElementsByClassName("icon-tag");
  792. if(shit.length > 0) for(var i = shit.length - 1; i > -1; i--) rmElement(shit[i]);
  793. }
  794.  
  795. /*
  796. * Format datetime
  797. */
  798. function ShowSecondsInDate(){
  799. tlog("ShowSecondsInDate()");
  800. var Tt = document.getElementsByTagName("time");
  801. for(var T in Tt){
  802. var A = Tt[T].attributes;
  803. if(!A || !A.datetime) continue;
  804. var aDate = new Date(A.datetime.value);
  805. Tt[T].innerHTML = aDate.toLocaleDateString() + " " + aDate.toLocaleTimeString();
  806. }
  807. }
  808.  
  809. function SortBackwards(){
  810. var comments = document.getElementsByClassName("msg");
  811. var nav = $("comments");
  812. var L = comments.length;
  813. for(var l = L - 1; l > 0; l--)
  814. nav.appendChild(comments[l]);
  815. }
  816.  
  817. function HideSimilar(){
  818. rmElement($("related-topics"));
  819. }
  820.  
  821. /*
  822. * Script originally written by moscwich
  823. */
  824. function AddUserPanel(){
  825. tlog("AddUserPanel()");
  826. function removeElements () {
  827. tlog("remove "+arguments.length+" elements");
  828. for (i = arguments.length-1; i > -1; i--) {
  829. var p = arguments[i].parentNode;
  830. if (p) p.removeChild (arguments[i]);
  831. }
  832. }
  833. function set (p, z) {
  834. for (i = 0; i < arguments.length && (arguments[i] === undefined); i++) {}
  835. return arguments[i];
  836. }
  837.  
  838. i = j = undefined;
  839. a = b = undefined;
  840.  
  841. form = document.getElementById ("commentForm") || document.getElementById ("messageForm") || document.getElementById ("changeForm").getElementsByTagName ("label")[7];
  842. msg = document.getElementById ("msg") || document.getElementById ("form_msg") || document.getElementById ("info");
  843. var u = window.location.href;
  844.  
  845. // Panel
  846. var panel = document.createElement ("div");
  847. panel.id = 'atag';
  848. panel.createBlock =
  849. function () {
  850. block = document.createElement ("span");
  851. for (i = 0; i < arguments.length; i++) {
  852. link = document.createElement ("a");
  853. link.textContent = arguments[i][0];
  854. link.title = arguments[i][1];
  855. link.exec = arguments[i][2];
  856. link.onclick = function(e){
  857. noDef(e)
  858. eval(this.exec);
  859. return false;
  860. }
  861. block.appendChild (link);
  862. }
  863. return this.appendChild (block);
  864. }
  865. panel.createBlock (
  866. ["[b]", "Полужирный", 'intag ("b");']
  867. ,["[i]", "Курсив", 'intag ("i");']
  868. ,["[s]", "Зачеркнутый", 'intag ("s");']
  869. /* ,["[u]", "Подчеркнутый", 'intag ("u");']*/
  870. );
  871. panel.createBlock (
  872. ["[quote]", "Цитата", 'intag ("quote", "\\n");']
  873. ,["[latex]", "Формула латех", 'intag ("latex");']
  874. ,["[code]", "Код", 'intag ("code", "\\n");']
  875. ,["[inline]", "Внутристрочный код", 'intag ("inline");']
  876. );
  877. panel.createBlock (
  878. ["[url]", "URL", 'url ();']
  879. ,["[user]", "Участник", 'intag ("user");']
  880. );
  881. panel.createBlock (
  882. ["[list]", "Список", 'lst();']
  883. ,["[*]", "Элемент списка", 'wrtSel ("[*]", "");']
  884. );
  885. panel.createBlock (
  886. ["«»", "Кавычки", 'wrtSel ("«", "»");'],
  887. ["„“", "Кавычки", 'wrtSel ("„", "“");'],
  888. ["[br]", "Перевод строки", 'wrtSel ("[br]", "");']
  889. );
  890. panel.createBlock (
  891. [" fix ", "Превратить знаки и обозначения в соответствующие спец. символы", 'fix();']
  892. /*,[" deltags-in ", "Удалить крайнее входящие обрамление тегами", 'deltagsin ();']*/
  893. ,[" brs ", "Добавить [br] к переводам строк", 'brs ();']
  894. );
  895.  
  896. msg.parentNode.insertBefore (panel, msg);
  897. msg.cols = 100;
  898. msg.rows = 20;
  899.  
  900. // Styles
  901. obj = document.createElement ("style");
  902. obj.innerHTML =
  903. '#atag a {\
  904. padding:2px 3px; margin:2px; cursor: pointer;\
  905. text-decoration: none; color: #FFF !important;\
  906. background-color:#004; border: #888 outset 1px;\
  907. }\
  908. #atag a:hover {background-color:#008; border-color:#888;}\
  909. #atag {\
  910. margin-top: 5px; margin-bottom: 5px;\
  911. padding: 3px 1px; font-size: 0.9em;\
  912. }\
  913. #atag > span {margin-right: 4px;}\
  914. label[for="msg"] {display: inline-block; margin-top: 5px;}\
  915. #msg {width: 50em !important;}\
  916. label[for="title"], label[for="form_mode"] {display: inline-block; margin: 5px 0 3px 0;\
  917. .msg_body p {margin: 0.3em 0 !important;}\
  918. .quote > p {margin: 0.5em 0 0.3em 0 !important;}';
  919. document.getElementsByTagName ("head")[0].appendChild (obj);
  920.  
  921. // Add quote links
  922. function cre_links(o, L){
  923. var S = document.createElement("span");
  924. tlog("LEN: " + L.length + " obj: " + o);
  925. var Ll = L.length;
  926. for (j = 0; j < Ll; j++){
  927. qlink = document.createElement ("a");
  928. qlink.textContent = L[j][0];
  929. d = document.createElement("span");
  930. if(L[j][0] == "#"){
  931. qlink.href = getMsgURL(o);
  932. }else{
  933. qlink.href = "#";
  934. }
  935. d.onclick = L[j][1];
  936. d.innerHTML = "[" + qlink.outerHTML + "] ";
  937. S.appendChild(d)
  938. }
  939. if(o.firstElementChild && o.firstElementChild.nodeName != "IMG"){
  940. clink = o.firstChild;
  941. o.insertBefore(S, clink);
  942. }else
  943. o.appendChild(S);
  944. }
  945. var t = document.getElementsByClassName("title");
  946. t.createQlink = function(){
  947. for (i = 0; i < this.length; i++){
  948. if(this[i].parentNode.nodeName != "ARTICLE") continue;
  949. var A = Array.prototype.slice.call(arguments)
  950. cre_links(this[i], A);
  951. }
  952. }
  953. t.createQlink(['#', insurl], ['пожаловаться', knock_knock], ['юзер', user],
  954. ['блок-цитата', qb], ['цитата', q]
  955. );
  956. t = document.getElementsByTagName("header")[0];
  957. cre_links(t, [['#', insurl], ['пожаловаться', knock_knock], ['юзер', user],
  958. ['блок-цитата', qb], ['цитата', q]]
  959. );
  960.  
  961. // Add \n to <br>
  962. var mbs = document.getElementsByClassName("msg_body");
  963. for (j in mbs) if (!isNaN (j)) {
  964. var mps = mbs[j].getElementsByTagName ("p");
  965. for (i in mps)
  966. if (!isNaN (i))
  967. mps[i].innerHTML = mps[i].innerHTML.replace (/<br\/?>(?![\n\r])/g, "<br>\n");
  968. }
  969.  
  970.  
  971. /* Main */
  972.  
  973. // Auxiliary functions
  974. function wrtSel(subj, offset, before, after, zset){ //Also msg.wrtSel (before, after, offset)
  975. tlog("MSGWRT!!!");
  976. if(typeof offset == "string")
  977. var
  978. after = offset, offset = before,
  979. before = subj, subj = undefined;
  980. var
  981. before = before || "", after = after || "",
  982. offset = set (offset, before.length), zset = zset || 0;
  983. var
  984. startSel = set (a, msg.selectionStart), endSel = set (b, msg.selectionEnd),
  985. subj = before + set (subj, msg.value.substring (startSel, endSel)) + after;
  986.  
  987. msg.value = msg.value.substring (0, startSel) + subj + msg.value.substring (endSel);
  988. msg.selectionStart = msg.selectionEnd = startSel+offset;
  989. msg.focus();
  990. a = b = undefined;
  991. }
  992. function lst(){
  993. a = msg.selectionStart; b = msg.selectionEnd;
  994. z = msg.value.substring(a, b).replace(/([^\n\r]+)[\n\r]*/g, "[*]$1\n");
  995. z = z.replace(/^[\s\r\n]+/g, '').replace(/^$/g,'');
  996. if(z.length == 0) z = "[*]\n";
  997. wrtSel(z, 6, "\n[list]\n", "[/list]\n");
  998. }
  999. function addbr (c) {
  1000. return c.replace (/^((?:(?!\[\/?(?:quote|code|list|br)(?:=.*)?\]$)[^\n\r])+)(\r?\n)(?!\n|\[\/?(?:br|quote(?:=.*)?|code(?:=.*)?)\])/gm, "$1[br]$2");
  1001. }
  1002. function getTextContent (post) {
  1003. var text = "";
  1004. var pTags = post.getElementsByClassName ("msg_body")[0].getElementsByTagName ("p");
  1005. for (i = 0; i < pTags.length; i++)
  1006. if (pTags[i].parentNode.className.indexOf ('msg_body') > -1) {
  1007. text += pTags[i].textContent;
  1008. if (i != pTags.length - 1) text += "\n\n";
  1009. }
  1010. return text;
  1011. }
  1012. function getUserName(evt){
  1013. var post = getMsg(evt.target);
  1014. if (i = post.getElementsByClassName("sign")[0].getElementsByTagName("a")[0])
  1015. return i.innerHTML;
  1016. else return "anonymous";
  1017. }
  1018.  
  1019. // Functions to run
  1020. function intag (tag, arg) {
  1021. var arg = arg || "";
  1022. wrtSel(
  1023. undefined,
  1024. tag.length + 2 + arg.length*2,
  1025. arg + "[" + tag + "]" + arg,
  1026. arg + "[/" + tag + "]" + arg
  1027. );
  1028. }
  1029.  
  1030. // reparce quotations if checked in glob settings
  1031. function reparceinline(text){
  1032. var bef = text.split("[inline]");
  1033. bef[0] = bef[0].replace(/"/g, "&#34;");
  1034. var N = bef.length;
  1035. for(var m = 1; m < N; m++){
  1036. var aft = bef[m].split("[/inline]");
  1037. aft[1] = aft[1].replace(/"/g, "&#34;");
  1038. bef[m] = aft.join("[/inline]");
  1039. }
  1040. text = bef.join("[inline]");
  1041. return text;
  1042. }
  1043. function reparce(text){
  1044. var bef = text.split("[code]");
  1045. //bef[0] = bef[0].replace(/"/g, "&#34;");
  1046. bef[0] = reparceinline(bef[0]);
  1047. var N = bef.length;
  1048. for(var m = 1; m < N; m++){
  1049. var aft = bef[m].split("[/code]");
  1050. //aft[1] = aft[1].replace(/"/g, "&#34;");
  1051. aft[1] = reparceinline(aft[1]);
  1052. bef[m] = aft.join("[/code]");
  1053. }
  1054. text = bef.join("[code]");
  1055. return text;
  1056. }
  1057. tlog("rep: "+Glob["reparceQuots"]);
  1058. if(Glob["reparceQuots"]){form.onsubmit = function(){msg.value = reparce(msg.value);}}
  1059.  
  1060. function fix () {
  1061. var a = msg.selectionStart, b = msg.selectionEnd;
  1062. var repc = function (c) {
  1063. c = c.replace (/\(c\)/gi, "©"); c = c.replace (/\([rр]\)/gi, "®");
  1064. c = c.replace (/\(f\)/gi, "£"); c = c.replace (/\(e\)/gi, "€");
  1065. c = c.replace (/%\/10/g, "‰"); c = c.replace (/%\/100/g, "‱");
  1066. c = c.replace (/\(V\)/g, "✓"); c = c.replace (/\(V\+\)/g, "✔");
  1067. c = c.replace (/\(x\)/g, "✗"); c = c.replace (/\(x\+\)/g, "✘");
  1068. c = c.replace (/`/g, "&#769;"); c = c.replace (/\(p\)/gi, "§");
  1069. c = c.replace (/(^| )- /g, "$1— "); c = c.replace (/\.\.\./g, "…");
  1070. c = c.replace (/\(\*\+?\)/g, "★"); c = c.replace (/\(\*-\)/g, "☆");
  1071. c = c.replace (/\([tт][mм]\)/gi, "™");
  1072. c = c.replace (/-->/g, "→");
  1073. return c;
  1074. }
  1075. if (a != b) {
  1076. var c = msg.value.substring (a, b);
  1077. var z = repc (c);
  1078. wrtSel(z, 0, "", "", z.length - c.length);
  1079. }
  1080. else
  1081. msg.value = repc (msg.value);
  1082. }
  1083. function url(U){
  1084. var U = U || "";
  1085. a = msg.selectionStart; b = msg.selectionEnd;
  1086. z = msg.value.substring (a, b);
  1087. if(U != ""){
  1088. wrtSel (z, 6+U.length,
  1089. "[url=" + U + "]", "[/url]",
  1090. -z.length
  1091. );
  1092. }
  1093. else if (/((ftp|http|https):\/\/)[\.\w- ]{2,}\.[A-Za-z]{2,4}(\/?$|\/.*)/.test(z) || z.length == 0) {
  1094. wrtSel (z, z.length+6,
  1095. "[url=", "][/url]"
  1096. );
  1097. }
  1098. else if (/[\.\w- ]{2,}\.[A-Za-z]{2,4}(\/?$|\/.*)/.test(z)) {
  1099. wrtSel (
  1100. "http://"+z, z.length+13,
  1101. "[url=", "][/url]", 7
  1102. );
  1103. }
  1104. else {
  1105. wrtSel (z, 5,
  1106. "[url=]", "[/url]",
  1107. -z.length
  1108. );
  1109. }
  1110. }
  1111. function deltagsin () {
  1112. z = msg.value.substring (a = msg.selectionStart, b = msg.selectionEnd);
  1113. c = z.replace (/\[\w+\](.*)\[\/\w+\]/, "$1");
  1114. wrtSel (c, 0, "", "", - z.length + c.length);
  1115. }
  1116. function brs () {
  1117. var a = msg.selectionStart, b = msg.selectionEnd;
  1118. if (a != b) {
  1119. var c = msg.value.substring (a, b);
  1120. var z = addbr (c);
  1121. wrtSel (z, 0, "", "", z.length - c.length);
  1122. }
  1123. else {
  1124. msg.value = addbr (msg.value);
  1125. }
  1126. }
  1127. function substTags(chN){
  1128. if(!chN) return;
  1129. var LORtagz = [ "b", "i","s","u","url","code","list","br","*","em","strong",
  1130. "pre", "quote"];
  1131. var txt = "", incode = false, latex = false;
  1132. var Tpre="", Tpost="";
  1133. if(chN.className == "sign" || chN.className == "reply") return "";
  1134. if(chN.nodeName == "B"){Tpre="[b]"; Tpost="[/b]";}
  1135. else if(chN.nodeName == "I"){Tpre="[i]"; Tpost="[/i]";}
  1136. else if(chN.nodeName == "S"){Tpre="[s]"; Tpost="[/s]";}
  1137. else if(chN.nodeName == "U"){Tpre="[u]"; Tpost="[/u]";}
  1138. else if(chN.nodeName == "A"){Tpre="[url="+chN.href+"]"; Tpost="[/url]";}
  1139. else if(chN.nodeName == "CODE"){Tpre="\n[code"+(chN.className ? "="+chN.className:"")+"]\n"; Tpost="[/code]"; incode = true;}
  1140. else if(chN.nodeName == "UL"){Tpre="\n[list]\n"; Tpost="\n[/list]";}
  1141. else if(chN.nodeName == "OL"){Tpre="\n[list=\""+chN.type+"\"]\n"; Tpost="\n[/list]";}
  1142. else if(chN.nodeName == "BR")Tpost="[br]\n";
  1143. else if(chN.nodeName == "LI"){Tpre="[*] "; Tpost="\n";}
  1144. else if(chN.nodeName == "EM"){Tpre="[em]"; Tpost="[/em]";}
  1145. else if(chN.nodeName == "STRONG"){Tpre="[strong]"; Tpost="[/strong]";}
  1146. else if(chN.nodeName == "PRE"){Tpre="[pre]\n"; Tpost="[/pre]";}
  1147. else if(chN.nodeName == "P"){Tpre="\n"; Tpost="\n";}
  1148. else if(chN.nodeName == "SPAN"){Tpre=""; Tpost="\n";}
  1149. else if(chN.nodeName == "CITE"){Tpre="[b]"; Tpost="[/b][br]\n";}
  1150. else if(chN.nodeName == "IMG"){Tpre="[latex]"; Tpost="[/latex]"; latex = true;}
  1151. //else if(chN.nodeName == ""){Tpre=""; Tpost="";}
  1152. //else if(chN.className == "quote"){Tpre="[quote]"; Tpost="[/quote]";}
  1153. else if(chN.nodeName == "BLOCKQUOTE"){Tpre="[quote]"; Tpost="[/quote]";}
  1154. if(latex) txt = chN.title;
  1155. else if(incode) txt = chN.textContent;
  1156. else if(chN.childNodes && chN.childNodes.length)
  1157. for (var ch in chN.childNodes)
  1158. txt += substTags(chN.childNodes[ch]);
  1159. else if(typeof(chN.textContent) != "undefined"){
  1160. txt = chN.textContent; //.replace(/\[/g, '[[').replace(/\]/g, ']]');
  1161. for(var j in LORtagz){
  1162. var Tg = LORtagz[j];
  1163. txt = txt.split("["+Tg+"]").join("[["+Tg+"]]");
  1164. txt = txt.split("[/"+Tg+"]").join("[[/"+Tg+"]]");
  1165. }
  1166. }
  1167. txt = Tpre + txt + Tpost;
  1168. return txt.replace(/^[\s\r\n]+$/, '').replace(/^$/,'');
  1169. }
  1170. function qb(e){
  1171. noDef(e);
  1172. var post, seltxt = getSelection ();
  1173.  
  1174. function f(s,o){
  1175. var T = "[quote" + (getMsg(o) != getMsg(msg)
  1176. ? "=" + getUserName (e)
  1177. : "") + "]"
  1178. + substTags(s) + "\n[/quote]\n\n";
  1179. return T.replace(/(^[ \t]*\n)/gm, "")
  1180. }
  1181. if (seltxt != "") {
  1182. post = getMsg(seltxt.getRangeAt(0).commonAncestorContainer);
  1183. wrtSel(i = f(seltxt.getRangeAt (0).cloneContents(),this), i.length);
  1184. }
  1185. else {
  1186. post = getMsg(this);
  1187. wrtSel (i = f(post.getElementsByClassName ("msg_body")[0], this), i.length);
  1188. }
  1189. return false;
  1190. }
  1191. function q(e) {
  1192. noDef(e);
  1193. var seltxt = getSelection ();
  1194. console.log(seltxt);
  1195. if (seltxt != "") {
  1196. var post = getMsg(seltxt.getRangeAt(0).commonAncestorContainer);
  1197. wrtSel (i = seltxt.toString ().replace (/(\n\r?|^)(?:\n\r?)?/g, "$1> ") + "\r\n", i.length);
  1198. }
  1199. else {
  1200. post = getMsg(this);
  1201. wrtSel (i = getTextContent (post).replace (/(\n\r?|^)(?:\n\r?)?/g, "$1> ") + "\r\n", i.length);
  1202. }
  1203. return false;
  1204. }
  1205. function user (e) {
  1206. noDef(e);
  1207. if ((i = getUserName(e)) != "anonymous")
  1208. wrtSel (i = "[user]" + i + "[/user], ", i.length);
  1209. else wrtSel (i = "[strong]Аноним[/strong], ", i.length);
  1210. return false;
  1211. }
  1212. function insurl(e){
  1213. noDef(e);
  1214. url(e.target.href);
  1215. }
  1216. }
  1217.  
  1218.  
  1219. // *****************************************************************************
  1220. // here - all functions that have no setup in profile
  1221. /*
  1222. * Allow to put html tags into user info
  1223. */
  1224. var UInfoArr = document.getElementsByClassName("user-remark");
  1225. tlog("L+"+UInfoArr.length );
  1226. for(var i = 0, j = UInfoArr.length; i < j; i++){
  1227. str = UInfoArr[i].innerHTML;
  1228. tlog(str);
  1229. str = str.replace(/&lt;/g, "<");
  1230. str = str.replace(/&gt;/g, ">");
  1231. UInfoArr[i].innerHTML = str;
  1232. }
  1233.  
  1234. /*
  1235. * Convert contents of tag [latex] into image from codecogs
  1236. */
  1237. function showLatex(){
  1238. var t = document.getElementsByClassName("msg_body");
  1239. function chk(a,str){
  1240. if(a) return str;
  1241. else return '';
  1242. }
  1243. function getInner(str, fstrun){
  1244. var a = str.indexOf("[latex]");
  1245. if(a == -1) return chk(fstrun, str);
  1246. var b = str.indexOf("[/latex]", a+7);
  1247. if (b == -1) return chk(fstrun, str);
  1248. var head = str.substr(0, a);
  1249. var tail = str.substr(b+8);
  1250. var midtext = str.substr(a+7, b-a-7);
  1251. return head + "<img src=\"http://latex.codecogs.com/svg.latex?"+
  1252. midtext+"\""+"title=\""+midtext+"\">"+getInner(tail,1);
  1253. //return head + "<img src=\"http://texify.com/img/\\LARGE\\!" +
  1254. //return head + "<img src=\"http://texify.com/img/" +
  1255. // midtext + ".gif\" " + "title=\""+midtext+"\">"+getInner(tail,1);
  1256. }
  1257. t.parceLatex = function(){
  1258. var L = this.length;
  1259. for(i = 0; i < L; i++){
  1260. var txt = this[i].innerHTML, newtxt = '', innertext='';
  1261. innertext = getInner(txt, 0);
  1262. if(innertext.length == 0) continue;
  1263. this[i].innerHTML = innertext;
  1264. tlog(innertext);
  1265. }
  1266. }
  1267. t.parceLatex();
  1268. }
  1269. showLatex();
  1270.  
  1271. }());