Skip to content

Commit 1f13e7d

Browse files
authored
badword.js
1 parent 07ffa39 commit 1f13e7d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

badword.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Periksa lingkungan eksekusi
2+
const isNode = typeof exports === 'object' && typeof module !== 'undefined';
3+
14
/**
25
* Fungsi untuk memeriksa apakah kata cocok dengan pola regex
36
* @param {string} word - string kata yang akan diperiksa
@@ -88,14 +91,14 @@ constructor(text = "", customFilter="", customSubFilter=""){
8891
this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|fk/gi;
8992

9093
this._subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi;
91-
92-
if (customFilter){
94+
if (customFilter.length>1){
9395
this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi");
9496
};
95-
if (customSubFilter){
97+
if (customSubFilter.length>1){
9698
this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi");
9799
};
98100
this.__subtxic = [];
101+
this._st = false;
99102
}
100103

101104

@@ -385,7 +388,7 @@ set ['thisToxic'](key){
385388
this.__subtxic.forEach(([oldWord, newWord]) => {
386389

387390
word.forEach((w, i) => {
388-
if (!(validateInput("email", w) || validateInput("url", w))){
391+
if (!(validateInput("email", w) || validateInput("url", w)) && this._st){
389392

390393
word[i] = w.replace(oldWord, newWord);
391394

@@ -412,10 +415,31 @@ class filters_badword extends FilterBadWord{
412415
['config'](cl=true, smart=true, customFilter="", customSubFilter=""){
413416
this._cl = cl;
414417
this._st = smart;
415-
if (customFilter){
418+
var isfiles = false;
419+
if (isNode){
420+
const {readFileSync, existsSync} = require("node:fs");
421+
if (existsSync(customSubFilter)) {
422+
var readata = readFileSync(customSubFilter).split("\n");
423+
function extractNames(text) {
424+
const namePattern = /\b[A-Z][a-zàâäéèêëïîôöùûüç'-]+\b/g;
425+
return text.match(namePattern);
426+
};
427+
readata = readata.map(value => (extractNames(value) || validateInput("email", value) ||
428+
validateInput("phone", value) || validateInput("url", value)) ? "" : value).
429+
filter(item => item && item.trim());
430+
if (readata.length>1){
431+
this._subfilter = new RegExp(this._subfilter.source + "|" + escapeRegExp(readata.join("|")), "gi");
432+
};
433+
}else{
434+
if (customSubFilter.includes("|")) this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi");
435+
};
436+
isfiles = true;
437+
};
438+
439+
if (customFilter.length>1){
416440
this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi");
417441
};
418-
if (customSubFilter){
442+
if (customSubFilter.length>1 && !isfiles){
419443
this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi");
420444
};
421445
}
@@ -477,8 +501,7 @@ const exportsObject = {
477501
filters_badword
478502
};
479503

480-
// Periksa lingkungan eksekusi
481-
const isNode = typeof exports === 'object' && typeof module !== 'undefined';
504+
482505

483506
// Ekspor ke lingkungan yang sesuai
484507
isNode ? module.exports = exportsObject : Object.assign(window, exportsObject);

0 commit comments

Comments
 (0)