Add Attribute to Element
To censor text, add the following attribute to the HTML element you want to process:
data-censor="true"
Attribute Example
Below is an example of text containing words that will be censored:
<p data-censor="true">
This is an example of text with bad words like "stupid" that will be censored.
</p>
Add Functionality
Include the following script before the closing </body>
tag to enable the censoring functionality:
<script src="https://api.i-as.dev/js/plugin/censorText.js"></script>
<script>
const config = {
dataCensor: [] // Add bad words here.
};
</script>
Add Words to the Bad Words List
You can expand the list of bad words by adding them to the dataCensor
property in the config
object:
const config = {
dataCensor: ["word1", "word2", "another"]
};
<!DOCTYPE html>
<html lang="en" data-censor="true">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Censor Example</title>
</head>
<body>
<p data-censor="true">
This is an example of text with bad words like "stupid" that will be censored.
</p>
<script src="https://api.i-as.dev/js/plugin/censorText.js"></script>
<script>
const config = {
dataCensor: ["stupid", "badword"]
};
</script>
</body>
</html>