-
Notifications
You must be signed in to change notification settings - Fork 37
/
chat_filter.min.js
1 lines (1 loc) · 13.3 KB
/
chat_filter.min.js
1
!function(e){"use strict";var t=document.createElement("script");t.appendChild(document.createTextNode("("+e.toString()+"());")),document.body.appendChild(t)}(function(){"use strict";function e(e,t){for(var n=0;n<e.length;n++)t(e[n],n,e)}function t(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return!0;return!1}function n(e,t){for(var n=0;n<e.length;n++)if(!t(e[n]))return!1;return!0}function a(e,t){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t(n,e[n])}function o(e,t){return e=e.toLowerCase(),e.indexOf(t.toLowerCase())>=0}function r(e){P.push(e)}function i(){e(P,function(e){e()})}function s(t){e(z,function(e){if(!(e in t))throw new Error("Missing param "+e)}),a(t,function(e){if(z.indexOf(e)<0&&U.indexOf(e)<0)throw new Error("Unexpected param "+e)});var n=this;a(t,function(e,t){n[e]=t}),this._value=null,this._observers=[]}function l(e){var t=new s(e);R.push(t),q[t.name]=t,t.message_filter&&J.push(t),t.message_css&&X.push(t),t.message_rewriter&&G.push(t)}function c(e){return q[e].getValue()}function u(e){var t=localStorage.getItem(e);return t?JSON.parse(t):null}function m(e,t){localStorage.setItem(e,JSON.stringify(t))}function f(){var t={},n=u(K);n&&a(q,function(a){e(["filters","rewriters","stylers"],function(e){n[e].indexOf(a)>=0&&(t[a]=!0)})});var o=u(Q);return o&&(t.TppBanCustomWords=!0,t.TppBannedWords=o),t}function p(){var e;e=window.localStorage?u(Y)||f():{},a(q,function(t,n){t in e?n.setValue(e[t]):n.setValue(null)})}function d(){if(window.localStorage){var e={};a(q,function(t,n){null!==n._value&&(e[t]=n._value)}),m(Y,e),localStorage.removeItem(K),localStorage.removeItem(Q)}}function g(e){$("head").append("<style>"+e.join("")+"</style>")}function h(e,t){if(0===e.length)return t.length;if(0===t.length)return e.length;var n,a,o=[];for(n=0;n<=t.length;n++)o[n]=[n];for(a=0;a<=e.length;a++)o[0][a]=a;for(n=1;n<=t.length;n++)for(a=1;a<=e.length;a++)t.charAt(n-1)===e.charAt(a-1)?o[n][a]=o[n-1][a-1]:o[n][a]=1+Math.min(o[n-1][a-1],o[n][a-1],o[n-1][a]);return o[t.length][e.length]}function v(e){return t(re,function(t){return h(t.toLowerCase(),e.toLowerCase())<=ie})}function y(e){return/^([0-9]+),([0-9]+)$/.test(e.replace(/\s/g,""))?!0:/^\s*item[a-z0-9]*\s*$/i.test(e)?!0:n(e.split(/\s+/),function(e){if(e.length<=0)return!0;var t=e.match(/(?:([a-z]+)[^a-z]{0,2})+/gi);return t&&n(t,function(e){var t=e.match(/[a-z]+/gi);return n(t,v)})})}function w(t){var n=0;return e(se,function(e){o(t,e)&&n++}),n>=2}function b(e){for(var t=0,n=0;n<e.length;n++){var a=e.charCodeAt(n);a>=9600&&9632>=a&&t++}return t>3}function _(e){return/[\u0400-\u04FF]/.test(e)}function C(e){for(var t=0,n=0;n<e.length;n++){var a=e.charCodeAt(n);le.indexOf(a)>=0&&t++}return t>1}function x(e){return e.split(/\s/g).length<=1}function T(e){return e.length>=200}function V(e){return/^\s*\!/.test(e)}function k(e,t){return"tppbankbot"===t.toLowerCase()?ce?e.toLowerCase().indexOf("@"+ce.toLowerCase())<0:!0:!1}function O(e){return e.replace(/(.{4}.*?)(\s*?\1)+/g,"$1")}function S(e){return e.replace(/[\u0300-\u036F]/g,"")}function N(t){var n=t;return e(ue,function(e){n=n.replace(e,"")}),/^\s*$/.test(n)}function B(e){var n=c("TppBanCustomWords"),a=c("TppBannedWords");return n&&t(a,function(t){return o(e,t)})}function F(t,n){var a={};return t=t||"",n=n||"",e(J,function(e){a[e.name]=e.message_filter(t,n)}),a}function M(e){var t=Date.now();ge=t,ve=he,he={text:e,time:t}}function A(){he=ve,ve=null}function D(e){var t;if(/now in slow mode/.test(e)&&(t=/(\d+) second/.exec(e))){if(pe===Number(t[1]))return!1;pe=Number(t[1])}if(/identical to the previous/.test(e)&&(t=/than (\d+) second/.exec(e),t&&(de=Number(t[1])),A()),/you are sending messages too quickly/.test(e)){if(t=/in (\d+) second/.exec(e)){var n=Number(t[1]),a=Date.now()-he.time+1e3*n;pe=Math.ceil(a/1e3)}A()}if(/You are banned/.test(e)){if(t=/for (\d+) more second/.exec(e)){var o=Number(t[1]);ye=Date.now()+1e3*o}A()}return W(),!0}function I(e){var t=Date.now();if(ye){var n=ye-t;if(n>0)return{blocked:!0,error:"you are banned",wait:n}}if(he){var a=ge+fe-t;if(a>0)return{blocked:!0,error:"",wait:null};if(e===he.text){var o=he.time+1e3*de-t;if(o>0)return{blocked:!0,error:"repeated message",wait:o}}var r=he.time+1e3*pe-t;if(r>0)return{blocked:!0,error:"slowmode",wait:r}}return{blocked:!1}}function W(){var e=$(ae).val(),t=I(e),n=$(oe);if(c("TppSlowmodeHelper")&&t.blocked){var a;a=t.error?"Wait "+Math.ceil(t.wait/1e3)+" seconds ("+t.error+")":"...",n.addClass(be),n.text(a),$e=!1}else $e||(n.removeClass(be),n.text(_e),$e=!0)}function E(){i(),p(),console.log(H)}function L(){return $(me).length>0}if(window.$){var j="3.7",H="TPP Chat Filter version "+j+" loaded. Please report bugs and suggestions to https://github.com/jpgohlke/twitch-chat-filter",P=[],z=["name","comment","category","defaultValue"],U=["longComment","message_filter","message_css","message_rewriter"];s.prototype.getValue=function(){return null!==this._value?this._value:this.defaultValue},s.prototype.setValue=function(t){var n=this.getValue();this._value=t;var a=this.getValue();e(this._observers,function(e){e(a,n)})},s.prototype.reset=function(){this.setValue(null)},s.prototype.observe=function(e){this._observers.push(e)},s.prototype.forceObserverUpdate=function(){var t=this.getValue();e(this._observers,function(e){e(t,t)})};var R=[],q={},J=[],G=[],X=[],Y="tpp-chat-filter-settings",K="tpp-custom-filter-active",Q="tpp-custom-filter-phrases";r(function(){e(R,function(e){e.observe(function(){d()})})});var Z=".chat-room",ee=".message",te=".from",ne=".chat-line",ae=".chat-interface textarea",oe="button.send-chat-button",re=["left","right","up","down","start","select","a","b","l","r","democracy","anarchy","wait","move","switch","run","item"],ie=2;l({name:"TppFilterCommand",comment:"Emulator commands",longComment:re.join(", "),category:"filters_category",defaultValue:!0,message_filter:y});var se=["misty","whitney","milk","guys","we have to","we need to","beat"];l({name:"TppFilterMisty",comment:"Misty meme",longComment:"Guys we need to milk Witney",category:"filters_category",defaultValue:!0,message_filter:w}),l({name:"TppFilterAscii",comment:"Blocky drawings",longComment:"Stuff like this: ░░░░▒▒▒▒▌ ▀▒▀▐▄█",category:"filters_category",defaultValue:!0,message_filter:b}),l({name:"TppFilterCyrillic",comment:"Cyrillic",longComment:"Cyrillic characters in copypastas confuse our other filters",category:"filters_category",defaultValue:!0,message_filter:_});var le=[3720,9685,664,8362,3232,176,8248,8226,7886,3237];l({name:"TppFilterDonger",comment:"Dongers",longComment:"ヽ༼ຈل͜ຈ༽ノ",category:"filters_category",defaultValue:!1,message_filter:C}),l({name:"TppFilterSmall",comment:"One-word messages",category:"filters_category",defaultValue:!1,message_filter:x}),l({name:"TppFilterLong",comment:"Overly long messages",longComment:"Hide messages over 200 characters (around 4 lines)",category:"filters_category",defaultValue:!1,message_filter:T}),l({name:"TppFilterBets",comment:"Stadium bets",longComment:'Any message starting with a "!". ex.: "!bet 100 blue"',category:"filters_category",defaultValue:!0,message_filter:V});var ce=null;r(function(){Twitch&&(ce=Twitch.user.displayName())}),l({name:"TppFilterBankBot",comment:"Stadium bank bot",longComment:"Messages from the bank bot about other players' balances",category:"filters_category",defaultValue:!0,message_filter:k}),l({name:"TppRewriteDuplicates",comment:"Copy pasted repetitions",category:"rewriters_category",defaultValue:!0,message_rewriter:O}),l({name:"TppMopUpDrinks",comment:"Mop up spilled drinks",category:"rewriters_category",defaultValue:!0,message_rewriter:S}),l({name:"TppConvertAllcaps",comment:"Lowercase everything",longComment:null,category:"visual_category",defaultValue:!0,message_css:ee+"{text-transform:lowercase !important;}"});var ue=[];r(function(){Twitch&&Twitch.api.get("chat/emoticons").then(function(t){e(t.emoticons,function(e){var t=e.regex;t.match(/^\w+$/)&&(t="\\b"+t+"\\b"),ue.push(new RegExp(t,"g"))})})}),l({name:"TppHideEmoticons",comment:"Hide emoticons",category:"visual_category",defaultValue:!1,message_css:ee+" .emoticon{display:none !important;}",message_filter:N}),l({name:"TppNoColor",comment:"Uncolor messages",longComment:"Remove color from messages created with the /me command",category:"visual_category",defaultValue:!1,message_css:ee+" {color:inherit !important;}"}),l({name:"TppBanCustomWords",comment:"Activate custom banlist",longComment:"",category:"customs_category",defaultValue:!1,message_css:"#menu-TppBannedWords { display:inherit; }"}),r(function(){g(["#menu-TppBannedWords { display:none; }"])}),l({name:"TppBannedWords",comment:"Banned Phrases",longComment:"If the custom banlist is activated, these messages will be hidden",category:"customs_category",defaultValue:[],message_filter:B});var me=".chat-settings";r(function(){function t(e,t){e.append($("<label>").attr("for",t.name).attr("title",t.longComment||"").append($('<input type="checkbox">').attr("id",t.name)).append(document.createTextNode(" "+t.comment)));var n=$("#"+t.name);n.on("change",function(){t.setValue($(this).prop("checked"))}),t.observe(function(e){n.prop("checked",e)})}function n(t,n){function a(e){var t=n.getValue().slice();t.indexOf(e)<0&&(t.push(e),n.setValue(t))}function o(e){var t=n.getValue().slice();t.splice(e,1),n.setValue(t)}function r(){$("#show-"+n.name).show(),$("#hide-"+n.name).hide(),$("#clear-"+n.name).hide(),$("#list-"+n.name).hide()}function i(){$("#show-"+n.name).hide(),$("#hide-"+n.name).show(),$("#clear-"+n.name).show(),$("#list-"+n.name).show()}t.append($("<label>").attr("for",n.name).attr("title",n.longComment||"").append(document.createTextNode("Add "+n.comment)).append($('<input type="text">').attr("id",n.name).css("width","100%"))).append($("<button>").attr("id","show-"+n.name).append(document.createTextNode("Show ")).append($("<span>").attr("id","num-banned-"+n.name)).append(document.createTextNode(" "+n.comment))).append($("<button>").attr("id","hide-"+n.name).append(document.createTextNode("Hide "+n.comment))).append($('<div class="custom_list_menu">').attr("id","list-"+n.name)).append($("<button>").attr("id","clear-"+n.name).append(document.createTextNode("Clear "+n.comment))),r(),n.observe(function(t){$("#num-banned-"+n.name).text(t.length);var a=$("#list-"+n.name);a.empty(),e(t,function(e,t){a.append($("<li>").text(e).append($('<a href="#">').text("[X]").click(function(){o(t)})))})}),$("#"+n.name).keyup(function(e){var t=$(this).val().trim();13===e.keyCode&&""!==t&&(a(t),$(this).val(""))}),$("#show-"+n.name).click(function(e){e.preventDefault(),i()}),$("#hide-"+n.name).click(function(e){e.preventDefault(),r()}),$("#clear-"+n.name).click(function(e){e.preventDefault(),n.setValue([])})}function a(e){$('<div class="list-header"/>').text(e).appendTo(r);var t=$('<div class="chat-menu-content">').appendTo(r);return t}function o(a,o){e(R,function(e){if(e.category===o){var r=$("<p>").attr("id","menu-"+e.name).addClass("dropmenu_action").appendTo(a),i=typeof e.defaultValue;if("boolean"===i)t(r,e);else{if("object"!==i)throw new Error("Unrecognized setting "+i);n(r,e)}}})}g([".chat-room { z-index: inherit !important; }",".chat-settings { z-index: 100 !important; }",".chat-settings { max-height: 500px; }",".chat-settings label { font-weight: inherit; }",".custom_list_menu li {background: #bbb; display: block; list-style: none; margin: 1px 0; padding: 0 2px}",".custom_list_menu li a {float: right;}"]);var r=$(me),i=a("Hide");o(i,"filters_category");var s=a("Automatically rewrite");o(s,"rewriters_category");var l=a("Visual tweaks");o(l,"visual_category");var c=a("Custom Banlist");o(c,"customs_category");var u=a("Misc");u.append($("<button>Reset TPP filter settings</a>").click(function(){confirm("This will reset all Twitch Chat Filter settings to their default values and will delete all custom banned phrases. Are you sure you want to continue?")&&e(R,function(e){e.reset()})}))}),r(function(){var t=[];e(X,function(e){t.push(Z+"."+e.name+" "+e.message_css)}),g(t),e(X,function(e){e.observe(function(t){$(Z).toggleClass(e.name,t)})})}),r(function(){var t=[];e(J,function(e){var n=e.name,a=e.name+"Hidden";t.push(Z+"."+a+" "+ne+"."+n+","+Z+"."+a+" ."+n+" "+ne+"{display:none}"),e.observe(function(){$(Z).toggleClass(a,e.getValue())})}),g(t)}),r(function(){var t=require("web-client/components/chat/chat-line/component")["default"].prototype,n=t.didInsertElement;t.didInsertElement=function(){n.apply(this,arguments);var e=this.$(),t=F(this.get("msgObject.message"),this.get("msgObject.from"));for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.toggleClass(a,t[a])},$(ne).each(function(){var t=$(this),n=t.find(ee).text().trim(),a=t.find(te).text().trim();e(J,function(e){t.toggleClass(e.name,e.message_filter(n,a))})})});var fe=1e3,pe=2,de=30,ge=null,he=null,ve=null,ye=null,we=500,be="tpp-slowmode-warning",_e=null,$e=!0;if(r(function(){_e=$(oe).text(),g(["."+be+"{ opacity:0.7 !important}"]),$(ae).keyup(function(e){13!==e.keyCode&&W()}),setInterval(function(){W()},we)}),l({name:"TppSlowmodeHelper",comment:"Slowmode helper",longComment:"Shows a countdown of how long you need to wait until being able to chat again",category:"visual_category",defaultValue:!0}),r(function(){var e=require("web-client/models/room")["default"].prototype,t=e.addMessage;e.addMessage=function(e){return"admin"!==e.style||D(e.message)?t.apply(this,arguments):!1};var n=e.send;e.send=function(e){return M(e),n.apply(this,arguments)}}),L())E();else var Ce=setInterval(function(){L()&&(clearInterval(Ce),E())},50)}});