|
1 | | -CensorCore |
| 1 | +CensorCore |
2 | 2 | ========== |
3 | | -<p><strong><span style="color:red">⚠️ WARNING: The <code>wordlist.json</code> file contains explicit language, slurs, and other harmful content. View it at your own risk.</span></strong></p> |
4 | | -<hr> |
5 | | -CensorCore is a lightweight JavaScript library for detecting explicit or inappropriate text using a centralized JSON wordlist. It is designed for straightforward integration: include a single script tag and call one function within your message handling logic. CensorCore is suitable for chat applications, comment systems, forms, or any environment where user generated text requires screening. |
6 | 3 |
|
7 | | -Features |
8 | | --------- |
9 | | - |
10 | | -- Zero configuration setup |
11 | | - |
12 | | -- Shared JSON wordlist loaded from CDN |
| 4 | +⚠️ WARNING: The `wordlist.json` file contains explicit language, slurs, and other harmful content. View it at your own risk. |
13 | 5 |
|
14 | | -- Efficient whole word matching |
| 6 | +CensorCore is a lightweight JavaScript library for detecting explicit, harmful, or inappropriate text using a centralized JSON wordlist. It is designed for straightforward integration: include a single script tag and call one function within your message‑handling logic. |
15 | 7 |
|
16 | | -- Minimal and predictable API |
| 8 | +Version 2.0 introduces a more advanced moderation engine with phrase detection, severity levels, async loading events, and a detailed `analyze()` API, while remaining fully backward‑compatible with the original `isBlocked()` function. CensorCore is suitable for chat applications, comment systems, forms, or any environment where user‑generated text requires screening. |
17 | 9 |
|
18 | | -- No DOM modification or event interception |
| 10 | +Features |
19 | 11 |
|
20 | | -- Full control retained by the integrating developer |
| 12 | +- Zero‑configuration setup - Shared JSON wordlist loaded from CDN - Phrase detection (supports multi‑word entries) - Automatic severity mapping based on category - Minimal and predictable API (isBlocked + analyze) - Async lifecycle events (onReady, onError) - Optional custom rule extension - No DOM modification or event interception - Full control retained by the integrating developer |
21 | 13 |
|
22 | 14 | Installation |
23 | | ------------- |
24 | | - |
25 | | -To install CensorCore, include the script tag in the <head> tag of your HTML file to ensure it loads before your application code runs: |
26 | | - |
27 | | -`<script src="https://cdn.jsdelivr.net/gh/DerrickRichard/CensorCore-Library@latest/CensorCore.js"></script>` |
28 | | - |
29 | | -The library will load after your code runs if you put it near the closing `<html>` tag, causing it to fail. |
30 | | - |
31 | | -After the script loads, a global object named censor will be available for use in your JavaScript. |
32 | | - |
33 | | -Make sure your internet connection allows loading scripts from the CDN[ ](https://cdn.jsdelivr.net)[cdn.jsdelivr.net](http://cdn.jsdelivr.net). |
34 | | - |
35 | | -Inside your logic to send messages, add this inside the function: |
36 | 15 |
|
37 | | -```JavaScript |
38 | | -//Block explicit messages using the CensorCore library |
| 16 | +To install CensorCore, include the script tag in the `<head>` of your HTML file to ensure it loads before your application code runs: |
39 | 17 |
|
40 | | - if (censor.isBlocked(text)) { |
| 18 | +Code |
41 | 19 |
|
42 | | - alert("Message blocked: Inappropriate Content"); |
43 | | - |
44 | | - return; |
45 | | - |
46 | | - } |
47 | 20 | ``` |
48 | | -Your entire send function should look similar to this: |
49 | | - |
50 | | -```JavaScript |
51 | | -function sendMessage() { |
| 21 | +<script src="https://cdn.jsdelivr.net/gh/DerrickRichard/CensorCore-Library@latest/CensorCore.js"></script> |
52 | 22 |
|
53 | | - const text = input.value; |
54 | | - |
55 | | - // Block explicit messages using the CensorCore library |
| 23 | +``` |
56 | 24 |
|
57 | | - if (censor.isBlocked(text)) { |
| 25 | +If you place the script near the closing `</html>` tag, the library may load after your code runs, which can prevent the wordlist from initializing correctly. |
58 | 26 |
|
59 | | - alert("Message blocked: Inappropriate Content"); |
| 27 | +After the script loads, a global object named `censor` will be available for use in your JavaScript. |
60 | 28 |
|
61 | | - return; |
| 29 | +Make sure your internet connection allows loading scripts from the CDN at: |
62 | 30 |
|
63 | | - } |
| 31 | +https://cdn.jsdelivr.net |
64 | 32 |
|
65 | | - addMessage(text); |
| 33 | +Basic Integration |
66 | 34 |
|
67 | | - input.value = ''; |
| 35 | +Inside your message‑sending logic, add this check: |
68 | 36 |
|
69 | | - input.focus(); |
| 37 | +JavaScript |
70 | 38 |
|
71 | | - } |
72 | 39 | ``` |
| 40 | +// Block explicit messages using the CensorCore library |
| 41 | +if (censor.isBlocked(text)) { |
| 42 | + alert("Message blocked: Inappropriate Content"); |
| 43 | + return; |
| 44 | +} |
73 | 45 |
|
74 | | -If you prefer, you can download the script and host it locally by cloning the repository or downloading the file directly, then updating the script src attribute accordingly. |
| 46 | +``` |
75 | 47 |
|
76 | | -Example of local hosting: |
| 48 | +A full example: |
77 | 49 |
|
78 | | -`<script src="path/to/CensorCore.js"></script>` |
| 50 | +JavaScript |
79 | 51 |
|
80 | | -This setup requires no additional configuration and works out of the box. |
| 52 | +``` |
| 53 | +function sendMessage() { |
| 54 | + const text = input.value; |
81 | 55 |
|
82 | | -Usage |
83 | | ------ |
| 56 | + // Block explicit messages using the CensorCore library |
| 57 | + if (censor.isBlocked(text)) { |
| 58 | + alert("Message blocked: Inappropriate Content"); |
| 59 | + return; |
| 60 | + } |
84 | 61 |
|
85 | | -Call `censor.isBlocked(text)` before sending or processing a message. Integrate this check into your message sending logic to prevent inappropriate content from being sent. |
| 62 | + addMessage(text); |
| 63 | + input.value = ''; |
| 64 | + input.focus(); |
| 65 | +} |
86 | 66 |
|
87 | | -Example: |
| 67 | +``` |
88 | 68 |
|
89 | | -```JavaScript |
90 | | -function sendMessage() { |
| 69 | +Advanced Usage (Version 2.0) |
91 | 70 |
|
92 | | - const text = input.value; |
| 71 | +Use the new `analyze()` API for detailed moderation results: |
93 | 72 |
|
94 | | - // Check if the message contains blocked words |
| 73 | +JavaScript |
95 | 74 |
|
96 | | - if (censor.isBlocked(text)) { |
| 75 | +``` |
| 76 | +const result = censor.analyze(text); |
97 | 77 |
|
98 | | - alert("Message blocked: Inappropriate Content"); |
| 78 | +if (result.blocked) { |
| 79 | + console.log("Blocked severity:", result.severity); |
| 80 | + console.log("Category:", result.category); |
| 81 | + console.log("Matches:", result.matches); |
| 82 | +} |
99 | 83 |
|
100 | | - return; // Prevent sending the message |
| 84 | +``` |
101 | 85 |
|
102 | | - } |
| 86 | +Custom Rules |
103 | 87 |
|
104 | | - // Proceed with sending the message |
| 88 | +You can add your own rules without modifying the main wordlist: |
105 | 89 |
|
106 | | - addMessage(text); |
| 90 | +JavaScript |
107 | 91 |
|
108 | | -} |
109 | 92 | ``` |
| 93 | +censor.extend([ |
| 94 | + { text: "my custom phrase", category: "custom", severity: "medium" } |
| 95 | +]); |
110 | 96 |
|
111 | | -In your sending logic, ensure you `call censor.isBlocked(text)` with the message text before actually sending or processing it. If it returns true, block the message and notify the user accordingly. You are able to adjust the alert content to your preferences. |
| 97 | +``` |
112 | 98 |
|
113 | 99 | Wordlist Structure |
114 | | ------------------- |
115 | 100 |
|
116 | | -CensorCore loads a JSON file structured by category: |
| 101 | +CensorCore loads a JSON file structured by category. Your actual wordlist includes categories such as: |
117 | 102 |
|
118 | | -```json |
119 | | -{ |
| 103 | +profanity hate_speech harassment sexual_content violence self_harm drugs weapons extremism terrorism disallowed_phrases custom |
120 | 104 |
|
121 | | -"profanity": ["word1", "word2"], |
| 105 | +Each category is automatically assigned a severity level (low, medium, or high). All categories are merged into a single internal rule engine. |
122 | 106 |
|
123 | | -"hate_speech": ["word3", "word4"], |
| 107 | +The CensorCore wordlist is curated solely by Derrick Richard to ensure consistency and quality. Community members cannot directly edit the wordlist. To request a new word or phrase, please use the Word Request section in the repository's Discussions page. |
124 | 108 |
|
125 | | -"harassment": ["word5", "word6"] |
| 109 | +API Reference |
126 | 110 |
|
127 | | -} |
128 | | -``` |
| 111 | +censor.isBlocked(text) Returns true if the text contains any blocked content. |
129 | 112 |
|
130 | | -All categories are automatically merged into a single internal list. The CensorCore word list is curated solely by Derrick Richard to ensure consistency and quality. Community members cannot directly edit the word list. To request a new word or phrase, please submit a request in the Word Request section of the repository's Discussions page. |
| 113 | +censor.analyze(text) Returns a detailed moderation result including: - whether the text is blocked - highest severity - category - all matched rules |
131 | 114 |
|
132 | | -API Reference |
133 | | -------------- |
| 115 | +censor.extend(rules) Adds custom moderation rules at runtime. |
| 116 | + |
| 117 | +censor.isReady() Returns true when the wordlist has finished loading. |
134 | 118 |
|
135 | | -### censor.isBlocked(text: string): boolean |
| 119 | +censor.isFailed() Returns true if the wordlist failed to load. |
136 | 120 |
|
137 | | -Returns true if the provided text contains any banned words. Returns false otherwise. |
| 121 | +censor.onReady(callback) Fires when the moderation engine is ready. |
| 122 | + |
| 123 | +censor.onError(callback) Fires if the moderation engine fails to load. |
138 | 124 |
|
139 | 125 | Design Philosophy |
140 | | ------------------ |
141 | 126 |
|
142 | | -CensorCore intentionally avoids modifying the host page's DOM, intercepting events, or altering user interface behavior. Instead, it provides a clear and predictable function that developers can integrate into their own message--handling logic. This approach ensures transparency, stability, and compatibility across a wide range of applications. |
| 127 | +CensorCore avoids modifying the DOM, intercepting events, or altering UI behavior. Instead, it provides a predictable, developer‑controlled moderation function. This ensures transparency, stability, and compatibility across a wide range of applications. |
143 | 128 |
|
144 | 129 | About the Developer |
145 | | -------------------- |
146 | | - |
147 | | -CensorCore was created and is maintained by Derrick Richard, a high school developer focused on building practical, lightweight tools for the web. He publishes weekly programming articles on[ dev.to](https://dev.to), which can be found at: |
148 | 130 |
|
149 | | -<https://dev.to/derrickrichard/> |
| 131 | +CensorCore was created and is maintained by Derrick Richard, a high school developer focused on building practical, lightweight tools for the web. |
150 | 132 |
|
151 | | -More information about his work and background is available on his personal profile: |
| 133 | +He publishes weekly programming articles at: https://dev.to/derrickrichard/ |
152 | 134 |
|
153 | | -<https://derrickrichard.github.io/profile/> |
| 135 | +More information about his work is available at: https://derrickrichard.github.io/profile/ |
154 | 136 |
|
155 | | -The CensorCore word list is curated solely by Derrick Richard to ensure consistency and quality. Community members cannot directly edit the word list. To request a new word or phrase, please submit a request in the Word Request section of the repository's Discussions page. |
| 137 | +The CensorCore wordlist is curated solely by Derrick Richard to ensure consistency and quality. Community members cannot directly edit the wordlist. To request a new word or phrase, please submit a request in the Word Request section of the repository's Discussions page. |
156 | 138 |
|
157 | 139 | Versions |
158 | | --------- |
159 | 140 |
|
160 | | -- v1.0.0: Initial release with basic filtering functionality and a basic JSON wordlist. |
161 | | -- v1.1.0: CensorCore v1.1.0 makes the filtering engine faster and more dependable. The wordlist is now processed ahead of time, the matching is quicker, and the library handles text in a more consistent way. The code has also been cleaned up so it is easier to follow and maintain. This update adds a couple of small helper functions that let you check whether the wordlist has loaded or if something went wrong while loading it. The public API is locked so it cannot be changed by accident, and the library behaves more safely if it is used before it finishes loading. Overall, this release makes CensorCore smoother and more reliable without changing how you already use it. |
| 141 | +v1.0.0 -- Initial release with basic filtering functionality and a basic JSON wordlist. |
| 142 | + |
| 143 | +v1.1.0 -- CensorCore v1.1.0 makes the filtering engine faster and more dependable. The wordlist is now processed ahead of time, the matching is quicker, and the library handles text in a more consistent way. The code has also been cleaned up so it is easier to follow and maintain. This update adds helper functions to check whether the wordlist has loaded or if something went wrong. The public API is locked to prevent accidental modification, and the library behaves more safely if used before loading finishes. |
| 144 | + |
| 145 | +v2.0.0 -- CensorCore v2.0.0 is a major upgrade that introduces phrase detection, automatic severity levels, async lifecycle events, a detailed analyze() API, and custom rule support. The internal rule engine has been redesigned for clarity and flexibility while remaining fully backward‑compatible with the original isBlocked() function. |
162 | 146 |
|
163 | 147 | License |
164 | | -------- |
165 | 148 |
|
166 | 149 | This project is released under the MIT License. |
0 commit comments