Files
CHOMPStation2/code/modules/vchat/js/vchat.min.js
2023-12-10 02:24:02 +01:00

2 lines
16 KiB
JavaScript

!function(){var e=console.log;console.log=function(t){send_debug(t),e.apply(console,arguments)};var t=console.error;console.error=function(e){send_debug(e),t.apply(console,arguments)},window.onerror=function(e,t,s,a,o){var n="";return o&&o.stack&&(n=o.stack),send_debug(e+" ("+t+"@"+s+":"+a+") "+o+"|UA: "+navigator.userAgent+"|Stack: "+n),!0}}();var vchat_opts={msBeforeDropped:3e4,cookiePrefix:"vst-",alwaysShow:["vc_adminpm","vc_system"],vchatTabsVer:1},DARKMODE_COLORS={buttonBgColor:"#40628a",buttonTextColor:"#FFFFFF",windowBgColor:"#272727",highlightColor:"#009900",tabTextColor:"#FFFFFF",tabBackgroundColor:"#272727"},LIGHTMODE_COLORS={buttonBgColor:"none",buttonTextColor:"#000000",windowBgColor:"none",highlightColor:"#007700",tabTextColor:"#000000",tabBackgroundColor:"none"},set_storage=set_cookie,get_storage=get_cookie,domparser=new DOMParser;storageAvailable("localStorage")&&(set_storage=set_localstorage,get_storage=get_localstorage);var vueapp,vchat_state={ready:!1,byond_ip:null,byond_cid:null,byond_ckey:null,lastPingReceived:0,latency_sent:0,lastId:0};function start_vchat(){start_vue(),vchat_state.ready=!0,push_Topic("done_loading"),push_Topic_showingnum(this.showingnum),doWinset("htmloutput",{"is-visible":!0}),doWinset("oldoutput",{"is-visible":!1}),doWinset("chatloadlabel",{"is-visible":!1}),setInterval(check_ping,vchat_opts.msBeforeDropped),send_debug("VChat Loaded!")}function start_vue(){vueapp=new Vue({el:"#app",data:{messages:[],shown_messages:[],unshown_messages:0,archived_messages:[],tabs:[{name:"Main",categories:[],immutable:!0,active:!0}],unread_messages:{},editing:!1,paused:!1,latency:0,reconnecting:!1,ext_styles:"",is_admin:!1,inverted:!1,crushing:3,animated:!1,fontsize:.9,lineheight:130,showingnum:200,type_table:[{matches:".filter_say, .say, .emote, .emotesubtle",becomes:"vc_localchat",pretty:"Local Chat",tooltip:"In-character local messages (say, emote, etc)",required:!1,admin:!1},{matches:".filter_radio, .alert, .syndradio, .centradio, .airadio, .entradio, .comradio, .secradio, .engradio, .medradio, .sciradio, .supradio, .srvradio, .expradio, .radio, .deptradio, .newscaster",becomes:"vc_radio",pretty:"Radio Comms",tooltip:"All departments of radio messages",required:!1,admin:!1},{matches:".filter_notice, .notice:not(.pm), .adminnotice, .info, .sinister, .cult",becomes:"vc_info",pretty:"Notices",tooltip:"Non-urgent messages from the game and items",required:!1,admin:!1},{matches:".filter_warning, .warning:not(.pm), .critical, .userdanger, .italics",becomes:"vc_warnings",pretty:"Warnings",tooltip:"Urgent messages from the game and items",required:!1,admin:!1},{matches:".valert, .vwarning, .vnotice, .vdanger",becomes:"vc_vore_message",pretty:"Vore Messages",tooltip:"Vore Messages",required:!1,admin:!1},{matches:".filter_deadsay, .deadsay",becomes:"vc_deadchat",pretty:"Deadchat",tooltip:"All of deadchat",required:!1,admin:!1},{matches:".filter_pray",becomes:"vc_pray",pretty:"Pray",tooltip:"Prayer messages",required:!1,admin:!1},{matches:".ooc, .filter_ooc",becomes:"vc_globalooc",pretty:"Global OOC",tooltip:"The bluewall of global OOC messages",required:!1,admin:!1},{matches:".nif",becomes:"vc_nif",pretty:"NIF Messages",tooltip:"Messages from the NIF itself and people inside",required:!1,admin:!1},{matches:".psay, .pemote",becomes:"vc_pmessage",pretty:"Pred/Prey Messages",tooltip:"Messages from / to absorbed or dominated prey",required:!1,admin:!1},{matches:".mentor_channel, .mentor",becomes:"vc_mentor",pretty:"Mentor messages",tooltip:"Mentorchat and mentor pms",required:!1,admin:!1},{matches:".filter_pm, .pm",becomes:"vc_adminpm",pretty:"Admin PMs",tooltip:"Messages to/from admins ('adminhelps'), always enabled",required:!0,admin:!1},{matches:".filter_ASAY, .admin_channel",becomes:"vc_adminchat",pretty:"Admin Chat",tooltip:"ASAY messages",required:!1,admin:!0},{matches:".filter_MSAY, .mod_channel",becomes:"vc_modchat",pretty:"Mod Chat",tooltip:"MSAY messages",required:!1,admin:!0},{matches:".filter_ESAY, .event_channel",becomes:"vc_eventchat",pretty:"Event Chat",tooltip:"ESAY messages",required:!1,admin:!0},{matches:".filter_combat, .danger",becomes:"vc_combat",pretty:"Combat Logs",tooltip:"Urist McTraitor has stabbed you with a knife!",required:!1,admin:!1},{matches:".filter_adminlogs, .log_message",becomes:"vc_adminlogs",pretty:"Admin Logs",tooltip:"ADMIN LOG: Urist McAdmin has jumped to coordinates X, Y, Z",required:!1,admin:!0},{matches:".filter_attacklogs",becomes:"vc_attacklogs",pretty:"Attack Logs",tooltip:"Urist McTraitor has shot John Doe",required:!1,admin:!0},{matches:".filter_debuglogs",becomes:"vc_debuglogs",pretty:"Debug Logs",tooltip:"DEBUG: SSPlanets subsystem Recover().",required:!1,admin:!0},{matches:".looc",becomes:"vc_looc",pretty:"Local OOC",tooltip:"Local OOC messages",required:!1},{matches:".rlooc",becomes:"vc_rlooc",pretty:"Remote LOOC",tooltip:"Remote LOOC messages",required:!1,admin:!0},{matches:".boldannounce, .filter_system",becomes:"vc_system",pretty:"System Messages",tooltip:"Messages from your client, always enabled",required:!0},{matches:".unsorted",becomes:"vc_unsorted",pretty:"Unsorted",tooltip:"Messages that don't have any filters.",required:!1,admin:!1}]},mounted:function(){this.load_settings();var e=new XMLHttpRequest;e.open("GET","ss13styles.css"),e.onreadystatechange=function(){this.ext_styles=e.responseText}.bind(this),e.send()},updated:function(){this.editing||this.paused||window.scrollTo(0,document.getElementById("messagebox").scrollHeight)},watch:{reconnecting:function(e,t){1==e&&0==t?this.internal_message("Your client has lost connection to the server, or there is severe lag. Your client will reconnect if possible."):0==e&&1==t&&this.internal_message("Your client has reconnected to the server.")},inverted:function(e){set_storage("darkmode",e),e?(document.body.classList.add("inverted"),switch_ui_mode(DARKMODE_COLORS)):(document.body.classList.remove("inverted"),switch_ui_mode(LIGHTMODE_COLORS))},crushing:function(e){set_storage("crushing",e)},animated:function(e){set_storage("animated",e)},fontsize:function(e,t){isNaN(e)?this.fontsize=t:(e<.2?this.fontsize=.2:e>5&&(this.fontsize=5),set_storage("fontsize",e))},lineheight:function(e,t){isFinite(e)?(e<100?this.lineheight=100:e>200&&(this.lineheight=200),set_storage("lineheight",e)):this.lineheight=t},showingnum:function(e,t){isFinite(e)?((e=Math.floor(e))<50?this.showingnum=50:e>2e3&&(this.showingnum=2e3),set_storage("showingnum",this.showingnum),push_Topic_showingnum(this.showingnum),this.attempt_archive()):this.showingnum=t},current_categories:function(e,t){e.length&&this.apply_filter(e)}},computed:{active_tab:function(){return this.tabs.find((function(e){return e.active}))},ping_classes:function(){return this.latency?"?"==this.latency?"grey":this.latency<0?"red":this.latency<=200?"green":this.latency<=400?"yellow":"grey":this.reconnecting?"red":"green"},current_categories:function(){return this.active_tab==this.tabs[0]?[]:this.active_tab.categories.concat(vchat_opts.alwaysShow)}},methods:{load_settings:function(){this.inverted=get_storage("darkmode",!1),this.crushing=get_storage("crushing",3),this.animated=get_storage("animated",!1),this.fontsize=get_storage("fontsize",.9),this.lineheight=get_storage("lineheight",130),this.showingnum=get_storage("showingnum",200),isNaN(this.crushing)&&(this.crushing=3),isNaN(this.fontsize)&&(this.fontsize=.9),this.load_tabs()},load_tabs:function(){var e=get_storage("tabs");if(e){var t=JSON.parse(e);t.version&&t.tabs?!t.version!=vchat_opts.vchatTabsVer?this.tabs.push.apply(this.tabs,t.tabs):this.internal_message("Your saved tabs are for an older version of VChat and must be recreated, sorry."):this.internal_message("There was a problem loading your tabs. Any new ones you make will be saved, however.")}},save_tabs:function(){var e={version:vchat_opts.vchatTabsVer,tabs:[]};this.tabs.forEach((function(t){if(!t.immutable){var s=t.name,a=[];t.categories.forEach((function(e){a.push(e)}));var o={name:s,categories:a,immutable:!1,active:!1};e.tabs.push(o)}}));var t=JSON.stringify(e);set_storage("tabs",t)},switchtab:function(e){e!=this.active_tab&&(this.active_tab.active=!1,e.active=!0,e.categories.forEach((function(e){this.unread_messages[e]=0}),this),this.apply_filter(this.current_categories))},editmode:function(){this.editing=!this.editing,this.save_tabs()},pause:function(){this.paused=!this.paused},newtab:function(){this.tabs.push({name:"New Tab",categories:[],immutable:!1,active:!1}),this.switchtab(this.tabs[this.tabs.length-1])},renametab:function(){if(!this.active_tab.immutable){var e=this.active_tab,t=window.prompt("Type the desired tab name:",e.name);null!==t&&""!==t&&null!==e&&(e.name=t)}},deltab:function(e){e||(e=this.active_tab),e.immutable||(this.switchtab(this.tabs[0]),this.tabs.splice(this.tabs.indexOf(e),1))},movetab:function(e,t){if(e&&!e.immutable){var s=this.tabs.indexOf(e),a=s+t;this.tabs.splice(a,0,this.tabs.splice(s,1)[0])}},tab_unread_count:function(e){var t=0,s=this.unread_messages;return e.categories.find((function(e){s[e]&&(t+=s[e])})),t},tab_unread_categories:function(e){var t=!1,s=this.unread_messages;return e.categories.find((function(e){if(s[e])return t=!0,!0})),{red:t,grey:!t}},attempt_archive:function(){if(this.messages.length>this.showingnum){var e=this.messages.splice(0,20);Array.prototype.push.apply(this.archived_messages,e)}},apply_filter:function(e){this.shown_messages.splice(0),this.unshown_messages=0,this.messages.forEach((function(t){e.indexOf(t.category)>-1&&this.shown_messages.push(t)}),this),this.archived_messages.forEach((function(t){e.indexOf(t.category)>-1&&this.unshown_messages++}),this)},add_message:function(e){let t={time:e.time,category:"error",content:e.message,repeats:1};if(t.category=this.get_category(t.content),"vc_unsorted"==t.category&&(t.content="<span class='unsorted'>"+t.content+"</span>"),this.crushing){let e=this.messages.slice(-this.crushing);for(let s=e.length-1;s>=0;s--){let a=e[s];a.content==t.content&&(t.repeats+=a.repeats,this.messages.splice(this.messages.indexOf(a),1))}}t.content=t.content.replace(/(\b(https?):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/gim,'<a href="$1">$1</a>'),this.current_categories.length&&this.current_categories.indexOf(t.category)<0?(isNaN(this.unread_messages[t.category])&&(this.unread_messages[t.category]=0),this.unread_messages[t.category]+=1):this.current_categories.length&&this.shown_messages.push(t),t.id=++vchat_state.lastId,this.attempt_archive(),this.messages.push(t)},internal_message:function(e){let t={time:this.messages.length?this.messages.slice(-1).time+1:0,category:"vc_system",content:"<span class='notice'>[VChat Internal] "+e+"</span>"};t.id=++vchat_state.lastId,this.messages.push(t)},on_mouseup:function(e){let t=e.target;"getSelection"in window&&!1===window.getSelection().isCollapsed||t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName)||(focusMapWindow(),e.preventDefault(),e.target.click())},click_message:function(e){let t=e.target;if("A"===t.tagName){e.stopPropagation(),e.preventDefault?e.preventDefault():e.returnValue=!1;var s=t.getAttribute("href");"?"==s[0]||s.length>=8&&"byond://"==s.substring(0,8)?window.location=s:window.location="byond://?action=openLink&link="+encodeURIComponent(s)}},get_category:function(e){if(!vchat_state.ready)return void push_Topic("not_ready");let t=domparser.parseFromString(e,"text/html").querySelector("span"),s="vc_unsorted";return t?(this.type_table.find((function(e){if(t.msMatchesSelector(e.matches))return s=e.becomes,!0})),s):s},save_chatlog:function(){var e="<html><head><style>"+this.ext_styles+"</style></head><body>",t=this.archived_messages.concat(this.messages),s=this.current_categories;t.forEach((function(t){(0==s.length||s.indexOf(t.category)>=0)&&(e+=t.content,t.repeats>1&&(e+="(x"+t.repeats+")"),e+="<br>\n")})),e+="</body></html>";var a=new Date,o=String(a.getHours());o.length<2&&(o="0"+o);var n=String(a.getMinutes());n.length<2&&(n="0"+n);var i=String(a.getDate());i.length<2&&(i="0"+i);var r=String(a.getMonth()+1);r.length<2&&(r="0"+r);var c="log"+(" "+String(a.getFullYear())+"-"+r+"-"+i+" ("+o+" "+n+")")+".html",l=document.createElement("a");if(void 0!==l.download)l.href="data:attachment/text,"+encodeURI(e),l.target="_blank",l.download=c,l.click();else{var d=new Blob([e],{type:"text/html;charset=utf8;"});saved=window.navigator.msSaveOrOpenBlob(d,c)}},do_latency_test:function(){send_latency_check()},blur_this:function(e){e.target.blur()}}})}function check_ping(){Date.now()-vchat_state.lastPingReceived>vchat_opts.msBeforeDropped&&(vueapp.reconnecting=!0)}function send_latency_check(){vchat_state.latency_sent||(vchat_state.latency_sent=Date.now(),vueapp.latency="?",push_Topic("ping"),setTimeout((function(){"?"==vchat_state.latency_ms&&(vchat_state.latency_ms=999)}),1e3),setTimeout((function(){vchat_state.latency_sent=0,vueapp.latency=0}),5e3))}function get_latency_check(){vchat_state.latency_sent&&(vueapp.latency=Date.now()-vchat_state.latency_sent)}function byondDecode(e){e=e.replace(/\+/g,"%20");try{e=decodeURIComponent(e)}catch(t){e=unescape(e)}return JSON.parse(e)}function putmessage(e){e=byondDecode(e),Array.isArray(e)?e.forEach((function(e){vueapp.add_message(e)})):"object"==typeof e&&vueapp.add_message(e)}function system_message(e){vueapp.internal_message(e)}function push_Topic(e){window.location="?_src_=chat&proc="+e}function push_Topic_showingnum(e){window.location="?_src_=chat&showingnum="+e}function focusMapWindow(){window.location="byond://winset?mapwindow.map.focus=true"}function send_debug(e){push_Topic("debug&param[message]="+encodeURIComponent(e))}function get_event(e){if(vchat_state.ready){var t;switch((t=byondDecode(e)).evttype){case"internal_error":system_message("Event parse error: "+e);break;case"byond_player":send_client_data(),vueapp.is_admin="true"===t.admin,vchat_state.byond_ip=t.address,vchat_state.byond_cid=t.cid,vchat_state.byond_ckey=t.ckey,set_storage("ip",vchat_state.byond_ip),set_storage("cid",vchat_state.byond_cid),set_storage("ckey",vchat_state.byond_ckey);break;case"keepalive":vchat_state.lastPingReceived=Date.now(),vueapp.reconnecting=!1;break;case"pong":get_latency_check();break;case"availability":push_Topic("done_loading");break;default:system_message("Didn't know what to do with event: "+e)}}else push_Topic("not_ready")}function send_client_data(){let e={ip:get_storage("ip"),cid:get_storage("cid"),ckey:get_storage("ckey")};push_Topic("ident&param[clientdata]="+JSON.stringify(e))}function set_localstorage(e,t){window.localStorage.setItem(vchat_opts.cookiePrefix+e,t)}function get_localstorage(e,t){let s=window.localStorage.getItem(vchat_opts.cookiePrefix+e);return"null"===s||null===s?s=t:"true"===s?s=!0:"false"===s?s=!1:isNaN(s)||(s=+s),s}function set_cookie(e,t){let s=new Date;s.setFullYear(s.getFullYear()+1);let a=s.toUTCString();document.cookie=vchat_opts.cookiePrefix+e+"="+t+";expires="+a+";path=/"}function get_cookie(e,t){let s=document.cookie.split(";"),a={};s.forEach((function(e){let s=e.replace(vchat_opts.cookiePrefix,"").trim(),o=s.search("="),n=decodeURIComponent(s.substring(0,o)),i=decodeURIComponent(s.substring(o+1));"null"==i||null===i?i=t:"true"===i?i=!0:"false"===i?i=!1:isNaN(i)||(i=+i),a[n]=i})),a[e]}var SKIN_BUTTONS=["rpane.textb","rpane.infob","rpane.wikib","rpane.forumb","rpane.rulesb","rpane.github","rpane.discord","rpane.mapb","rpane.changelog","mainwindow.saybutton","mainwindow.mebutton","mainwindow.hotkey_toggle"],SKIN_ELEMENTS=["mainwindow","mainwindow.mainvsplit","mainwindow.tooltip","rpane","rpane.rpanewindow","rpane.mediapanel"];function switch_ui_mode(e){doWinset(SKIN_BUTTONS.reduce((function(t,s){return t[s+".background-color"]=e.buttonBgColor,t}),{})),doWinset(SKIN_BUTTONS.reduce((function(t,s){return t[s+".text-color"]=e.buttonTextColor,t}),{})),doWinset(SKIN_ELEMENTS.reduce((function(t,s){return t[s+".background-color"]=e.windowBgColor,t}),{})),doWinset("infowindow",{"background-color":e.tabBackgroundColor,"text-color":e.tabTextColor}),doWinset("infowindow.info",{"background-color":e.tabBackgroundColor,"text-color":e.tabTextColor,"highlight-color":e.highlightColor,"tab-text-color":e.tabTextColor,"tab-background-color":e.tabBackgroundColor})}function doWinset(e,t){void 0===t&&(t=e,e=null);var s="byond://winset?";e&&(s+="id="+e+"&"),s+=Object.keys(t).map((function(e){return e+"="+encodeURIComponent(t[e])})).join("&"),window.location=s}