Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function update_chat(new_data, first_load) {
  2.     "use strict";
  3.     // Check if this post number already exists
  4.     var id = new_data.count;
  5.     if (id === undefined) return;
  6.     var new_post = (chat[id] === undefined || id == 0);
  7.  
  8.     // Set kot name
  9.     if (new_data.name == 'Kot') {
  10.     if (typeof new_data.country !== 'undefined')
  11.             new_data.name = kot_names[new_data.country.split('-')[0]] || 'Kot';
  12.     }
  13.  
  14.         if (ignored_ids && new_data && new_data.identifier && $.inArray(new_data.identifier, ignored_ids) > -1) {
  15.             return;
  16.         }
  17.             if($("#sounds").prop('checked')){
  18.         message_sound.play();
  19.         }
  20.     // Find post element or create blank one
  21.     var post = new_post ? generate_post(id) : $("#chat_" + id);
  22.  
  23.     // Find old post data object or create empty one
  24.     if (new_post) chat[id] = {};
  25.     var data = chat[id];
  26.  
  27.     // Populate post data object and mark new/changed fields
  28.     var changed = {};
  29.     var key = null;
  30.     for (key in new_data) {
  31.         changed[key] = (data[key] !== new_data[key]);
  32.         data[key] = new_data[key];
  33.     }
  34.  
  35.     // Populate post element with new/changed fields
  36.     if (changed.chat && chat_id === "all") {
  37.         post.find(".chat_label")
  38.             .css("display", "inline")
  39.             .attr("href", "/chat/" + data.chat + "#" + id)
  40.             .text("/" + data.chat);
  41.     }
  42.    
  43.     if (changed.name) {
  44.         post.find(".name_part").text(data.name);
  45.     }
  46.    
  47.     if (changed.identifier) {
  48.         post.find(".chat_identifier")
  49.         .text(data.identifier.slice(50))
  50.         .css({
  51.             background:'white'
  52.         });
  53.     }
  54.    
  55.     if (changed.country || (special_trips.indexOf(data.trip)>-1)) {
  56.         if (hidden_trips.indexOf(data.trip) > -1) {
  57.             if ((data.trip in flags_image_table) && (data.trip in flags_hover_strings)) {
  58.                 var country = $("<img src='/icons/tripflags/" + flags_image_table[data.trip] + "'/>");
  59.                 post.find(".flag").attr("data-country", flags_hover_strings[data.trip]);
  60.                 post.find(".flag").prepend(country);
  61.             }
  62.         } else if (bots.indexOf(data.trip) > -1) {
  63.             var country = $("<img src='/icons/bot.png' style='height:20px;margin-bottom:-3px;'/>");
  64.         country_name = "anna";
  65.         post.find(".flag").attr("data-country", country_name);
  66.         post.find(".flag").prepend(country);
  67.         } else {
  68.         var country_name = "";
  69.         //if (special_countries.indexOf(data.country)>-1) {
  70.         if (data.country[2] == "-") {
  71.             var state = $("<img src='/icons/countries2/"+data.country+".png'/>");
  72.             post.find(".flag").prepend(state);
  73.         if (special_countries && data.country in special_countries) {
  74.             country_name += special_countries[data.country]+", ";
  75.         } else {
  76.                 country_name += data.country.slice(3)+", ";
  77.             }
  78.         }
  79.         var country = $("<img src='/icons/countries2/"+data.country.slice(0,2)+".png'/>");
  80.         country_name += data.country_name ? data.country_name : data.country;
  81.         post.find(".flag").attr("data-country", country_name);
  82.         post.find(".flag").prepend(country);
  83.         }
  84.         post.find(".flag").click(function(){
  85.             var language;
  86.             if (window.navigator) language = window.navigator.userLanguage || window.navigator.language;
  87.             if (!language) language = "en";
  88.             language = language.slice(0,2);
  89.             ajaxTranslate(post.find(".chat_body").text(), "", language, function(data){
  90.                 post.find(".chat_body").append($("<span>").text(data).prepend($("<br>")));
  91.             });
  92.             post.find(".flag").unbind("click");
  93.         })
  94.     }
  95.     if (changed.trip) {
  96.         var special = ($.inArray(data.trip, special_trips)>-1);
  97.         var contrib = ($.inArray(data.trip, contribs) > -1);
  98.         var admin = ($.inArray(data.trip, admins) > -1);
  99.         var dev = ($.inArray(data.trip, devs) > -1);
  100.         var colortrip = ($.inArray(data.trip, Object.keys(color_trips)) > -1);
  101.         post.find(".trip_code")
  102.                         .text(data.trip)
  103.             .toggleClass("hidden", special || admin || dev || contrib || colortrip);
  104.         var addend = dev ? " ## Developer" : "";
  105.         addend = admin ? " ## Mod" : addend;
  106.         post.find(".chat_name")
  107.             .toggleClass("contrib", contrib)
  108.             .toggleClass("admin", admin)
  109.             .toggleClass("dev", dev)
  110.             .append(addend);
  111.         if(colortrip) {
  112.             post.find(".chat_name").css({'color': color_trips[data.trip]});
  113.         }
  114.     }
  115.     if (changed.convo || changed.convo_id) {
  116.         var is_op = (data.convo_id === data.count);
  117.         if (data.convo !== "" && data.convo !== "General" &&
  118.             $.inArray(data.convo, Object.keys(convo_map)) < 0){
  119.             convo_map[data.convo] = data.convo_id;
  120.         }
  121.         post.toggleClass("convo_op", is_op);
  122.         var chat_convo = post.find(".chat_convo");
  123.         chat_convo
  124.         .text(data.convo + (is_op ? " (OP)" : ""))
  125.         .css({
  126.             background:getRandomColor(hashString(data.convo))
  127.         });
  128.         if (!is_op) chat_convo.data("dest", data.convo_id);
  129.     }
  130.     if (changed.convo || new_post) {
  131.         apply_filter(post);
  132.     }
  133.     if (changed.date) {
  134.         var date = new Date(data.date);
  135.         date = (date == "NaN") ? data.date : date.toLocaleString();
  136.         post.find(".chat_date").text(date);
  137.     }
  138.     if (changed.image || changed.thumb) {
  139.         post.find(".chat_file").css("display", data.image ? "block" : "none");
  140.         var audio_container = post.find(".chat_audio_cont");
  141.         audio_container.empty();
  142.         var img_container = post.find(".chat_img_cont");
  143.         img_container.empty();
  144.  
  145.         if (data.image) {
  146.             var base_name = data.image.match(/[\w\-\.]*$/)[0];
  147.             var extension = base_name.match(/\w*$/)[0];
  148.             var url_file = "/tmp/uploads/" + base_name;
  149.  
  150.             post.find(".file_link")
  151.                 .attr("href", url_file)
  152.                 .text(base_name);
  153.  
  154.             if (extension === "ogg" || extension === "mp3" || extension === 'flac') {
  155.                 audio_container.append($("<audio/>").attr({src: url_file, controls: "controls", preload: "none"}));
  156.             }
  157.  
  158.             var url_static = null;
  159.             if (data.thumb) {
  160.                 url_static = "/tmp/thumb/" + data.thumb.match(/[\w\-\.]*$/)[0];
  161.             } else if ($.inArray(extension, ["jpg", "jpeg", "png"]) > -1) {
  162.                 url_static = url_file;
  163.             }
  164.             var url_anim = url_static;
  165.             if (extension === "gif") {
  166.                 url_anim = url_file;
  167.             }
  168.  
  169.             img_container.attr("href", url_file);
  170.             //img_container.css("height", (url_static !== null || url_anim !== null) ? 104 : 0);
  171.             img_container.css("height", (url_static !== null || url_anim !== null) ? 'auto' : 0);
  172.             if (url_static !== null) {
  173.                 img_container.append($("<img class='chat_img thumb_static'>").attr("src", url_static));
  174.             }
  175.             if (url_anim !== null) {
  176.                 img_container.append($("<img class='chat_img thumb_anim'>").attr("src", url_anim));
  177.             }
  178.             img_container.find(".chat_img")
  179.                 .css("display", "none")
  180.                 .attr("alt", "Image #" + data.count);
  181.  
  182.             if ($("#thumbnail_mode").val() === "static") img_container.find(".thumb_static").css("display", "inline");
  183.             if ($("#thumbnail_mode").val() === "animated") img_container.find(".thumb_anim").css("display", "inline");
  184.         }
  185.     }
  186.     if (changed.image || changed.image_filesize || changed.image_width || changed.image_height || changed.image_filename) {
  187.         var data_items = [];
  188.         if (data.image_filesize !== undefined) {
  189.             data_items.push(humanFileSize(data.image_filesize, false));
  190.         }
  191.         if (data.image_width !== undefined && data.image_height !== undefined) {
  192.             data_items.push(data.image_width + "x" + data.image_height);
  193.         }
  194.         if (data.duration !== undefined) {
  195.             var minutes = Math.floor(data.duration / 60);
  196.             var seconds = data.duration - 60 * minutes;
  197.             if (minutes > 0) {
  198.                 data_items.push(minutes + ":" + ("00" + Math.round(seconds)).slice(-2));
  199.             } else {
  200.                 data_items.push(seconds.toPrecision(3) + "s");
  201.             }
  202.         }
  203.         if (data.image_filename !== undefined) {
  204.             data_items.push(data.image_filename);
  205.         }
  206.         if (data_items.length > 0) {
  207.             post.find(".file_data").text("-(" + data_items.join(", ") + ")");
  208.         } else {
  209.             post.find(".file_data").text("");
  210.         }
  211.     }
  212.     if (changed.body) {
  213.         // Remove any old backlinks to this post
  214.         if (quote_links_to[id] !== undefined) {
  215.             $.each(quote_links_to[id], function() {
  216.                 if (this.hasClass("back_link")) this.remove();
  217.             });
  218.         }
  219.  
  220.         // Process body markup
  221.         var ref_ids = [];
  222.         var rules = [
  223.             [/>>>\/([a-z0-9]+)(?:[#\/](\d+))?/g, function(m, o) {
  224.                 o.push(board_link(m[1], m[2]));
  225.             }],
  226.             [/(?:\{(\d+)\}|>>(\d+))/g, function(m, o) {
  227.                 var ref_id = parseInt(m[1] ? m[1] : m[2], 10);
  228.                 if ($.inArray(ref_id, ref_ids) === -1) ref_ids.push(ref_id);
  229.                 o.push(quote_link(ref_id));
  230.             }],
  231.             [/^>+/mg, function(m, o) {
  232.                 var body = this.parse(rules, /$/mg);
  233.                 o.push($("<output class='greentext'/>").text(m[0]).append(body));
  234.             }],
  235.             [/\r?\n/g, function(m, o) {
  236.                 o.push($("<br>"));
  237.             }],
  238.             [/\[code(?: language=([a-z]+))?\](?:\r?\n)?/g, function(m, o) {
  239.                 var body = this.no_parse(/\[\/code\]/g);
  240.                 try {
  241.                     if (m[1]) {
  242.                         try {
  243.                             o.push($("<pre class='code'/>").html($("<code/>").html(hljs.highlight(m[1], body).value)));
  244.                         } catch(e) {
  245.                             o.push($("<pre class='code'/>").html($("<code/>").html(hljs.highlightAuto(body).value)));
  246.                         }
  247.                     } else {
  248.                         o.push($("<pre class='code'/>").html($("<code/>").html(hljs.highlightAuto(body).value)));
  249.                     }
  250.                 } catch(e) {
  251.                     o.push($("<pre class='code'/>").text(body));
  252.                 }
  253.             }],
  254.             [/\[spoiler\]/g, function(m, o) {
  255.                 var body = this.parse(rules, /\[\/spoiler\]/g);
  256.                 o.push($("<span class='spoiler'/>").append(body));
  257.             }],
  258.             [/(?:https?:\/\/)?(?:www\.)?(?:twitter\.com)\/(.*)/g, function(m, o) {
  259.                 var main = $("<span/>");
  260.                 var url = m[0][0] == 'y' ? "https://"+m[0] : m[0];
  261.                 var elem = $("<a target='_blank'/>").attr("href", url).text(m[0]);
  262.                 var embed = $("<span>(embed)</span>").css({cursor:"pointer", fontSize:'10px'});
  263.                 main.append(elem, " ", embed);
  264.                 o.push(main);
  265.                 var embedded = false;
  266.                 embed.click(function(e) {
  267.                     e.stopPropagation();
  268.                     if (embedded) {
  269.                         main.find("div.twit").remove();
  270.                     } else {
  271.                         $.ajax({
  272.                             url:'https://publish.twitter.com/oembed?url='+url,
  273.                             dataType:'jsonp',
  274.                             success:function(data){
  275.                                 main.append('<div class="twit">'+data.html+'</div>');
  276.                             }
  277.                         });
  278.                     }
  279.                     embedded = !embedded;
  280.                     embed.text(embedded ? "(unembed)" : "(embed)");
  281.                     var post = main.parents(".chat");
  282.                     post.toggleClass('chat_embed', embedded);// post.find("div.twit").length > 0);
  283.                 });
  284.             }],
  285.             [/(?:https?:\/\/)?(?:www\.)?(?:coub\.com)\/view\/(\S+)/g, function(m, o) {
  286.                 var main = $("<span/>");
  287.                 var url = m[0][0] == 'y' ? "https://"+m[0] : m[0];
  288.                 var elem = $("<a target='_blank'/>").attr("href", url).text(m[0]);
  289.                 var embed = $("<span>(embed)</span>").css({cursor:"pointer", fontSize:'10px'});
  290.                 main.append(elem, " ", embed);
  291.                 o.push(main);
  292.                 var embedded = false;
  293.                 embed.click(function(e) {
  294.                     e.stopPropagation();
  295.                     if (embedded) {
  296.                         main.find("iframe").remove();
  297.                     } else {
  298.                         var cb = $('<iframe allowfullscreen frameborder="0" width="640" height="360" allow="autoplay"></iframe>')
  299.                             .attr("src", '//coub.com/embed/'+m[1]+'?muted=false&autostart=false&originalSize=false&startWithHD=false')
  300.                             .css({float:"left", marginRight:'5px'});
  301.                         main.append(cb);
  302.                     }
  303.                     embedded = !embedded;
  304.                     embed.text(embedded ? "(unembed)" : "(embed)");
  305.                     var post = main.parents(".chat");
  306.                     post.toggleClass('chat_embed', post.find("iframe").length > 0);
  307.                 });
  308.             }],
  309.             [/(?:https?:\/\/)?(?:www\.)?(?:instagram\.com)\/(.*)/g, function(m, o) {
  310.                 var main = $("<span/>");
  311.                 var url = m[0][0] == 'y' ? "https://"+m[0] : m[0];
  312.                 var elem = $("<a target='_blank'/>").attr("href", url).text(m[0]);
  313.                 var embed = $("<span>(embed)</span>").css({cursor:"pointer", fontSize:'10px'});
  314.                 main.append(elem, " ", embed);
  315.                 o.push(main);
  316.                 var embedded = false;
  317.                 embed.click(function(e) {
  318.                     e.stopPropagation();
  319.                     if (embedded) {
  320.                         main.find("div.twit").remove();
  321.                     } else {
  322.                         $.ajax({
  323.                             url:'https://api.instagram.com/oembed?url='+url,
  324.                             dataType:'jsonp',
  325.                             success:function(data){
  326.                                 main.append('<div class="twit">'+data.html+'</div>');
  327.                             }
  328.                         });
  329.                     }
  330.                     embedded = !embedded;
  331.                     embed.text(embedded ? "(unembed)" : "(embed)");
  332.                     var post = main.parents(".chat");
  333.                     post.toggleClass('chat_embed', embedded);// post.find("div.twit").length > 0);
  334.                 });
  335.             }],
  336.             [/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(\S+)/g, function(m, o) {
  337.                 var main = $("<span/>");
  338.                 var url = m[0][0] == 'y' ? "https://"+m[0] : m[0];
  339.                 var elem = $("<a target='_blank'/>").attr("href", url).text(m[0]);
  340.                 var embed = $("<span>(embed)</span>").css({cursor:"pointer", fontSize:'10px'});
  341.                 main.append(elem, " ", embed);
  342.                 o.push(main);
  343.                 var embedded = false;
  344.                 embed.click(function(e) {
  345.                     e.stopPropagation();
  346.                     if (embedded) {
  347.                         main.find("iframe").remove();
  348.                     } else {
  349.                         var yt = $("<iframe width='560' height='315' style='max-width:100%;' frameborder='0' allowfullscreen></iframe>")
  350.                             .attr("src", "https://www.youtube.com/embed/"+m[1]).css({float:"left", marginRight:'5px'});
  351.                         main.append(yt);
  352.                     }
  353.                     embedded = !embedded;
  354.                     embed.text(embedded ? "(unembed)" : "(embed)");
  355.                     var post = main.parents(".chat");
  356.                     post.toggleClass('chat_embed', post.find("iframe").length > 0);
  357.                 });
  358.                 get_youtube_data(m[1],elem);
  359.             }],
  360.             [/(?:https?:\/\/)?(?:www\.)?(?:music\.yandex\.[a-z]{2})\/album\/(\d+)\/track\/(\d+)\/?/g, function(m, o){
  361.                 var main = $("<span/>");        
  362.                 var url = m[0][0] == 'y' ? "https://"+m[0] : m[0];
  363.                 var elem = $("<a target='_blank' class='yandex'/>").attr("href", url).text(url);
  364.                 var embed = $("<span>(embed)</span>").css({cursor:"pointer", fontSize:'10px'});
  365.                 main.append(elem, " ", embed);  
  366.                 o.push(main);  
  367.                 var embedded = false;          
  368.                 embed.click(function(e) {      
  369.                     e.stopPropagation();            
  370.                         if (embedded) {                
  371.                             main.find("iframe").remove();  
  372.                         } else {
  373.                             var src = "https://music.yandex.ru/iframe/#track/"+ m[2] + "/";
  374.                             main.append($('<iframe frameborder="0" style="border:none;width:400px;height:100px;" width="400" height="100">')
  375.                                 .attr('src', src));            
  376.                         }
  377.                     embedded = !embedded;          
  378.                     embed.text(embedded ? "(unembed)" : "(embed)");
  379.                     var post = main.parents(".chat");
  380.                     post.toggleClass('chat_embed', post.find("iframe").length > 0);
  381.                 });
  382.             }],
  383.             [/https?:\/\/\S+()/g, function(m, o) { // stupid extra () is for some syntax highlighters to play nice.
  384.                 o.push($("<a target='_blank'/>").attr("href", m[0]).text(m[0]));
  385.             }],
  386.             [/\[b\]/g, function(m, o) {
  387.                 var body = this.parse(rules, /\[\/b\]/g);
  388.                 o.push($("<span style='font-weight: bold;'/>").append(body));
  389.             }],
  390.             [/\[i\]/g, function(m, o) {
  391.                 var body = this.parse(rules, /\[\/i\]/g);
  392.                 o.push($("<span style='font-style: italic;'/>").append(body));
  393.             }],
  394.             [/\[u\]/g, function(m, o) {
  395.                 var body = this.parse(rules, /\[\/u\]/g);
  396.                 o.push($("<span style='text-decoration: underline;'/>").append(body));
  397.             }],
  398.             [/\[s\]/g, function(m, o) {
  399.                 var body = this.parse(rules, /\[\/s\]/g);
  400.                 o.push($("<span style='text-decoration: line-through;'/>").append(body));
  401.             }],
  402.             [/\[ree\]/g, function(m, o) {
  403.                 var body = this.parse(rules, /\[\/ree\]/g);
  404.                 o.push($("<article class='shake'/>").append(body));
  405.             }],
  406.             [/\[roll\]/g, function(m, o) {
  407.                 var body = this.parse(rules, /\[\/roll\]/g);
  408.                 o.push($("<article class='roll'/>").append(body));
  409.             }],
  410.             [/\[lspin\]/g, function(m, o) {
  411.                 var body = this.parse(rules, /\[\/lspin\]/g);
  412.                 o.push($("<article class='lspin'/>").append(body));
  413.             }],
  414.             [/\[spin\]/g, function(m, o) {
  415.                 var body = this.parse(rules, /\[\/spin\]/g);
  416.                 o.push($("<article class='spin'/>").append(body));
  417.             }],
  418.             [/\[hflip\]/g, function(m, o) {
  419.                 var body = this.parse(rules, /\[\/hflip\]/g);
  420.                 o.push($("<article class='hflip'/>").append(body));
  421.             }],
  422.             [/\[vflip\]/g, function(m, o) {
  423.                 var body = this.parse(rules, /\[\/vflip\]/g);
  424.                 o.push($("<article class='vflip'/>").append(body));
  425.             }],
  426.             [/\[nonono\]/g, function(m, o) {
  427.                 var body = this.parse(rules, /\[\/nonono\]/g);
  428.                 o.push($("<article class='nonono'/>").append(body));
  429.             }],
  430.             [/\[color=([#\w]+)\]/g, function(m, o) {
  431.                 var body = this.parse(rules, /\[\/color\]/g);
  432.                 if ($('#spoilers').prop("checked")) {
  433.                     o.push($("<span/>").css("color", m[1]).append(body));
  434.                 } else {
  435.                     o.push($("<span/>").append(body));
  436.                 }
  437.             }],
  438.             [/\[rotate=([+-]{0,1}[\d]+)\]/g, function(m, o) {
  439.                 var body = this.parse(rules, /\[\/rotate\]/g);
  440.                 o.push($("<article/>").css("transform", "rotate("+m[1]+"deg)").css("display", "inline-block").append(body));
  441.             }],
  442.             [/\[flag\]/g, function(m, o) {
  443.                 var body = this.parse(rules, /\[\/flag\]/g);
  444.                 if (special_countries) {
  445.                     o.push($("<img/>").attr("src", encodeURI("/icons/countries2/"+body[0].data.replace('/','').toUpperCase()+".png")).css({height:"44px"}));
  446.                 } else {
  447.                     o.push($("<span>").text(body[0].data.toUpperCase()));
  448.                 }
  449.             }],
  450.             [/\[st\]/g, function(m, o) {
  451.                 var body = this.parse(rules, /\[\/st\]/g);
  452.                 o.push($("<img/>").attr("src", encodeURI("/images/stickers/"+body[0].data.replace('/','')+".png")).css({'min-height':"64px"}).css({'max-height':'100px'}).click(sticker_click));
  453.             }],
  454.             [/\[noparse\]/g, function(m, o) {
  455.                 var body = this.no_parse(/\[\/noparse\]/g);
  456.                 o.push(document.createTextNode(body));
  457.             }]
  458.         ];
  459.         var smiles = [
  460.             [/\:\-\)|\:\)|\=\)/g, function(m, o) {
  461.                 o.push($("<img/>").attr("src", "/icons/smiles/ab.gif"));
  462.             }],
  463.             [/\:\-\(|\:\(|\;\(/g, function(m, o) {
  464.                 o.push($("<img/>").attr("src", "/icons/smiles/ac.gif"));
  465.             }],
  466.             [/\:\-P/g, function(m, o) {
  467.                 o.push($("<img/>").attr("src", "/icons/smiles/ae.gif"));
  468.             }],
  469.             [/8\-\)/g, function(m, o) {
  470.                 o.push($("<img/>").attr("src", "/icons/smiles/af.gif"));
  471.             }],
  472.             [/\:\-D/g, function(m, o) {
  473.                 o.push($("<img/>").attr("src", "/icons/smiles/ag.gif"));
  474.             }],
  475.             [/\:\-\[/g, function(m, o) {
  476.                 o.push($("<img/>").attr("src", "/icons/smiles/ah.gif"));
  477.             }],
  478.             [/\=\-O/g, function(m, o) {
  479.                 o.push($("<img/>").attr("src", "/icons/smiles/ai.gif"));
  480.             }],
  481.             [/\:\'\(/g, function(m, o) {
  482.                o.push($("<img/>").attr("src", "/icons/smiles/ak.gif"));
  483.            }],
  484.            [/\:\-X|\:\-x/g, function(m, o) {
  485.                o.push($("<img/>").attr("src", "/icons/smiles/al.gif"));
  486.            }],
  487.            [/\>\:o/g, function(m, o) {
  488.                o.push($("<img/>").attr("src", "/icons/smiles/am.gif"));
  489.            }],
  490.            [/\:\-\|/g, function(m, o) {
  491.                o.push($("<img/>").attr("src", "/icons/smiles/an.gif"));
  492.            }],
  493.            [/\:\-\\|\:\-\//g, function(m, o) {
  494.                o.push($("<img/>").attr("src", "/icons/smiles/ao.gif"));
  495.            }],
  496.            [/\*JOKINGLY\*/g, function(m, o) {
  497.                o.push($("<img/>").attr("src", "/icons/smiles/ap.gif"));
  498.            }],
  499.            [/\]\:\-\>/g, function(m, o) {
  500.                o.push($("<img/>").attr("src", "/icons/smiles/aq.gif"));
  501.            }],
  502.            [/\[\:\-\}/g, function(m, o) {
  503.                o.push($("<img/>").attr("src", "/icons/smiles/ar.gif"));
  504.            }],
  505.            [/\:\-\!/g, function(m, o) {
  506.                o.push($("<img/>").attr("src", "/icons/smiles/at.gif"));
  507.            }],
  508.            [/\*TIRED\*/g, function(m, o) {
  509.                o.push($("<img/>").attr("src", "/icons/smiles/au.gif"));
  510.            }],
  511.            [/\*STOP\*/g, function(m, o) {
  512.                o.push($("<img/>").attr("src", "/icons/smiles/av.gif"));
  513.            }],
  514.            [/\*THUMBS|UP\*/g, function(m, o) {
  515.                o.push($("<img/>").attr("src", "/icons/smiles/ay.gif"));
  516.            }],
  517.            [/\*DRINK\*/g, function(m, o) {
  518.                o.push($("<img/>").attr("src", "/icons/smiles/az.gif"));
  519.            }],
  520.            [/\*HELP\*/g, function(m, o) {
  521.                o.push($("<img/>").attr("src", "/icons/smiles/bc.gif"));
  522.            }],
  523.            [/\\m\//g, function(m, o) {
  524.                o.push($("<img/>").attr("src", "/icons/smiles/bd.gif"));
  525.            }],
  526.            [/\%\)/g, function(m, o) {
  527.                o.push($("<img/>").attr("src", "/icons/smiles/be.gif"));
  528.            }],
  529.            [/\*OK\*/g, function(m, o) {
  530.                o.push($("<img/>").attr("src", "/icons/smiles/bf.gif"));
  531.            }],
  532.            [/\*SORRY\*/g, function(m, o) {
  533.                o.push($("<img/>").attr("src", "/icons/smiles/bh.gif"));
  534.            }],
  535.            [/\*ROFL\*|\*LOL\*/g, function(m, o) {
  536.                o.push($("<img/>").attr("src", "/icons/smiles/bj.gif"));
  537.            }],
  538.            [/\*NO\*/g, function(m, o) {
  539.                o.push($("<img/>").attr("src", "/icons/smiles/bl.gif"));
  540.            }],
  541.            [/\*CRAZY\*/g, function(m, o) {
  542.                o.push($("<img/>").attr("src", "/icons/smiles/bm.gif"));
  543.            }],
  544.            [/\*DUNNO\*/g, function(m, o) {
  545.                o.push($("<img/>").attr("src", "/icons/smiles/bn.gif"));
  546.            }],
  547.            [/\*DANCE\*/g, function(m, o) {
  548.                o.push($("<img/>").attr("src", "/icons/smiles/bo.gif"));
  549.            }],
  550.            [/\*YAHOO\*/g, function(m, o) {
  551.                o.push($("<img/>").attr("src", "/icons/smiles/bp.gif"));
  552.            }],
  553.            [/\*HI\*/g, function(m, o) {
  554.                o.push($("<img/>").attr("src", "/icons/smiles/bq.gif"));
  555.            }],
  556.            [/\*BYE\*/g, function(m, o) {
  557.                o.push($("<img/>").attr("src", "/icons/smiles/br.gif"));
  558.            }],
  559.            [/\*YES\*/g, function(m, o) {
  560.                o.push($("<img/>").attr("src", "/icons/smiles/bs.gif"));
  561.            }],
  562.            [/\;D/g, function(m, o) {
  563.                o.push($("<img/>").attr("src", "/icons/smiles/bt.gif"));
  564.            }],
  565.            [/\*WALL\*/g, function(m, o) {
  566.                o.push($("<img/>").attr("src", "/icons/smiles/bu.gif"));
  567.            }],
  568.            [/\*SCRATCH\*/g, function(m, o) {
  569.                o.push($("<img/>").attr("src", "/icons/smiles/bw.gif"));
  570.            }],
  571.            [/\*BANANA\*/g, function(m, o) {
  572.                o.push($("<img/>").attr("src", "/icons/smiles/banana.gif"));
  573.            }],
  574.            [/\*SUP\*/g, function(m, o) {
  575.                o.push($("<img/>").attr("src", "/icons/smiles/bg.gif"));
  576.            }],
  577.            [/\*YEEES\!\*/g, function(m, o) {
  578.                o.push($("<img/>").attr("src", "/icons/smiles/bx.gif"));
  579.            }],
  580.            [/\*SMOKE\*/g, function(m, o) {
  581.                o.push($("<img/>").attr("src", "/icons/smiles/by.gif"));
  582.            }],
  583.            [/\*GAMER\*/g, function(m, o) {
  584.                o.push($("<img/>").attr("src", "/icons/smiles/cc.gif"));
  585.            }],
  586.            [/\*BLACKEYE\*/g, function(m, o) {
  587.                o.push($("<img/>").attr("src", "/icons/smiles/cg.gif"));
  588.            }],
  589.            [/\*SEARCH\*/g, function(m, o) {
  590.                o.push($("<img/>").attr("src", "/icons/smiles/ci.gif"));
  591.            }],
  592.            [/\*FOCUS\*/g, function(m, o) {
  593.                o.push($("<i    mg/>").attr("src", "/icons/smiles/ck.gif"));
  594.            }],
  595.            [/\*HUNTER\*/g, function(m, o) {
  596.                o.push($("<img/>").attr("src", "/icons/smiles/cl.gif"));
  597.            }],
  598.            [/X\)/g, function(m, o) {
  599.                o.push($("<img/>").attr("src", "/icons/smiles/dc.gif"));
  600.            }],
  601.            [/\*JOB\*/g, function(m, o) {
  602.                o.push($("<img/>").attr("src", "/icons/smiles/de.gif"));
  603.            }],
  604.            [/\*THANK\*/g, function(m, o) {
  605.                o.push($("<img/>").attr("src", "/icons/smiles/dh.gif"));
  606.            }],
  607.            [/\*LAZY\*/g, function(m, o) {
  608.                o.push($("<img/>").attr("src", "/icons/smiles/dj.gif"));
  609.            }],
  610.            [/\*WIZARD\*/g, function(m, o) {
  611.                o.push($("<img/>").attr("src", "/icons/smiles/dm.gif"));
  612.            }],
  613.            [/\*TEASE\*/g, function(m, o) {
  614.                o.push($("<img/>").attr("src", "/icons/smiles/dp.gif"));
  615.            }],
  616.            [/\*TRAINING\*/g, function(m, o) {
  617.                o.push($("<img/>").attr("src", "/icons/smiles/du.gif"));
  618.            }],
  619.            [/\*POPCORN\*/g, function(m, o) {
  620.                o.push($("<img/>").attr("src", "/icons/smiles/dw.gif"));
  621.            }],
  622.            [/\*PARDON\*/g, function(m, o) {
  623.                o.push($("<img/>").attr("src", "/icons/smiles/pardon.gif"));
  624.            }],
  625.        ];
  626.        rules = rules.concat(smiles);
  627.        var body = new Parser(data.body).parse(rules);
  628.        post.find(".chat_body").empty().append(body);
  629.        
  630.        var for_you = /\(You\)/.test(post.find(".quote_link").text());
  631.        
  632.        if (for_you) {
  633.             post.toggleClass("chat_highlight", true);
  634.         }
  635.        
  636.         if (admin_pass != "" && /(admin|dev(eloper)?)/.test(post.find(".chat_body").text().toLowerCase())) {
  637.             post.toggleClass("chat_highlight", true);
  638.             for_you = true;
  639.         }
  640.        
  641.         if (highlight_regex && highlight_regex.test(post.find(".chat_body").text().toLowerCase())) {
  642.             post.toggleClass("chat_highlight", true);
  643.             for_you = true;
  644.         }
  645.  
  646.        // Create new backlinks
  647.        $(ref_ids).each(function () {
  648.            var link = quote_link(id);
  649.            link.addClass("back_link");
  650.            var their_refs = $("#chat_" + this + " .chat_refs");
  651.            if (their_refs.length === 0) {
  652.                if (future_ids[this] === undefined) future_ids[this] = $("<output />");
  653.                future_ids[this].append(" ", link);
  654.            } else {
  655.                their_refs.append(" ", link);
  656.            }
  657.        });
  658.    }
  659.  
  660.    if (new_post) {
  661.        // Place post conversation at top of list
  662.        var convo_index = $.inArray(data.convo, convos);
  663.        if (convo_index < 0) {
  664.            convos.push(data.convo);
  665.            //highlighted_convos.push(data.convo);
  666.        } else {
  667.            convos.splice(convo_index,1);
  668.            convos.push(data.convo);
  669.        }
  670.        if (!first_load) draw_convos();
  671.  
  672.        // Activate blinking title to notify user of new posts
  673.        if (!first_load) notifications(data.convo, for_you);
  674.  
  675.        // Insert post into chat (with fade-in animation if not first load)
  676.        if (!first_load) {
  677.            post.css('opacity', '0');
  678.        }
  679.        
  680.        if (!first_load) {
  681.             var keys = Object.keys(chat);
  682.             var count_convo = 0;
  683.             for (var k in keys) {
  684.                 if (data.convo === chat[keys[k]].convo)
  685.                     count_convo++;
  686.             }
  687.             if ($("#autoscroll").prop('checked')) {
  688.                 while (count_convo > max_chats) {
  689.                     var i = 0;
  690.                     while (data.convo !== chat[keys[i]].convo || chat[keys[i]].convo_id === chat[keys[i]].count) {
  691.                         i++;
  692.                     }
  693.                    
  694.                     var old_chat = keys[i];
  695.                     $("#chat_"+old_chat).remove();
  696.                     delete chat[old_chat];
  697.                     keys = Object.keys(chat);
  698.                     count_convo--;
  699.                 }
  700.             }
  701.         }
  702.        
  703.        var post_id = post.attr('id').split("_")[1];
  704.        
  705.        insert_post(post, data.chat);
  706.        if (!first_load) {
  707.            post.animate({
  708.                opacity: 1
  709.            }, 300, 'swing', function () {
  710.            });
  711.        }
  712.    }
  713.    
  714.    $(".spoiler").toggleClass("spoiled", !$('#spoilers').prop("checked"));
  715. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement