From f53e8fbae8ba6dfc4817dcdbbb9373ea5a0f3484 Mon Sep 17 00:00:00 2001 From: Aylong <69762909+Aylong220@users.noreply.github.com> Date: Sat, 27 Jan 2024 19:03:05 +0200 Subject: [PATCH] Fix: Chat Highlights - NoCrush Edition (#948) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Что этот PR делает Починка подсветки кириллицы, ноу вылет эдишн (наверное) ## Почему это хорошо для игры ## Изображения изменений ![image](https://github.com/ss220club/Paradise-SS220/assets/69762909/842808d8-6015-4654-aeab-8cb2f53f02e4) ## Тестирование Блять ## Changelog :cl: tweak: Добавлена подсветка слов в чате на кириллице /:cl: --- tgui/packages/tgui-panel/chat/renderer.js | 2 +- tgui/packages/tgui-panel/chat/replaceInTextNode.js | 2 +- tgui/public/tgui-panel.bundle.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tgui/packages/tgui-panel/chat/renderer.js b/tgui/packages/tgui-panel/chat/renderer.js index e18414f9cb08..37e6780657ad 100644 --- a/tgui/packages/tgui-panel/chat/renderer.js +++ b/tgui/packages/tgui-panel/chat/renderer.js @@ -190,7 +190,7 @@ class ChatRenderer { const highlightWholeMessage = setting.highlightWholeMessage; const matchWord = setting.matchWord; const matchCase = setting.matchCase; - const allowedRegex = /^[a-z0-9_\-$/^[\s\]\\]+$/gi; + const allowedRegex = /^[a-zа-яё0-9_\-$/^[\s\]\\]+$/gi; // SS220 EDIT - CYRILLIC SUPPORT const regexEscapeCharacters = /[!#$%^&*)(+=.<>{}[\]:;'"|~`_\-\\/]/g; const lines = String(text) .split(/[,|]/) diff --git a/tgui/packages/tgui-panel/chat/replaceInTextNode.js b/tgui/packages/tgui-panel/chat/replaceInTextNode.js index 753997b3b821..2242d84d43ec 100644 --- a/tgui/packages/tgui-panel/chat/replaceInTextNode.js +++ b/tgui/packages/tgui-panel/chat/replaceInTextNode.js @@ -93,7 +93,7 @@ export const replaceInTextNode = (regex, words, createNode) => (node) => { for (let word of words) { // Capture if the word is at the beginning, end, middle, // or by itself in a message - wordRegexStr += `^${word}\\W|\\W${word}\\W|\\W${word}$|^${word}$`; + wordRegexStr += `^${word}\\S\\w|\\S\\w${word}\\S\\w|\\S\\w${word}$|^${word}\\S\\w$`; // SS220 EDIT - CYRILLIC SUPPORT // Make sure the last character for the expression is NOT '|' if (++i !== words.length) { wordRegexStr += '|'; diff --git a/tgui/public/tgui-panel.bundle.js b/tgui/public/tgui-panel.bundle.js index cadf20f322ea..94e2f6271f81 100644 --- a/tgui/public/tgui-panel.bundle.js +++ b/tgui/public/tgui-panel.bundle.js @@ -134,11 +134,11 @@ * @file * @copyright 2020 Aleksej Komarov * @license MIT -*/var u=(0,o.createLogger)("chatRenderer"),v=24,s=function(S){for(var b=document.body,C=S;C&&C!==b;){if(C.scrollWidth=a.IMAGE_RETRY_LIMIT){u.error("failed to load an image after "+C+" attempts");return}var P=b.src;b.src=null,b.src=P+"#"+C,b.setAttribute("data-reload-n",C+1)},a.IMAGE_RETRY_DELAY)},E=function(S){var b=S.node,C=S.times;if(!(!b||!C)){var P=b.querySelector(".Chat__badge"),N=P||document.createElement("div");N.textContent=C,N.className=(0,r.classes)(["Chat__badge","Chat__badge--animate"]),requestAnimationFrame(function(){N.className="Chat__badge"}),P||b.appendChild(N)}},I=function(){function T(){var b=this;this.loaded=!1,this.rootNode=null,this.queue=[],this.messages=[],this.visibleMessages=[],this.page=null,this.events=new n.EventEmitter,this.scrollNode=null,this.scrollTracking=!0,this.handleScroll=function(C){var P=b.scrollNode,N=P.scrollHeight,w=P.scrollTop+P.offsetHeight,M=Math.abs(N-w)0&&(this.processBatch(this.queue),this.queue=[])}return b}(),S.assignStyle=function(){function b(C){C===void 0&&(C={});for(var P=0,N=Object.keys(C);P{}[\]:;'"|~`_\-\\/]/g,V=String(L).split(/[,|]/).map(function(it){return it.trim()}).filter(function(it){return it&&it.length>1&&D.test(it)&&((D.lastIndex=0)||!0)}),G,Y;if(V.length!==0){for(var z=[],et=c(V),at;!(at=et()).done;){var ft=at.value;if(ft.charAt(0)==="/"&&ft.charAt(ft.length-1)==="/"){var W=ft.substring(1,ft.length-1);if(/^(\[.*\]|\\.|.)$/.test(W))continue;z.push(W)}else G||(G=[]),ft=ft.replace(F,"\\$&"),G.push(ft)}var X=z.join("|"),nt="g"+($?"":"i");try{if(X)Y=new RegExp("("+X+")",nt);else{var ct=(U?"\\b":"")+"("+G.join("|")+")"+(U?"\\b":"");Y=new RegExp(ct,nt)}}catch(it){Y=null}N.highlightParsers||(N.highlightParsers=[]),N.highlightParsers.push({highlightWords:G,highlightRegex:Y,highlightColor:K,highlightWholeMessage:x})}})}return b}(),S.scrollToBottom=function(){function b(){this.scrollNode.scrollTop=this.scrollNode.scrollHeight}return b}(),S.changePage=function(){function b(C){if(!this.isReady()){this.page=C,this.tryFlushQueue();return}this.page=C,this.rootNode.textContent="",this.visibleMessages=[];for(var P=document.createDocumentFragment(),N,w=c(this.messages),M;!(M=w()).done;){var L=M.value;(0,i.canPageAcceptType)(C,L.type)&&(N=L.node,P.appendChild(N),this.visibleMessages.push(L))}N&&(this.rootNode.appendChild(P),N.scrollIntoView())}return b}(),S.getCombinableMessage=function(){function b(C){for(var P=Date.now(),N=this.visibleMessages.length,w=N-1,M=Math.max(0,N-a.COMBINE_MAX_MESSAGES),L=w;L>=M;L--){var K=this.visibleMessages[L],x=!K.type.startsWith(a.MESSAGE_TYPE_INTERNAL)&&(0,i.isSameMessage)(K,C)&&P0){this.visibleMessages=C.slice(P);for(var N=0;N0&&(this.messages=this.messages.slice(M),u.log("pruned "+M+" stored messages"))}}}return b}(),S.rebuildChat=function(){function b(){if(this.isReady()){for(var C=Math.max(0,this.messages.length-a.MAX_PERSISTED_MESSAGES),P=this.messages.slice(C),N=c(P),w;!(w=N()).done;){var M=w.value;M.node=void 0}this.rootNode.textContent="",this.messages=[],this.visibleMessages=[],this.processBatch(P,{notifyListeners:!1})}}return b}(),S.clearChat=function(){function b(){var C=this.visibleMessages;this.visibleMessages=[];for(var P=0;P\n\n\n
\n'+K+"
\n\n\n",F=new Blob([D]),V=new Date().toISOString().substring(0,19).replace(/[-:]/g,"").replace("T","-");window.navigator.msSaveBlob(F,"ss13-chatlog-"+V+".html")}}return b}(),T}();window.__chatRenderer__||(window.__chatRenderer__=new I);var O=e.chatRenderer=window.__chatRenderer__},97507:function(y,e){"use strict";e.__esModule=!0,e.replaceInTextNode=e.linkifyNode=e.highlightNode=void 0;function t(u,v){var s=typeof Symbol!="undefined"&&u[Symbol.iterator]||u["@@iterator"];if(s)return(s=s.call(u)).next.bind(s);if(Array.isArray(u)||(s=n(u))||v&&u&&typeof u.length=="number"){s&&(u=s);var p=0;return function(){return p>=u.length?{done:!0}:{done:!1,value:u[p++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(u,v){if(u){if(typeof u=="string")return r(u,v);var s=Object.prototype.toString.call(u).slice(8,-1);if(s==="Object"&&u.constructor&&(s=u.constructor.name),s==="Map"||s==="Set")return Array.from(u);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return r(u,v)}}function r(u,v){(v==null||v>u.length)&&(v=u.length);for(var s=0,p=new Array(v);s=a.IMAGE_RETRY_LIMIT){u.error("failed to load an image after "+C+" attempts");return}var P=b.src;b.src=null,b.src=P+"#"+C,b.setAttribute("data-reload-n",C+1)},a.IMAGE_RETRY_DELAY)},E=function(S){var b=S.node,C=S.times;if(!(!b||!C)){var P=b.querySelector(".Chat__badge"),N=P||document.createElement("div");N.textContent=C,N.className=(0,r.classes)(["Chat__badge","Chat__badge--animate"]),requestAnimationFrame(function(){N.className="Chat__badge"}),P||b.appendChild(N)}},I=function(){function T(){var b=this;this.loaded=!1,this.rootNode=null,this.queue=[],this.messages=[],this.visibleMessages=[],this.page=null,this.events=new n.EventEmitter,this.scrollNode=null,this.scrollTracking=!0,this.handleScroll=function(C){var P=b.scrollNode,N=P.scrollHeight,w=P.scrollTop+P.offsetHeight,M=Math.abs(N-w)0&&(this.processBatch(this.queue),this.queue=[])}return b}(),S.assignStyle=function(){function b(C){C===void 0&&(C={});for(var P=0,N=Object.keys(C);P{}[\]:;'"|~`_\-\\/]/g,V=String(L).split(/[,|]/).map(function(it){return it.trim()}).filter(function(it){return it&&it.length>1&&D.test(it)&&((D.lastIndex=0)||!0)}),G,Y;if(V.length!==0){for(var z=[],et=c(V),at;!(at=et()).done;){var ft=at.value;if(ft.charAt(0)==="/"&&ft.charAt(ft.length-1)==="/"){var W=ft.substring(1,ft.length-1);if(/^(\[.*\]|\\.|.)$/.test(W))continue;z.push(W)}else G||(G=[]),ft=ft.replace(F,"\\$&"),G.push(ft)}var X=z.join("|"),nt="g"+($?"":"i");try{if(X)Y=new RegExp("("+X+")",nt);else{var ct=(U?"\\b":"")+"("+G.join("|")+")"+(U?"\\b":"");Y=new RegExp(ct,nt)}}catch(it){Y=null}N.highlightParsers||(N.highlightParsers=[]),N.highlightParsers.push({highlightWords:G,highlightRegex:Y,highlightColor:K,highlightWholeMessage:x})}})}return b}(),S.scrollToBottom=function(){function b(){this.scrollNode.scrollTop=this.scrollNode.scrollHeight}return b}(),S.changePage=function(){function b(C){if(!this.isReady()){this.page=C,this.tryFlushQueue();return}this.page=C,this.rootNode.textContent="",this.visibleMessages=[];for(var P=document.createDocumentFragment(),N,w=c(this.messages),M;!(M=w()).done;){var L=M.value;(0,i.canPageAcceptType)(C,L.type)&&(N=L.node,P.appendChild(N),this.visibleMessages.push(L))}N&&(this.rootNode.appendChild(P),N.scrollIntoView())}return b}(),S.getCombinableMessage=function(){function b(C){for(var P=Date.now(),N=this.visibleMessages.length,w=N-1,M=Math.max(0,N-a.COMBINE_MAX_MESSAGES),L=w;L>=M;L--){var K=this.visibleMessages[L],x=!K.type.startsWith(a.MESSAGE_TYPE_INTERNAL)&&(0,i.isSameMessage)(K,C)&&P0){this.visibleMessages=C.slice(P);for(var N=0;N0&&(this.messages=this.messages.slice(M),u.log("pruned "+M+" stored messages"))}}}return b}(),S.rebuildChat=function(){function b(){if(this.isReady()){for(var C=Math.max(0,this.messages.length-a.MAX_PERSISTED_MESSAGES),P=this.messages.slice(C),N=c(P),w;!(w=N()).done;){var M=w.value;M.node=void 0}this.rootNode.textContent="",this.messages=[],this.visibleMessages=[],this.processBatch(P,{notifyListeners:!1})}}return b}(),S.clearChat=function(){function b(){var C=this.visibleMessages;this.visibleMessages=[];for(var P=0;P\n\n\n
\n'+K+"
\n\n\n",F=new Blob([D]),V=new Date().toISOString().substring(0,19).replace(/[-:]/g,"").replace("T","-");window.navigator.msSaveBlob(F,"ss13-chatlog-"+V+".html")}}return b}(),T}();window.__chatRenderer__||(window.__chatRenderer__=new I);var O=e.chatRenderer=window.__chatRenderer__},97507:function(y,e){"use strict";e.__esModule=!0,e.replaceInTextNode=e.linkifyNode=e.highlightNode=void 0;function t(u,v){var s=typeof Symbol!="undefined"&&u[Symbol.iterator]||u["@@iterator"];if(s)return(s=s.call(u)).next.bind(s);if(Array.isArray(u)||(s=n(u))||v&&u&&typeof u.length=="number"){s&&(u=s);var p=0;return function(){return p>=u.length?{done:!0}:{done:!1,value:u[p++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(u,v){if(u){if(typeof u=="string")return r(u,v);var s=Object.prototype.toString.call(u).slice(8,-1);if(s==="Object"&&u.constructor&&(s=u.constructor.name),s==="Map"||s==="Set")return Array.from(u);if(s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return r(u,v)}}function r(u,v){(v==null||v>u.length)&&(v=u.length);for(var s=0,p=new Array(v);s9999)return{};b||(b=document.createDocumentFragment()),I||(I=[]);var N=g?g(T[0]):T[0],w=N.length,M=T.index+T[0].indexOf(N);S9999)return{};b||(b=document.createDocumentFragment()),I||(I=[]);var N=g?g(T[0]):T[0],w=N.length,M=T.index+T[0].indexOf(N);S