├── .gitattributes ├── .gitignore ├── README.md ├── antimat.js └── test ├── css └── main.css ├── images ├── fail.png └── ok.png └── index.html /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | 217 | 218 | .idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Антимат 2 | 3 | Простая система защиты от матерных слов. Отвечает на вопрос, содержит ли сообщение мат 4 | 5 | ## Usage 6 | 7 | Загрузить библиотеку. Никаких зависимостей не требуется. 8 | 9 | ```html 10 | 11 | ``` 12 | 13 | Теперь можно использовать специальный метод: 14 | 15 | ```html 16 | 22 | ``` 23 | 24 | ## Ссылки 25 | [Пишем простой антимат для чата](http://www.itlessons.info/javascript/simple-obscene-checker/) 26 | 27 | ## Автор 28 | 29 | [itlessons](http://www.itlessons.info) ([@itlessonsinfo](http://twitter.com/itlessonsinfo)) 30 | 31 | ## Лецензия 32 | [MIT License](http://www.opensource.org/licenses/mit-license.php) -------------------------------------------------------------------------------- /antimat.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Obscene words detector for russian language 3 | * 4 | * @name antimat 5 | * @version 0.0.1 6 | * @license MIT License - http://www.opensource.org/licenses/mit-license.php 7 | * @see https://github.com/itlessons/js-antimat 8 | * 9 | * Copyright (c) 2014, www.itlessons.info 10 | */ 11 | (function () { 12 | 13 | var t = {}; 14 | 15 | window.containsMat = function (text) { 16 | return t.containsMat(text); 17 | }; 18 | 19 | window.antimat = t; 20 | 21 | t.badPatterns = [ 22 | "^(о|а)н(о|а)нист.*", 23 | "^лошар.*", 24 | "^к(а|о)злина$", 25 | "^к(о|а)зел$", 26 | "^сволоч(ь|ъ|и|уга|ам|ами).*", 27 | "^лох[уеыаоэяию].*", 28 | ".*урод(ы|у|ам|ина|ины).*", 29 | ".*бля(т|д).*", ".*гандо.*", 30 | "^м(а|о)нд(а|о).*", 31 | ".*сперма.*", 32 | ".*[уеыаоэяию]еб$", 33 | "^сучк(а|у|и|е|ой|ай).*", 34 | "^придур(ок|ки).*", 35 | "^д(е|и)би(л|лы).*", 36 | "^сос(ать|и|ешь|у)$", 37 | "^залуп.*", 38 | "^муд(е|ил|о|а|я|еб).*", 39 | ".*шалав(а|ы|ам|е|ами).*", 40 | ".*пр(а|о)ст(и|е)т(у|е)тк(а|и|ам|е|ами).*", 41 | ".*шлюх(а|и|ам|е|ами).*", 42 | ".*ху(й|и|я|е|л(и|е)).*", 43 | ".*п(и|е|ы)зд.*", 44 | "^бл(я|т|д).*", 45 | "(с|сц)ук(а|о|и|у).*", 46 | "^еб.*", 47 | ".*(д(о|а)лб(о|а)|разъ|разь|за|вы|по)ебы*.*", 48 | ".*пид(а|о|е)р.*", 49 | ".*хер.*" 50 | ]; 51 | 52 | t.goodPatterns = [ 53 | ".*психу.*", 54 | ".*к(о|а)манд.*", 55 | ".*истр(е|и)блять.*", 56 | ".*л(о|а)х(о|а)трон.*", 57 | ".*(о|а)ск(о|а)рблять.*", 58 | "хул(е|и)ган", 59 | ".*м(а|о)нд(а|о)рин.*", 60 | ".*р(а|о)ссл(а|о)блять.*", 61 | ".*п(о|а)тр(е|и)блять.*", 62 | ".*@.*\\.(ру|сом|нет)$" 63 | ]; 64 | 65 | t.goodWords = [ 66 | "дезмонда", 67 | "застрахуйте", 68 | "одномандатный", 69 | "подстрахуй", 70 | "психуй" 71 | ]; 72 | 73 | t.letters = { 74 | "a": "а", 75 | "b": "в", 76 | "c": "с", 77 | "e": "е", 78 | "f": "ф", 79 | "g": "д", 80 | "h": "н", 81 | "i": "и", 82 | "k": "к", 83 | "l": "л", 84 | "m": "м", 85 | "n": "н", 86 | "o": "о", 87 | "p": "р", 88 | "r": "р", 89 | "s": "с", 90 | "t": "т", 91 | "u": "у", 92 | "v": "в", 93 | "x": "х", 94 | "y": "у", 95 | "w": "ш", 96 | "z": "з", 97 | "ё": "е", 98 | "6": "б", 99 | "9": "д" 100 | }; 101 | 102 | t.containsMat = function (text) { 103 | 104 | text = t.cleanBadSymbols(text.toLowerCase()); 105 | 106 | var words = text.split(" "); 107 | 108 | for (var i = 0; i < words.length; i++) { 109 | 110 | var word = t.convertEngToRus(words[i]); 111 | 112 | if (t.isInGoodWords(word) && t.isInGoodPatterns(word)) 113 | continue; 114 | 115 | if (t.isInBadPatterns(word)) 116 | return true; 117 | } 118 | 119 | if (t.containsMatInSpaceWords(words)) 120 | return true; 121 | 122 | return false; 123 | }; 124 | 125 | t.convertEngToRus = function (word) { 126 | for (var j = 0; j < word.length; j++) { 127 | for (var key in t.letters) { 128 | if (word.charAt(j) == key) 129 | word = word.substring(0, j) + t.letters[key] + word.substring(j + 1, word.length) 130 | } 131 | } 132 | 133 | return word; 134 | }; 135 | 136 | t.cleanBadSymbols = function (text) { 137 | return text.replace(/[^a-zA-Zа-яА-Яё0-9\s]/g, ""); 138 | }; 139 | 140 | t.isInGoodWords = function (word) { 141 | 142 | for (var i = 0; i < t.goodWords.length; i++) { 143 | if (word == t.goodWords[i]) 144 | return true; 145 | } 146 | 147 | return false; 148 | }; 149 | 150 | t.isInGoodPatterns = function (word) { 151 | 152 | for (var i = 0; i < t.goodPatterns.length; i++) { 153 | var pattern = new RegExp(t.goodPatterns[i]); 154 | if (pattern.test(word)) 155 | return true; 156 | } 157 | 158 | return false; 159 | }; 160 | 161 | t.isInBadPatterns = function (word) { 162 | 163 | for (var i = 0; i < t.badPatterns.length; i++) { 164 | var pattern = new RegExp(t.badPatterns[i]); 165 | if (pattern.test(word)) 166 | return true; 167 | } 168 | 169 | return false; 170 | }; 171 | 172 | t.containsMatInSpaceWords = function (words) { 173 | var spaceWords = t.findSpaceWords(words); 174 | 175 | for (var i = 0; i < spaceWords.length; i++) { 176 | 177 | var word = t.convertEngToRus(spaceWords[i]); 178 | 179 | if (t.isInBadPatterns(word)) 180 | return true; 181 | } 182 | 183 | return false; 184 | }; 185 | 186 | t.findSpaceWords = function (words) { 187 | 188 | var out = []; 189 | var spaceWord = ""; 190 | 191 | for(var i=0; i < words.length; i++ ){ 192 | var word = words[i]; 193 | 194 | if(word.length <= 3){ 195 | spaceWord += word; 196 | continue; 197 | } 198 | 199 | if(spaceWord.length >= 3){ 200 | out.push(spaceWord); 201 | spaceWord = ""; 202 | } 203 | } 204 | 205 | return out; 206 | }; 207 | 208 | t.addBadPattern = function (pattern) { 209 | t.badPatterns.push(pattern); 210 | }; 211 | 212 | t.addGoodPattern = function (pattern) { 213 | t.goodPatterns.push(pattern); 214 | }; 215 | 216 | t.addGoodWord = function (pattern) { 217 | t.goodWords.push(pattern); 218 | }; 219 | 220 | })(); -------------------------------------------------------------------------------- /test/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #f2f2f2; 3 | } 4 | 5 | a { 6 | color: #4F6B72; 7 | text-decoration: none; 8 | } 9 | 10 | a:hover { 11 | text-decoration: underline; 12 | } 13 | 14 | .demo { 15 | width: 600px; 16 | margin: 20px auto; 17 | padding: 10px; 18 | color: #4F6B72; 19 | font-family: "PT Sans", Verdana, Arial, sans-serif; 20 | font-size: 13px; 21 | } 22 | 23 | .demo h1 { 24 | font-size: 18px; 25 | } 26 | 27 | .demo .permalink { 28 | display: block; 29 | color: #4F6B72; 30 | margin: 10px 0; 31 | } 32 | 33 | .demo .obsceneChecker{ 34 | background: #fff; 35 | width: 400px; 36 | padding: 0 10px 10px; 37 | -moz-box-shadow: 0 0 10px rgba(0,0,0,0.5); 38 | -webkit-box-shadow: 0 0 10px rgba(0,0,0,0.5); 39 | box-shadow: 0 0 10px rgba(0,0,0,0.5); 40 | } 41 | 42 | .demo .obsceneChecker .oc-title{ 43 | margin: 0 -10px 10px; 44 | padding: 10px; 45 | color: #fff; 46 | background: #00B8D9; 47 | font-size: 16px; 48 | } 49 | 50 | .demo .obsceneChecker .result{ 51 | padding: 0 5px 5px 25px; 52 | margin: 5px 0; 53 | } 54 | 55 | .demo .obsceneChecker .result.ok{ 56 | background: url("../images/ok.png") no-repeat; 57 | } 58 | 59 | .demo .obsceneChecker .result.fail{ 60 | background: url("../images/fail.png") no-repeat; 61 | } 62 | 63 | .demo .obsceneChecker input{ 64 | 65 | display: block; 66 | width: 100%; 67 | } 68 | -------------------------------------------------------------------------------- /test/images/fail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlessons/js-antimat/99eea9cf8f8f83b4370d20931925bc32999dc5a1/test/images/fail.png -------------------------------------------------------------------------------- /test/images/ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlessons/js-antimat/99eea9cf8f8f83b4370d20931925bc32999dc5a1/test/images/ok.png -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Демо Простой антимат на Javascript! 8 | 9 | 10 |
11 | 12 |

Демо Простой антимат на Javascript!

13 | 14 |
15 |
Проверка на мат
16 | 17 |
18 |
вот так дела
19 |
су ка вот так дела
20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 53 |
54 | 55 | --------------------------------------------------------------------------------