-
Notifications
You must be signed in to change notification settings - Fork 42
/
jquery.profanityfilter.min.js
1 lines (1 loc) · 1.92 KB
/
jquery.profanityfilter.min.js
1
!function(e){"use strict";String.prototype.repeat=function(e){return new Array(e+1).join(this)},Array.prototype.unique=function(){var e,t,r;for(e=this.concat(),t=0;t<e.length;++t)for(r=t+1;r<e.length;++r)e[t]===e[r]&&e.splice(r,1);return e};var t={replaceWith:"*",customSwears:null,externalSwears:null,filter:!0,profaneText:function(){}};e.fn.profanityFilter=function(r){function n(e){function t(e){var t,r=[];for(t=0;t<e.childNodes.length;t+=1)r[t]=e.childNodes[t];return r}for(var r,n=[],a=t(e);a.length;)r=a.shift(),1===r.nodeType&&a.unshift.apply(a,t(r)),3===r.nodeType&&n.push(r);return n}function a(e){var t=new XMLHttpRequest;t.open("GET",e,!1),t.setRequestHeader("X-Requested-With","XMLHttpRequest"),t.send(null);try{return JSON.parse(t.responseText)}catch(r){return""}}function l(e){var t=Math.floor(Math.random()*e);return null==i?i=t:t==i&&0!=e&&(t+=1),t>e&&(t=0),i=t,t}var o,u=e.extend({},t,r);o=function(){var e,t=new Date;try{return localStorage.setItem("uid",t),e=localStorage.getItem("uid")===t,localStorage.removeItem("uid"),e&&localStorage}catch(r){}}();var i=null;return this.each(function(){var t,r,i,s,c,p=n(this),f=e(this).find(":input"),h=!1,g=[];if(null!==u.externalSwears?(o?(null===localStorage.getItem("localSwears")&&localStorage.setItem("localSwears",JSON.stringify(a(u.externalSwears))),t=JSON.parse(localStorage.getItem("localSwears"))):t=a(u.externalSwears),null!==u.customSwears&&(t=t.concat(u.customSwears).unique())):null!==u.customSwears&&(t=u.customSwears),null!==t){for(r=0;r<t.length;r+=1){i=new RegExp("\\b"+t[r]+"\\b","gi");var S=l(u.replaceWith.length-1);for(s=u.replaceWith[S],"string"==typeof u.replaceWith&&(s=u.replaceWith[S].repeat(t[r].length)),c=0;c<p.length;c+=1)i.test(p[c].nodeValue)&&(h=!0,g.push(t[r]),u.filter&&(p[c].nodeValue=p[c].nodeValue.replace(i,s)));for(var c=0;c<f.length;c++)i.test(f[c].value)&&(h=!0,g.push(t[r]),u.filter&&e(f[c]).val(f[c].value.replace(i,s)))}h&&u.profaneText(g.unique())}})}}(jQuery);