Advertisement
Guest User

Untitled

a guest
Feb 27th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          LOR TreeView
  3. // @description   Make tree view for LOR threads (with jQuery)
  4. // @exclude http*://*linux.org.ru/forum/*/
  5. // @exclude http*://*linux.org.ru/news/*/
  6. // @exclude http*://*linux.org.ru/gallery/*/
  7. // @exclude http*://*linux.org.ru/polls/*/
  8. // @include http*://*linux.org.ru/forum/*/*
  9. // @include http*://*linux.org.ru/news/*/*
  10. // @include http*://*linux.org.ru/gallery/*/*
  11. // @include http*://*linux.org.ru/polls/*/*
  12. // @grant GM_log
  13. // @UpdateURL http://userscripts.org/scripts/source/15985.user.js
  14. // @version 7.15
  15. // ==/UserScript==
  16. //
  17. // License: GNU GPL v3 or later
  18. // Copyright (C) 2012 sdio
  19. //
  20. // The JavaScript code in this page is free software: you can
  21. // redistribute it and/or modify it under the terms of the GNU
  22. // General Public License (GNU GPL) as published by the Free Software
  23. // Foundation, either version 3 of the License, or (at your option)
  24. // any later version.  The code is distributed WITHOUT ANY WARRANTY;
  25. // without even the implied warranty of MERCHANTABILITY or FITNESS
  26. // FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
  27. //
  28. // As additional permission under GNU GPL version 3 section 7, you
  29. // may distribute non-source (e.g., minimized or compacted) forms of
  30. // that code without the copy of the GNU GPL normally required by
  31. // section 4, provided you include this license notice and a URL
  32. // through which recipients can access the Corresponding Source.
  33. //
  34. // Author:  sdio (http://www.linux.org.ru/people/sdio/profile)
  35. // Contributed by:
  36. //  kodx ( http://kodx.org )
  37. //  ZaWertun ( http://www.linux.org.ru/people/ZaWertun/profile )
  38. //
  39. //
  40.  
  41.  
  42.  
  43. var js = document.createElement("script");
  44. js.type = "text/javascript";
  45. js.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
  46. var callback = function (){
  47.     // change color of links
  48.     var ALTERLINKS = 1;
  49.     // use quick answer form
  50.     var USE_QUICK_ANSWER = 1;
  51.  
  52.     var THEME;
  53.     // set the default theme in case autodetect fail
  54.     THEME = 'tango';
  55.     //THEME = 'white'
  56.     //THEME = 'black';
  57.  
  58.     //----------------------------------------------------------------
  59.     var COLOR = new Array();
  60.     COLOR['white']  = 'black';
  61.     COLOR['white2'] = 'black';
  62.     COLOR['black']  = 'white';
  63.     COLOR['tango']  = '#babdb6';
  64.     COLOR['swamp']  = 'black';
  65.  
  66.     // Length of the BACKGROUNDS array may be any, so change it as you want
  67.     var BACKGROUNDS = new Array;
  68.     BACKGROUNDS['white']  = ['#ccf', '#ffc', '#cfc', '#fcc', '#cff', '#fcf', '#ccc'];
  69.     BACKGROUNDS['white2'] = ['#ccf', '#ffc', '#cfc', '#fcc', '#cff', '#fcf', '#ccc'];
  70.     BACKGROUNDS['black']  = ['#006', '#330', '#303', '#033', '#300', '#030', '#333'];
  71.     BACKGROUNDS['tango']  = ['#272c2d', '#2c3233', '#313738', '#353c3d'];
  72.     BACKGROUNDS['swamp']  = ['#C0C3B1', '#B0B8A1', '#A0A895','#909580'];
  73.  
  74.     var POPUPBG = new Array;
  75.     POPUPBG['white']  = 'yellow';
  76.     POPUPBG['white2'] = 'yellow';
  77.     POPUPBG['black']  = 'grey';
  78.     POPUPBG['tango']  = 'grey';
  79.     POPUPBG['swamp']  = 'yellow';
  80.  
  81.     var POPUPBRD = new Array;
  82.     POPUPBRD['white']  = 'black';
  83.     POPUPBRD['white2'] = 'black';
  84.     POPUPBRD['black']  = 'white';
  85.     POPUPBRD['tango']  = 'white';
  86.     POPUPBRD['swamp']  = 'black';
  87.  
  88.     // Indentation per reply level
  89.     const INDENT = '10px';
  90.  
  91.  
  92.     const DAYS = 3;
  93.     const COOKIENAME = "TreeView";
  94.  
  95.  
  96.     var options = {
  97.         // target: '#quickanswerdiv',
  98.         // post-submit callback
  99.         success: showResponse,
  100.         cache: false
  101.     };
  102.  
  103.     var jq;
  104.     var st;
  105.  
  106.     if (typeof(GM_log) == 'function') {
  107.         // For FF, Mozilla (with greasemonkey sandbox)
  108.         jq = unsafeWindow.$;
  109.         jq = $;
  110.         console.log(unsafeWindow.$);
  111.         st = unsafeWindow.setTimeout;
  112.         unsafeWindow.ctrl_enter = function(e, form) {
  113.             if (((e.keyCode == 13) || (e.keyCode == 10)) && (e.ctrlKey)) {
  114.                 jq("#quickanswerform").ajaxForm(options).submit();
  115.             }
  116.         };
  117.  
  118.         unsafeWindow.jump = function(link) {
  119.             return 1;
  120.         };
  121.  
  122.         unsafeWindow.image_onload = function(elem){
  123.             var width = elem.naturalWidth;
  124.             if (width < 320) {
  125.                 elem.style.width = '';
  126.             }
  127.         };
  128.         unsafeWindow.onbeforeunload = null;
  129.  
  130.  
  131.     } else {
  132.         // For Epiphany, Opera
  133.         jq = $;
  134.         st = setTimeout;
  135.         function ctrl_enter(e, form) {
  136.             if (((e.keyCode == 13) || (e.keyCode == 10)) && (e.ctrlKey)) {
  137.                 jq("#quickanswerform").ajaxForm(options).submit();
  138.             }
  139.         }
  140.  
  141.         function jump(link) {
  142.             return 1;
  143.         }
  144.         function image_onload(elem){
  145.             var width = elem.naturalWidth;
  146.             if (width < 320) {
  147.                 elem.style.width = '';
  148.             }
  149.         }
  150.         window.onbeforeunload = null;
  151.     }
  152.  
  153.     var msgs = -1;
  154.     var thread_id;
  155.     var topic = jq('div.messages article[id*="topic-"]');
  156.     if (topic.length) {
  157.         thread_id = topic.attr('id').split('-')[1];
  158.     } else {
  159.         alert('Error: can not detect thread ID.');
  160.     }
  161.  
  162.     var cnt       = getCounter(thread_id, 0);
  163.     var newid     = new Array;
  164.  
  165.  
  166.     jq('link').each(function(){
  167.         var found = this.href.match(/\/([^/]*)\/combined\.css/);
  168.         if (found) {
  169.             THEME = found[0].split('/')[1];
  170.             if (THEME == 'tango') {
  171.                 var subtheme = readCookie("style_selected");
  172.                 if (subtheme == 'tango-swamp') {
  173.                     THEME = 'swamp';
  174.                 }
  175.             }
  176.         }
  177.     });
  178.  
  179.  
  180.     jq('<div id="popupContact"><br><h2><span id="popupMsgs">0</span> new messages</h2><br></div>').hide().appendTo('body');
  181.     jq("#popupContact").css({
  182.         "background-color": POPUPBG[THEME],
  183.         "padding": "10px",
  184.         "border": "1px solid " +  POPUPBRD[THEME],
  185.         "position": "fixed",
  186.         "top":  (document.documentElement.clientHeight - 200)/2,
  187.         "left": (document.documentElement.clientWidth  - 300)/2
  188.     });
  189.  
  190.     jq('<div id="popupPreview"></div>').hide().appendTo('body');
  191.     jq("#popupPreview").css({
  192.         "text-align": "left",
  193.         "background-color": POPUPBG[THEME],
  194.         "padding": "5px",
  195.         "border": "1px solid " +  POPUPBRD[THEME],
  196.         "position": "fixed",
  197.         "top":  (document.documentElement.clientHeight)/5,
  198.         "left": 50
  199.     });
  200.  
  201.     function insertAfter(referenceNode, newNode) {
  202.         referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  203.     }
  204.  
  205.     //start: Сообщить модератору (based on http://infoman.name/userscripts)
  206.  
  207.     jq.GMReport = {
  208.         topicnum: null
  209.     };
  210.  
  211.     GMReportFunctions = {
  212.         // Save topic number in cache
  213.         savetopicnum: function() {
  214.             createCookie("topicnum",jq.GMReport.topicnum,DAYS);
  215.             createCookie("topictime", new Date().getTime().toString(),DAYS);
  216.         },
  217.  
  218.         fetchtopicnum: function() {
  219.             jq.GMReport.topicnum = -1;
  220.             var req = new XMLHttpRequest();
  221.             req.open('GET', location.protocol + '//www.linux.org.ru/group.jsp?group=4068', true);
  222.             req.onreadystatechange = function (e) {
  223.                 if (req.readyState == 4) {
  224.                     if(req.status == 200)
  225.                     {
  226.                         jq(req.responseText).find("img[alt='Прикреплено']").each(function()
  227.                                                                                  {
  228.                             var link = jq(this).next("a");
  229.                             if (/Ссылки.*некор/i.test(link.html()))
  230.                             {
  231.                                 jq.GMReport.topicnum = /linux-org-ru\/(\d+)/.exec(link.attr("href"))[1];
  232.                                 GMReportFunctions.savetopicnum();
  233.                             }
  234.                         });
  235.                     }
  236.                     else
  237.                     {
  238.                         alert("Cannot get reports topic number");
  239.                     }
  240.                 }
  241.             };
  242.             req.send(null);
  243.         },
  244.  
  245.         // Get topic number for sending reports
  246.         gettopicnum: function() {
  247.             if (jq.GMReport.topicnum == null)
  248.             {
  249.                 var num = readCookie("topicnum");
  250.                 var time = new Number(readCookie("topictime"));
  251.                 var cur = new Date().getTime();
  252.                 if ((num != null) && ((cur - time) < 7200000))
  253.                 {
  254.                     jq.GMReport.topicnum = num;
  255.                 }
  256.                 else
  257.                 {
  258.                     GMReportFunctions.fetchtopicnum();
  259.                 }
  260.             }
  261.             if (jq.GMReport.topicnum == -1)
  262.             {
  263.                 st(GMReportFunctions.gettopicnum, 100);
  264.             }
  265.             if (jq.GMReport.topicnum > 0)
  266.             {
  267.                 letsGo();
  268.             }
  269.         }
  270.     };
  271.  
  272.     GMReportFunctions.gettopicnum();
  273.  
  274.     // All your GM code must be inside this function
  275.     function letsGo() {
  276.         jq("div.reply").each(function()
  277.                              {
  278.             var div = jq(this);
  279.             if (/^[^Ответ]/.test(div.html()))
  280.             {
  281.                 div.append("[<a class='lor-report-msg' href='javascript:{/*Сообщить модератору (страница не будет перезагружена)*/}'>Сообщить модератору</a>]");
  282.             }
  283.         });
  284.  
  285.  
  286.         jq("a.lor-report-msg").click(function() {
  287.             // hack: why .unbind() doesn't work
  288.             if (jq(this).html() == "Просмотреть") { return true; }
  289.             //
  290.             var comment = prompt("Please provide a comment about this message", "Нацпол");
  291.             if (comment === null) { return false; }
  292.             // Constructing message for posting
  293.             var msgtext = null;
  294.             var reportlink = jq(this);
  295.             var  url1 = reportlink.parent().parent().parent().parent().find("div.msg_body h1 a:first");
  296.             if (url1.length == 0) {
  297.                 url1 = reportlink.parent().find("li:nth-child(2) a:first");
  298.             }
  299.  
  300.             if (!msgtext) {
  301.                 msgtext = comment + " : " + url1.get(0).href;
  302.             }
  303.  
  304.             var message = {
  305.                 csrf: /CSRF_TOKEN="(.+)"/.exec(document.cookie)[1],
  306.                 topic:    jq.GMReport.topicnum,
  307.                 title:    "",
  308.                 msg:      msgtext
  309.             };
  310.             jq.post(location.protocol + "//www.linux.org.ru/add_comment.jsp", message, function(data) {
  311.                 var allmsgs = jq(data).find("article.msg");
  312.                 var reportnum = /\d+/.exec(allmsgs.eq(allmsgs.length - 1).attr("id"))[0];
  313.                 reportlink.unbind().attr("href", location.protocol + "//www.linux.org.ru/jump-message.jsp?msgid=" + jq.GMReport.topicnum + "&cid=" + reportnum).html("Просмотреть");
  314.             });
  315.         });
  316.     }
  317.  
  318.     //end: Сообщить модератору
  319.  
  320.  
  321.     function createCookie(name,value,days) {
  322.         var expires;
  323.         if (days) {
  324.             var date = new Date();
  325.             date.setTime(date.getTime()+(days*24*60*60*1000));
  326.             expires = "; expires="+date.toGMTString();
  327.         } else {
  328.             expires = "";
  329.         }
  330.         document.cookie = name+"="+value+expires+"; path=/";
  331.     }
  332.  
  333.     function readCookie(name) {
  334.         var nameEQ = name + "=";
  335.         var ca = document.cookie.split(';');
  336.         for(var i=0; i<ca.length; i++) {
  337.             var c = ca[i];
  338.             while (c.charAt(0)==' ') c = c.substring(1,c.length);
  339.             if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  340.         }
  341.         return null;
  342.     }
  343.  
  344.     function jq_get(url, callback) {
  345.         var data = {};
  346.         var param = url.split('?')[1];
  347.         var url = url.split('?')[0];
  348.         if (param) {
  349.             var params = param.split('&');
  350.             for (var i=0; i<params.length; i++) {
  351.                 var key = params[i].split('=')[0];
  352.                 var val = params[i].split('=')[1];
  353.                 switch (key) {
  354.                     case 'msgid':
  355.                         data[key] = val;
  356.                         break;
  357.                     case 'page':
  358.                         data[key] = val;
  359.                         break;
  360.                     case 'filter':
  361.                         data[key] = val;
  362.                         break;
  363.                 }
  364.             }
  365.         }
  366.         jq.ajaxSetup({cache: false});
  367.         jq.get(url, data, callback);
  368.     }
  369.  
  370.  
  371.  
  372.     //get from Cookie or GM stored thread's message counter
  373.     function getCounter(msg_id, update) {
  374.         var count = null;
  375.         var str = readCookie(COOKIENAME);
  376.         if (str) {
  377.             var flag = 0;
  378.             var d = new Date();
  379.             var nowtime = d.getTime();
  380.             var newarr = new Array;
  381.             var arr = str.split("_");
  382.             var j;
  383.             var k = 0;
  384.             newarr[k++] = "";
  385.             for (var i=1; i<arr.length; i+=3){
  386.                 if (arr[i] == msg_id) {
  387.                     // found
  388.                     j = i+1;
  389.                     count = arr[j];
  390.                 } //if
  391.                 j = i+2;
  392.                 if (arr[j] > nowtime) {
  393.                     j=i;
  394.                     newarr[k++] = arr[j++];
  395.                     newarr[k++] = arr[j++];
  396.                     newarr[k++] = arr[j++];
  397.                 } else {
  398.                     flag = 1; // will purge expired records
  399.                 } //if
  400.  
  401.             } //for
  402.             if (flag) {
  403.                 str = newarr.join("_");
  404.                 createCookie(COOKIENAME, str, DAYS);
  405.             }
  406.         } //if(str)
  407.         if (!count) {
  408.             if (update) {
  409.                 count = jq("div.comment article.msg").length;
  410.             } else {
  411.                 count = 0;
  412.             }
  413.         }
  414.         return count;
  415.     }
  416.  
  417.     function setCounter(msg_id, value) {
  418.         var d = new Date();
  419.         var expireat = d.getTime();
  420.         expireat += DAYS * 24 * 60 * 60 * 1000;
  421.  
  422.         var flag = 0;
  423.         var str = readCookie(COOKIENAME);
  424.         if (str) {
  425.             var arr = str.split("_");
  426.             for (var i=1; i<arr.length; i+=3){
  427.                 if (arr[i] == msg_id) {
  428.                     // found
  429.                     arr[++i] = value;
  430.                     arr[++i] = expireat;
  431.                     flag = 1;
  432.                     break;
  433.                 }
  434.             }
  435.         } else {
  436.             str = "";
  437.         }
  438.  
  439.         if (flag) {
  440.             // updated
  441.             str = arr.join("_");
  442.         } else {
  443.             // new one
  444.             str = str + "_" + msg_id + "_" + value + "_" + expireat;
  445.         }
  446.         createCookie(COOKIENAME, str, DAYS);
  447.     }
  448.  
  449.     //
  450.     // callback function on UPDATE action
  451.     //
  452.     function onAjaxSuccess(data) {
  453.         // data is html returned by server
  454.         var up_div = jq(data).find('div.comment article.msg');
  455.  
  456.         // number of messages received from server
  457.         var newmsgs = up_div.length;
  458.  
  459.         // [newmsgs > msgs] means that there are new messages
  460.         if (newmsgs > msgs) {
  461.             newid.length = 0;
  462.             if (msgs > 0) {
  463.                 up_div.slice(msgs,newmsgs).each(doindent);
  464.             } else {
  465.                 up_div.each(doindent);
  466.             }
  467.             // update message counter
  468.             jq("#popupMsgs").text(newmsgs-msgs);
  469.             msgs = jq('div.comment article.msg').length;
  470.             setCounter(thread_id, msgs);
  471.             cnt = msgs;
  472.  
  473.             jq('a._new_').remove();
  474.             addNavigateLinks(newid);
  475.             if (document.getElementById(newid[0]))  document.getElementById(newid[0]).scrollIntoView();
  476.             newid.length = 0;
  477.  
  478.         } else {
  479.             // no news
  480.             // drop temp data
  481.             jq("#popupMsgs").text('0');
  482.         }
  483.         jq("#popupContact").show();
  484.         st('$("#popupContact").hide();',3000);
  485.     }
  486.  
  487.  
  488.     function quickAnswer(elem) {
  489.         var topic;
  490.         var replyto;
  491.         var href = elem.search;
  492.         var session = /CSRF_TOKEN="(.+)"/.exec(document.cookie)[1];
  493.  
  494.         var seltxt;
  495.         try {
  496.             seltxt = window.getSelection().toString();
  497.         } catch(err){
  498.             alert(err);
  499.         }
  500.         if (seltxt) {
  501.             seltxt = '> ' + seltxt + "\n";
  502.         }
  503.  
  504.         jq("#quickanswerdiv").remove();
  505.  
  506.         var formhtml1 = '<form id="quickanswerform" method="POST" action="add_comment.jsp"> <input type="hidden" name="csrf" value="' + session + '"/>  <input type="hidden" name="topic" value="';
  507.         var formhtml2 = '<input type="text" name="title" size="73" value=""/><br> <textarea name="msg" cols="70" rows="10" onkeypress="return ctrl_enter(event, this.form);">'+seltxt+'</textarea><br> <input type="hidden" name="texttype" value="0"/><br><input type="submit" value="Отправить"/><input type="submit" value="Предпросмотр" name="preview"/></form>';
  508.  
  509.         if (href.match(/replyto=/)) {
  510.             topic   = href.replace(/^.*topic=(\d+).*$/, "$1");
  511.             replyto = href.replace(/^.*replyto=(\d+).*$/, "$1");
  512.             formhtml1 = formhtml1 + topic + '"/> <input type="hidden" name="replyto" value="'+replyto+'"/>';
  513.         } else {
  514.             topic   = href.replace(/^.*topic=(\d+).*$/, "$1");
  515.             formhtml1 = formhtml1 + topic + '"/>';
  516.         }
  517.  
  518.         jq(elem).parent().append('<div id="quickanswerdiv">' + formhtml1 + formhtml2 + '</div>');
  519.  
  520.         jq("#quickanswerform").ajaxForm(options);
  521.  
  522.         jq("textarea[name=msg]").focus();
  523.  
  524.     }
  525.  
  526.  
  527.     function showResponse(responseText, statusText) {
  528.         // data is html returned by server
  529.         var h1txt = jq(responseText).find('div.error').text();
  530.         if (h1txt) {
  531.             alert(h1txt);
  532.             return;
  533.         }
  534.  
  535.         h1txt = jq(responseText).find('p:contains("Ваше сообщение")').text();
  536.         if (h1txt) {
  537.             var rmsg = jq(responseText).find('div.messages');
  538.             if (rmsg) {
  539.                 jq("#popupPreview").get(0).innerHTML = rmsg.get(rmsg.length - 1).innerHTML;
  540.                 jq("#popupPreview").show();
  541.                 st('$("#popupPreview").hide();',5000);
  542.             }
  543.         } else {
  544.  
  545.             //up_div.empty();
  546.             jq("#quickanswerdiv").remove();
  547.             jq_get(document.location.href, onAjaxSuccess);
  548.         }
  549.     }
  550.  
  551.     //add a link with "text", "url" and "id" after <<elem>> html object.
  552.     function addNavButton(elem, text, url, cls){
  553.         var newA = document.createElement("a");
  554.         newA.href = url;
  555.         newA.className = cls;
  556.         newA.textContent = text;
  557.         newA.style.paddingLeft = "20px !important";
  558.         newA.style.color = COLOR[THEME] + '!important';
  559.         elem.appendChild(newA);
  560.     }
  561.  
  562.     //add navigation links (First/Next/Prev/Last) for recently added messages
  563.     function addNavigateLinks(msg_array){
  564.         var len = msg_array.length;
  565.         //Add navigation buttons for new messages
  566.         for (var i=0; i<len; i++){
  567.             var msgTD = jq("#"+msg_array[i]+" div.title").get(0);
  568.             if (msgTD) {
  569.                 //next message
  570.                 var nText = "[Next new]";
  571.                 var n = i + 1;
  572.                 if (n >= len) {
  573.                     n = 0;
  574.                     nText = "[First new]";
  575.                     var titleA = jq("div.title").get(0);
  576.                     if (titleA) {
  577.                         addNavButton(titleA,
  578.                                      nText,
  579.                                      'javascript:document.getElementById("' + msg_array[n] + '").scrollIntoView()', "_new_"
  580.                                     );
  581.                     }
  582.                 }
  583.                 addNavButton(msgTD, nText, 'javascript:document.getElementById("' + msg_array[n] + '").scrollIntoView()', "_new_");
  584.  
  585.                 //previous message
  586.                 var pText = "[Prev new]";
  587.                 var p = i - 1;
  588.                 if (p < 0) {
  589.                     p = len - 1;
  590.                     pText = "[Last new]";
  591.                 }
  592.                 addNavButton(msgTD,
  593.                              pText,
  594.                              'javascript:document.getElementById("' + msg_array[p] + '").scrollIntoView()', "_new_"
  595.                             );
  596.             }
  597.         }
  598.     }
  599.  
  600.     // ---------------------------------------------------------------------
  601.     function doindent(index) {
  602.         this.setAttribute("treelevel", "0");  // initial indent level
  603.         //    this.style.paddingBottom = "1px"; // style
  604.         //    this.style.marginBottom  = "4px"; // style
  605.         var root;
  606.  
  607.         // store new id in array
  608.         if ((msgs+index+1) >= cnt) {
  609.             newid.push(this.id);
  610.         }
  611.  
  612.         root = jq("div.comment").get(0);
  613.  
  614.         // remove subject
  615.         //  jq("h2", this).html('<hr>');
  616.  
  617.         var nick = jq("div.sign a:first",this).text();
  618.         if (nick) {
  619.             jq("div.title", this).append('[<a href="'+location.protocol+'//www.linux.org.ru/show-replies.jsp?output=rss&nick=' + nick + '" >' + nick + ' events</a>]');
  620.         }
  621.         // append [update page] link
  622.         jq("div.title", this).append('<a href="#" class="updatepage">[update page]</a>');
  623.         jq('a.updatepage', this).click(function(event) {
  624.             jq_get(document.location.href, onAjaxSuccess);
  625.             event.preventDefault();
  626.         });
  627.         var ign = jq('span.user-remark:contains("###"):first', this);
  628.         if (ign.length) {
  629.             ign.parent().parent().hide();
  630.             jq("div.title", this).append('<a href="javascript:{}" class="vtoggle">[show/hide]</a>');
  631.             jq('a.vtoggle', this).click(function(event) {
  632.                 jq('div[class*="msg_body"]:first', jq(this).parent().parent()).toggle();
  633.                 event.preventDefault();
  634.             });
  635.  
  636.         }
  637.  
  638.         // do all links colored black
  639.         if (ALTERLINKS) {
  640.             if (THEME != 'tango' || THEME != 'swamp') {
  641.                 jq("a", this).css('cssText', 'color: ' + COLOR[THEME] + ' !important');
  642.             }
  643.         }
  644.         jq(".sign", this).css('cssText', 'text-align: left');
  645.  
  646.         // enumerate message
  647.         jq("div.title", this).prepend('['+(msgs+index+1) + '] ');
  648.         //    jq("div.title a:first", this).each(function () {
  649.         //        this.setAttribute("class", "counter");
  650.         //    });
  651.  
  652.         // quick answer
  653.         if (USE_QUICK_ANSWER) {
  654.             jq('a:contains("Ответить на это сообщение")', this).click(function(event) {
  655.                 event.preventDefault();
  656.                 quickAnswer(this);
  657.             });
  658.         }
  659.  
  660.         // is a message answer to other (non root) message?
  661.         var a = jq('div.title a[data-samepage="samePage"]', this);
  662.         if (a.length) {
  663.             // #Id of reply message <DIV>
  664.             var idr = a.attr('href').split('cid=')[1];
  665.             idr='comment-'+idr;
  666.             // "parent" message
  667.             var idr_msg   = document.getElementById(idr);
  668.             // child's indent level
  669.             var idr_level = idr_msg.getAttribute("treelevel");
  670.             idr_level++;
  671.  
  672.             // save child's indent level
  673.             this.setAttribute("treelevel", idr_level);
  674.  
  675.             insertAfter(idr_msg, this);
  676.             // choose color accordingly to indent level
  677.             var bgcolor = BACKGROUNDS[THEME][idr_level % BACKGROUNDS[THEME].length] + ' !important';
  678.             var leftShift = idr_level * 20;
  679.             jq('article#' + this.id).css('cssText', "position: relative; left: " + leftShift + 'px;');
  680.  
  681.         } else {
  682.             if (msgs > -1) {
  683.                 root.appendChild(this);
  684.             }
  685.         }
  686.     }
  687.     // ---------------------------------------------------------------------
  688.  
  689.  
  690.     jq('#commentForm').remove();
  691.  
  692.     function makeTree() {
  693.         msgs = -1;
  694.         jq(".updatepage,._new_").remove();
  695.  
  696.         jq("article.msg").each(doindent);
  697.         idx = newid.shift(); // remove topic
  698.  
  699.         addNavigateLinks(newid);
  700.         newid.length = 0;
  701.         // set message counter
  702.         msgs = jq('div.comment article.msg').length;
  703.         setCounter(thread_id, msgs);
  704.     }
  705.  
  706.     makeTree();
  707.  
  708.     //var h1subj = jq('div.msg_body h1').get(0);
  709.     //h1subj.innerHTML = '<br><u>' + h1subj.innerHTML + '</u><br><br>';
  710.  
  711.     var urlhash = document.location.hash;
  712.     if (urlhash) {
  713.         urlhash = urlhash.split('#')[1];
  714.         document.getElementById(urlhash).scrollIntoView();
  715.     }
  716.  
  717. };
  718. js.onload = callback;
  719. document.head.appendChild(js);
  720.  
  721.  
  722.  
  723.  
  724.  
  725. // ---------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement