Protect Email Addresses Using ROT13 Substitution Cipher – email-protector.js

Category: Javascript | February 24, 2025
Author:bearbyt3z
Views Total:400 views
Official Page:Go to website
Last Update:February 24, 2025
License:MIT

Preview:

Protect Email Addresses Using ROT13 Substitution Cipher – email-protector.js

Description:

A powerful and user-friendly JavaScript solution to protect spambots from harvesting email addresses from your website.

The library encodes email addresses using ROT13 letter substitution cipher and automatically decodes them whenever the user clicks on the mailto link.

How to use it:

1. Download and import the email-protector.js into the page.

<script src="email-protector.js"></script>

2. Use the rot() function to encode an email address

// encoded with 13
let myEmail = EmailProtector.rot('[email protected]');
// encoded with 11
let myEmail = EmailProtector.rot('[email protected]', 11);
// encoded with 36
let myEmail = EmailProtector.rot('[email protected]', 36);

3. Insert the encoded email address into the page.

<span id="email-protector"></span>
// using append() method
EmailProtector.append('email-protector', myEmail);
// using write() method
EmailProtector.write(myEmail);
// decoding with 15, because it was encoded with 11
EmailProtector.write('[email protected]', { code: 15 });
// or ...
EmailProtector.write({
  email:   '[email protected]',
  subject: 'Message from www',
  body:    'Hi, I\'m contacting you',
  cc:      '[email protected]',
  bcc:     '[email protected]'
});

4. You can also specify an email link label.

EmailProtector.append('email-protector', '[email protected]', { 
  linkLabel: 'email link label' 
});

5. Using global parameters and configuration.

EmailProtector.setGlobalParams({ email: '[email protected]', subject: 'Message from www' });
EmailProtector.setGlobalConfig({ code: 15, hiddenSpan: false, htmlComments: false });
...
EmailProtector.write();
// reset params and configs
EmailProtector.resetParams();
EmailProtector.resetConfig();
...
EmailProtector.write('[email protected]');

6. All default parameters and configs for append() and write() functions

EmailProtector.write('[email protected]', {
  code: 13,
  cssReverse: true,
  hiddenSpan: true,
  htmlComments: true
});

Changelog:

v1.1.2 (02/24/2025)

  • Replaced deprecated substr() with substring() function

v1.0.2 (06/18/2024)

  • Replaced deprecated substr() with substring() function

v1.0.0 (06/17/2024)

  • Update

v0.8.0 (04/04/2024)

  • Added support for complex email addresses.

v0.6.1 (03/27/2023)

  • Bugfix

v0.5.2 (05/21/2022)

  • Replaced deprecated String.prototype.substr() with substring()

04/23/2021

  • Fixed bug with decoding a user name containing dots

You Might Be Interested In:


Leave a Reply